make iti_single and iti_multi sample values into functions
This commit is contained in:
		
							parent
							
								
									fd835efa46
								
							
						
					
					
						commit
						0d8ad2a356
					
				| @ -11,14 +11,14 @@ import ( | |||||||
| 
 | 
 | ||||||
| func TestNew(t *testing.T) { | func TestNew(t *testing.T) { | ||||||
| 	initTest() | 	initTest() | ||||||
| 	doc := Create(&iti_single).(*story) | 	doc := Create(iti_single()).(*story) | ||||||
| 	assert.Equal(t, iti_single.Title, doc.Title) | 	assert.Equal(t, iti_single().Title, doc.Title) | ||||||
| 	assert.Equal(t, iti_single.Chapters[0].Summary, doc.Chapters[0].Summary) | 	assert.Equal(t, iti_single().Chapters[0].Summary, doc.Chapters[0].Summary) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func TestSave(t *testing.T) { | func TestSave(t *testing.T) { | ||||||
| 	initTest() | 	initTest() | ||||||
| 	storyDoc := Create(iti_multi).(*story) | 	storyDoc := Create(iti_multi()).(*story) | ||||||
| 	lauthor := Create(author).(*user) | 	lauthor := Create(author).(*user) | ||||||
| 	storyDoc.Author = lauthor | 	storyDoc.Author = lauthor | ||||||
| 	assert.Equal(t, storyDoc.Id(), int64(0)) | 	assert.Equal(t, storyDoc.Id(), int64(0)) | ||||||
| @ -37,8 +37,8 @@ func TestSave(t *testing.T) { | |||||||
| func TestPopulate(t *testing.T) { | func TestPopulate(t *testing.T) { | ||||||
| 	initTest() | 	initTest() | ||||||
| 
 | 
 | ||||||
| 	bandDoc := Create(iti_single.Chapters[0].Bands[0]).(*band) | 	bandDoc := Create(iti_single().Chapters[0].Bands[0]).(*band) | ||||||
| 	storyDoc := Create(iti_single).(*story) | 	storyDoc := Create(iti_single()).(*story) | ||||||
| 	mauthor := Create(author).(*user) | 	mauthor := Create(author).(*user) | ||||||
| 	saveDoc(t, mauthor) | 	saveDoc(t, mauthor) | ||||||
| 	saveDoc(t, bandDoc) | 	saveDoc(t, bandDoc) | ||||||
| @ -79,7 +79,8 @@ func TestUpdate(t *testing.T) { | |||||||
| 
 | 
 | ||||||
| func TestModel_FindAll(t *testing.T) { | func TestModel_FindAll(t *testing.T) { | ||||||
| 	initTest() | 	initTest() | ||||||
| 	createAndSave(t, &iti_multi) | 	im := iti_multi() | ||||||
|  | 	createAndSave(t, &im) | ||||||
| 	smodel := Create(story{}).(*story) | 	smodel := Create(story{}).(*story) | ||||||
| 	query, err := smodel.Find(bson.M{}, options.Find()) | 	query, err := smodel.Find(bson.M{}, options.Find()) | ||||||
| 	assert.Equal(t, nil, err) | 	assert.Equal(t, nil, err) | ||||||
| @ -90,12 +91,13 @@ func TestModel_FindAll(t *testing.T) { | |||||||
| 
 | 
 | ||||||
| func TestModel_PopulateMulti(t *testing.T) { | func TestModel_PopulateMulti(t *testing.T) { | ||||||
| 	initTest() | 	initTest() | ||||||
| 	bandDoc := Create(iti_single.Chapters[0].Bands[0]).(*band) | 	bandDoc := Create(iti_single().Chapters[0].Bands[0]).(*band) | ||||||
| 	saveDoc(t, bandDoc) | 	saveDoc(t, bandDoc) | ||||||
| 	mauthor := Create(author).(*user) | 	mauthor := Create(author).(*user) | ||||||
| 	saveDoc(t, mauthor) | 	saveDoc(t, mauthor) | ||||||
| 	iti_multi.Author = mauthor | 	im := iti_multi() | ||||||
| 	createAndSave(t, &iti_multi) | 	im.Author = mauthor | ||||||
|  | 	createAndSave(t, &im) | ||||||
| 	smodel := Create(story{}).(*story) | 	smodel := Create(story{}).(*story) | ||||||
| 	query, err := smodel.Find(bson.M{}, options.Find()) | 	query, err := smodel.Find(bson.M{}, options.Find()) | ||||||
| 	assert.Equal(t, nil, err) | 	assert.Equal(t, nil, err) | ||||||
| @ -109,12 +111,13 @@ func TestModel_PopulateMulti(t *testing.T) { | |||||||
| 
 | 
 | ||||||
| func TestModel_PopulateChained_Multi(t *testing.T) { | func TestModel_PopulateChained_Multi(t *testing.T) { | ||||||
| 	initTest() | 	initTest() | ||||||
| 	bandDoc := Create(iti_single.Chapters[0].Bands[0]).(*band) | 	im := iti_multi() | ||||||
|  | 	bandDoc := Create(iti_single().Chapters[0].Bands[0]).(*band) | ||||||
| 	saveDoc(t, bandDoc) | 	saveDoc(t, bandDoc) | ||||||
| 	mauthor := Create(author).(*user) | 	mauthor := Create(author).(*user) | ||||||
| 	saveDoc(t, mauthor) | 	saveDoc(t, mauthor) | ||||||
| 	iti_multi.Author = mauthor | 	im.Author = mauthor | ||||||
| 	createAndSave(t, &iti_multi) | 	createAndSave(t, &im) | ||||||
| 	smodel := Create(story{}).(*story) | 	smodel := Create(story{}).(*story) | ||||||
| 	query, err := smodel.Find(bson.M{}, options.Find()) | 	query, err := smodel.Find(bson.M{}, options.Find()) | ||||||
| 	assert.Equal(t, nil, err) | 	assert.Equal(t, nil, err) | ||||||
| @ -129,8 +132,8 @@ func TestModel_PopulateChained_Multi(t *testing.T) { | |||||||
| func TestPopulate_Chained(t *testing.T) { | func TestPopulate_Chained(t *testing.T) { | ||||||
| 	initTest() | 	initTest() | ||||||
| 
 | 
 | ||||||
| 	bandDoc := Create(iti_single.Chapters[0].Bands[0]).(*band) | 	bandDoc := Create(iti_single().Chapters[0].Bands[0]).(*band) | ||||||
| 	storyDoc := Create(iti_single).(*story) | 	storyDoc := Create(iti_single()).(*story) | ||||||
| 	mauthor := Create(author).(*user) | 	mauthor := Create(author).(*user) | ||||||
| 	saveDoc(t, mauthor) | 	saveDoc(t, mauthor) | ||||||
| 	saveDoc(t, bandDoc) | 	saveDoc(t, bandDoc) | ||||||
| @ -181,7 +184,7 @@ func TestModel_Delete(t *testing.T) { | |||||||
| 
 | 
 | ||||||
| func TestModel_Pull(t *testing.T) { | func TestModel_Pull(t *testing.T) { | ||||||
| 	initTest() | 	initTest() | ||||||
| 	storyDoc := Create(iti_multi).(*story) | 	storyDoc := Create(iti_multi()).(*story) | ||||||
| 	smodel := Create(story{}).(*story) | 	smodel := Create(story{}).(*story) | ||||||
| 	saveDoc(t, storyDoc) | 	saveDoc(t, storyDoc) | ||||||
| 	err := storyDoc.Pull("Chapters", storyDoc.Chapters[4]) | 	err := storyDoc.Pull("Chapters", storyDoc.Chapters[4]) | ||||||
| @ -197,8 +200,9 @@ func TestModel_Pull(t *testing.T) { | |||||||
| 
 | 
 | ||||||
| func TestModel_Swap(t *testing.T) { | func TestModel_Swap(t *testing.T) { | ||||||
| 	initTest() | 	initTest() | ||||||
| 	iti_single.Author = &author | 	is := iti_single() | ||||||
| 	storyDoc := Create(iti_single).(*story) | 	is.Author = &author | ||||||
|  | 	storyDoc := Create(iti_single()).(*story) | ||||||
| 	saveDoc(t, storyDoc) | 	saveDoc(t, storyDoc) | ||||||
| 	storyDoc.Chapters[0].Bands = append(storyDoc.Chapters[0].Bands, bodom) | 	storyDoc.Chapters[0].Bands = append(storyDoc.Chapters[0].Bands, bodom) | ||||||
| 	assert.Equal(t, 2, len(storyDoc.Chapters[0].Bands)) | 	assert.Equal(t, 2, len(storyDoc.Chapters[0].Bands)) | ||||||
| @ -229,30 +233,6 @@ func TestModel_GridFSLoad(t *testing.T) { | |||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func TestModel_GridFSLoad_Complex(t *testing.T) { |  | ||||||
| 	initTest() |  | ||||||
| 	model := Create(story{}).(*story) |  | ||||||
| 	bandDoc := Create(iti_single.Chapters[0].Bands[0]).(*band) |  | ||||||
| 	thingDoc := Create(iti_multi).(*story) |  | ||||||
| 	mauthor := Create(author).(*user) |  | ||||||
| 	found := &story{} |  | ||||||
| 	saveDoc(t, mauthor) |  | ||||||
| 	saveDoc(t, bandDoc) |  | ||||||
| 	thingDoc.Author = mauthor |  | ||||||
| 	saveDoc(t, thingDoc) |  | ||||||
| 	assert.NotZero(t, thingDoc.ID) |  | ||||||
| 	fq, err := model.FindByID(thingDoc.ID) |  | ||||||
| 	assert.Nil(t, err) |  | ||||||
| 	fq.Populate("Author", "Chapters.Bands").LoadFile("Chapters.Text").Exec(found) |  | ||||||
| 	assert.NotZero(t, len(found.Chapters)) |  | ||||||
| 	for _, c := range found.Chapters { |  | ||||||
| 		assert.NotZero(t, c.Text) |  | ||||||
| 		assert.NotZero(t, c.Bands[0].Name) |  | ||||||
| 	} |  | ||||||
| 	j, _ := fq.JSON() |  | ||||||
| 	fmt.Printf("%s\n", j) |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| func TestModel_GridFSLoad_Chained(t *testing.T) { | func TestModel_GridFSLoad_Chained(t *testing.T) { | ||||||
| 	initTest() | 	initTest() | ||||||
| 	ModelRegistry.Model(somethingWithNestedChapters{}) | 	ModelRegistry.Model(somethingWithNestedChapters{}) | ||||||
| @ -271,3 +251,27 @@ func TestModel_GridFSLoad_Chained(t *testing.T) { | |||||||
| 		assert.NotZero(t, c.Text) | 		assert.NotZero(t, c.Text) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | func TestModel_GridFSLoad_Complex(t *testing.T) { | ||||||
|  | 	initTest() | ||||||
|  | 	model := Create(story{}).(*story) | ||||||
|  | 	bandDoc := Create(iti_single().Chapters[0].Bands[0]).(*band) | ||||||
|  | 	thingDoc := Create(iti_multi()).(*story) | ||||||
|  | 	mauthor := Create(author).(*user) | ||||||
|  | 	found := &story{} | ||||||
|  | 	saveDoc(t, bandDoc) | ||||||
|  | 	saveDoc(t, mauthor) | ||||||
|  | 	thingDoc.Author = mauthor | ||||||
|  | 	saveDoc(t, thingDoc) | ||||||
|  | 	assert.NotZero(t, thingDoc.ID) | ||||||
|  | 	fq, err := model.FindByID(thingDoc.ID) | ||||||
|  | 	assert.Nil(t, err) | ||||||
|  | 	fq.Populate("Author", "Chapters.Bands").LoadFile("Chapters.Text").Exec(found) | ||||||
|  | 	assert.NotZero(t, len(found.Chapters)) | ||||||
|  | 	for _, c := range found.Chapters { | ||||||
|  | 		assert.NotZero(t, c.Text) | ||||||
|  | 		assert.NotZero(t, c.Bands[0].Name) | ||||||
|  | 	} | ||||||
|  | 	j, _ := fq.JSON() | ||||||
|  | 	fmt.Printf("%s\n", j) | ||||||
|  | } | ||||||
|  | |||||||
							
								
								
									
										23
									
								
								testing.go
									
									
									
									
									
								
							
							
						
						
									
										23
									
								
								testing.go
									
									
									
									
									
								
							| @ -163,21 +163,24 @@ func doSomethingWithNested() somethingWithNestedChapters { | |||||||
| 	} | 	} | ||||||
| 	return swnc | 	return swnc | ||||||
| } | } | ||||||
| 
 | func iti_single() story { | ||||||
| var iti_single = story{ | 	return story{ | ||||||
| 	Title:     "title", | 		Title:     "title", | ||||||
| 	Completed: true, | 		Completed: true, | ||||||
| 	Chapters:  genChaps(true), | 		Chapters:  genChaps(true), | ||||||
|  | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| var iti_multi = story{ | func iti_multi() story { | ||||||
| 	Title:     "Brian Tatler Fucked and Abused Sean Harris", | 	return story{ | ||||||
| 	Completed: false, | 		Title:     "Brian Tatler Fucked and Abused Sean Harris", | ||||||
| 	Chapters:  genChaps(false), | 		Completed: false, | ||||||
|  | 		Chapters:  genChaps(false), | ||||||
|  | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func iti_blank() story { | func iti_blank() story { | ||||||
| 	t := iti_single | 	t := iti_single() | ||||||
| 	t.Chapters = make([]chapter, 0) | 	t.Chapters = make([]chapter, 0) | ||||||
| 	return t | 	return t | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user