-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmock_test.go
More file actions
59 lines (51 loc) · 1.11 KB
/
Copy pathmock_test.go
File metadata and controls
59 lines (51 loc) · 1.11 KB
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
package neogo
import (
"context"
"testing"
"github.com/neo4j/neo4j-go-driver/v5/neo4j"
"github.com/rlch/neogo/db"
"github.com/stretchr/testify/require"
)
func newHybridDriver(t *testing.T, ctx context.Context) (d Driver, m mockDriver) {
m = NewMock()
if testing.Short() {
d = m
} else {
uri, cancel := startNeo4J(ctx)
var err error
d, err = New(uri, neo4j.BasicAuth("neo4j", "password", ""))
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() {
if err := cancel(ctx); err != nil {
t.Fatal(err)
}
})
}
return
}
func TestMockDriver(t *testing.T) {
ctx := context.Background()
t.Run("must provide bindings for all transactions", func(t *testing.T) {
d := NewMock()
d.Bind(nil)
// Should work without error when bindings are provided
err := d.Exec().
Cypher("RETURN 1").
Run(ctx)
require.NoError(t, err)
})
t.Run("mock with data", func(t *testing.T) {
d := NewMock()
d.Bind(map[string]any{
"test": "value",
})
var result string
err := d.Exec().
Return(db.Qual(&result, "test")).
Run(ctx)
require.NoError(t, err)
require.Equal(t, "value", result)
})
}