add test cases for chaining Query methods
This commit is contained in:
parent
95bfdf7863
commit
aa16700270
@ -107,6 +107,51 @@ func TestModel_PopulateMulti(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestModel_PopulateChained_Multi(t *testing.T) {
|
||||
initTest()
|
||||
bandDoc := Create(iti_single.Chapters[0].Bands[0]).(*band)
|
||||
saveDoc(t, bandDoc)
|
||||
mauthor := Create(author).(*user)
|
||||
saveDoc(t, mauthor)
|
||||
iti_multi.Author = mauthor
|
||||
createAndSave(t, &iti_multi)
|
||||
smodel := Create(story{}).(*story)
|
||||
query, err := smodel.Find(bson.M{}, options.Find())
|
||||
assert.Equal(t, nil, err)
|
||||
final := CreateSlice(story{})
|
||||
query.Populate("Author").Populate("Chapters.Bands").Exec(&final)
|
||||
assert.Greater(t, len(final), 0)
|
||||
for _, s := range final {
|
||||
assert.NotZero(t, s.Chapters[0].Bands[0].Name)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPopulate_Chained(t *testing.T) {
|
||||
initTest()
|
||||
|
||||
bandDoc := Create(iti_single.Chapters[0].Bands[0]).(*band)
|
||||
storyDoc := Create(iti_single).(*story)
|
||||
mauthor := Create(author).(*user)
|
||||
saveDoc(t, mauthor)
|
||||
saveDoc(t, bandDoc)
|
||||
storyDoc.Author = mauthor
|
||||
saveDoc(t, storyDoc)
|
||||
assert.Greater(t, storyDoc.ID, int64(0))
|
||||
|
||||
smodel := Create(story{}).(*story)
|
||||
q, err := smodel.FindByID(storyDoc.ID)
|
||||
assert.Equal(t, nil, err)
|
||||
assert.NotPanics(t, func() {
|
||||
foundDoc := &story{}
|
||||
q.Populate("Author").Populate("Chapters.Bands").Exec(foundDoc)
|
||||
j, _ := q.JSON()
|
||||
fmt.Printf("%s\n", j)
|
||||
})
|
||||
for _, c := range storyDoc.Chapters {
|
||||
assert.NotZero(t, c.Bands[0].Name)
|
||||
}
|
||||
}
|
||||
|
||||
func TestModel_Append(t *testing.T) {
|
||||
initTest()
|
||||
bandDoc := Create(metallica).(*band)
|
||||
|
Loading…
Reference in New Issue
Block a user