-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtesting_test.go
128 lines (101 loc) · 2.86 KB
/
testing_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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package quirk
import (
"context"
"errors"
"testing"
"github.com/dgraph-io/dgo/v2"
"github.com/dgraph-io/dgo/v2/protos/api"
. "github.com/franela/goblin"
)
func TestTestBuilder(t *testing.T) {
g := Goblin(t)
g.Describe("testBuilder", func() {
g.It("should not error when writing", func() {
b := &testBuilder{}
n, err := b.Write([]byte{})
g.Assert(n).
Equal(0)
g.Assert(err).
Equal(error(nil))
})
g.It("should error when writing", func() {
b := &testBuilder{failOn: 1}
n, err := b.Write([]byte{})
g.Assert(n).
Equal(0)
g.Assert(err).
Equal(errors.New("WRITE_ERROR"))
})
g.It("should not error when stringing", func() {
b := &testBuilder{}
n, err := b.Write([]byte{})
g.Assert(n).
Equal(0)
g.Assert(err).
Equal(error(nil))
})
g.It("should error when stringing", func() {
b := &testBuilder{failOn: 1}
g.Assert(b.String()).Equal("STRING_ERROR")
})
})
}
func TestTestDgraphClient(t *testing.T) {
g := Goblin(t)
g.Describe("testDgraphClient", func() {
dg := &testDgraphClient{}
g.It("should return response when Login is called", func() {
r, err := dg.Login(context.Background(), &api.LoginRequest{})
g.Assert(r).
Equal(&api.Response{})
g.Assert(err).
Equal(error(nil))
})
g.It("should return response when Query is called", func() {
_, err := dg.Query(context.Background(), &api.Request{})
g.Assert(err).
Equal(error(nil))
})
g.It("should return payload when Alter is called", func() {
r, err := dg.Alter(context.Background(), &api.Operation{})
g.Assert(r).
Equal(&api.Payload{})
g.Assert(err).
Equal(error(nil))
})
g.It("should return context when CommitOrAbort is called", func() {
r, err := dg.CommitOrAbort(context.Background(), &api.TxnContext{})
g.Assert(r).
Equal(&api.TxnContext{})
g.Assert(err).
Equal(error(nil))
})
g.It("should return version when CheckVersion is called", func() {
r, err := dg.CheckVersion(context.Background(), &api.Check{})
g.Assert(r).
Equal(&api.Version{})
g.Assert(err).
Equal(error(nil))
})
// Updated api.Assigned to api.Response as part of dgo major version change.
// See Issue #17 for more info.
g.It("should return assigned with a uid when Mutate is called", func() {
dg.shouldAbort = false
r, err := dg.Mutate(context.Background(), &api.Mutation{})
g.Assert(r).
Equal(&api.Response{Uids: map[string]string{"damienstamates": "0x1"}})
g.Assert(err).
Equal(error(nil))
})
// Updated api.Assigned to api.Response as part of dgo major version change.
// See Issue #17 for more info.
g.It("should return assigned with a uid when Mutate is called", func() {
dg.shouldAbort = true
r, err := dg.Mutate(context.Background(), &api.Mutation{})
g.Assert(r).
Equal(&api.Response{})
g.Assert(err).
Equal(dgo.ErrAborted)
})
})
}