/
pipeline_step_query_entity_from_datastore_test.go
80 lines (66 loc) · 1.98 KB
/
pipeline_step_query_entity_from_datastore_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
package appx_test
import (
"appengine/aetest"
"appengine/datastore"
"github.com/drborges/appx"
"github.com/drborges/rivers"
. "github.com/smartystreets/goconvey/convey"
"testing"
"time"
)
func TestQueryEntityFromDatastore(t *testing.T) {
gaeCtx, _ := aetest.NewContext(nil)
defer gaeCtx.Close()
user := &User{
Name: "Borges",
Email: "diego@email.com",
SSN: "123123123",
keySpec: &appx.KeySpec{
Kind: "Users",
StringID: "borges",
},
}
parentKey := datastore.NewKey(gaeCtx, "Parent", "parent id", 0, nil)
user.SetParentKey(parentKey)
Convey("Given I have a query entity from datastore transformer", t, func() {
riversCtx := rivers.NewContext()
queryProcessor := appx.NewStep(riversCtx).QueryEntityFromDatastore(gaeCtx)
Convey("When I transform the inbound stream with non existent entity", func() {
nonExistentUser := &User{
Email: "diego@email.com",
keySpec: &appx.KeySpec{
Kind: "Users",
},
}
runQuery := func() {
queryProcessor(nonExistentUser)
}
Convey("Then query processor panics", func() {
So(runQuery, ShouldPanic)
})
})
Convey("And I have an entity in datastore", func() {
err := appx.NewKeyResolver(gaeCtx).Resolve(user)
So(err, ShouldBeNil)
_, err = datastore.Put(gaeCtx, user.Key(), user)
So(err, ShouldBeNil)
// Give datastore some time so that the created entity is available to be queried
time.Sleep(200 * time.Millisecond)
Convey("When I transform the inbound stream", func() {
userFromDatastore := &User{
Email: "diego@email.com",
keySpec: &appx.KeySpec{
Kind: "Users",
},
}
queryProcessor(userFromDatastore)
Convey("And queryable entities are loaded from datastore", func() {
So(userFromDatastore.Name, ShouldEqual, user.Name)
So(userFromDatastore.Email, ShouldEqual, user.Email)
So(userFromDatastore.Key(), ShouldResemble, user.Key())
So(userFromDatastore.ParentKey(), ShouldResemble, user.ParentKey())
})
})
})
})
}