/
runner_test.go
81 lines (63 loc) · 1.88 KB
/
runner_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package appx_test
import (
"appengine/aetest"
"appengine/datastore"
"github.com/drborges/appx"
"github.com/drborges/rivers/stream"
. "github.com/smartystreets/goconvey/convey"
"testing"
)
func TestQuery(t *testing.T) {
c, _ := aetest.NewContext(nil)
defer c.Close()
golang := &Tag{Name: "golang", Owner: "Borges"}
swift := &Tag{Name: "swift", Owner: "Borges"}
ruby := &Tag{Name: "ruby", Owner: "Diego"}
createAll(c, golang, swift, ruby)
Convey("Given I have a QueryRunner", t, func() {
byOwner := datastore.NewQuery(new(Tag).KeySpec().Kind).Filter("Owner=", "Borges")
runner := appx.NewDatastore(c).Query(byOwner)
Convey("When I run Results", func() {
result := []*Tag{}
err := runner.Results(&result)
Convey("Then it succeeds", func() {
So(err, ShouldBeNil)
Convey("Then it loads the matched entities into the given slice", func() {
So(result, ShouldResemble, []*Tag{golang, swift})
Convey("Then it sets keys back to the entities", func() {
So(result[0].Key(), ShouldNotBeNil)
So(result[1].Key(), ShouldNotBeNil)
})
})
})
})
Convey("When I run Result", func() {
tag := &Tag{}
err := runner.Result(tag)
Convey("Then it succeeds", func() {
So(err, ShouldBeNil)
Convey("Then it loads data into the given entity", func() {
So(tag, ShouldResemble, golang)
Convey("Then it sets the key back to the entity", func() {
So(tag.Key(), ShouldNotBeNil)
})
})
})
})
Convey("When I run Count", func() {
count, err := runner.Count()
Convey("Then it succeeds", func() {
So(err, ShouldBeNil)
Convey("Then count is 2", func() {
So(count, ShouldEqual, 2)
})
})
})
Convey("When I stream the data", func() {
s := runner.StreamOf(Tag{}).Stream
Convey("Then the entities are streammed", func() {
So(s.ReadAll(), ShouldResemble, []stream.T{golang, swift})
})
})
})
}