Skip to content

Commit 0e4c5f6

Browse files
Peter Wilhelmsson2hdddg
authored andcommitted
testkit: Porting tests to testkit
Added support for Consume in testkit backend and cleaned up among integration tests (moved some to unit tests and removed some tests covered by testkit tests)
1 parent fa39565 commit 0e4c5f6

File tree

4 files changed

+20
-52
lines changed

4 files changed

+20
-52
lines changed

neo4j/session_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func TestSession(st *testing.T) {
131131
})
132132

133133
st.Run("Bookmarking", func(bt *testing.T) {
134-
bt.Run("Last initial bookmark is used for LastBookmark", func(t *testing.T) {
134+
bt.Run("Initial bookmark is used for LastBookmark", func(t *testing.T) {
135135
_, _, sess := createSessionWithBookmarks([]string{"b1", "b2"})
136136
AssertStringEqual(t, sess.LastBookmark(), "b2")
137137
})
@@ -159,6 +159,11 @@ func TestSession(st *testing.T) {
159159
}
160160
}
161161
})
162+
163+
bt.Run("LastBookmark is empty when no initial bookmark", func(t *testing.T) {
164+
_, _, sess := createSession()
165+
AssertStringEqual(t, sess.LastBookmark(), "")
166+
})
162167
})
163168

164169
st.Run("Run", func(bt *testing.T) {

neo4j/test-integration/auth_test.go

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -38,34 +38,6 @@ func TestAuthentication(tt *testing.T) {
3838
return driver, driver.NewSession(neo4j.SessionConfig{AccessMode: neo4j.AccessModeRead})
3939
}
4040

41-
assertConnect := func(t *testing.T, token neo4j.AuthToken) {
42-
driver, session := getDriverAndSession(token)
43-
defer driver.Close()
44-
defer session.Close()
45-
46-
_, err := session.Run("RETURN 1", nil)
47-
if err != nil {
48-
t.Errorf("Failed to run query when connect should succeed: %s", err)
49-
}
50-
}
51-
52-
tt.Run("when credentials are provided as a basic token with realm", func(t *testing.T) {
53-
token := neo4j.BasicAuth(server.Username, server.Password, "native")
54-
assertConnect(t, token)
55-
})
56-
57-
tt.Run("when credentials are provided as a custom token", func(t *testing.T) {
58-
token := neo4j.CustomAuth("basic", server.Username, server.Password, "native", nil)
59-
assertConnect(t, token)
60-
})
61-
62-
tt.Run("when credentials are provided as a custom token with parameters", func(t *testing.T) {
63-
token := neo4j.CustomAuth("basic", server.Username, server.Password, "native", map[string]interface{}{
64-
"otp": "12345",
65-
})
66-
assertConnect(t, token)
67-
})
68-
6941
tt.Run("when wrong credentials are provided, it should fail with authentication error", func(t *testing.T) {
7042
token := neo4j.BasicAuth("wrong", "wrong", "")
7143
driver, session := getDriverAndSession(token)

neo4j/test-integration/bookmark_test.go

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -78,29 +78,7 @@ var _ = Describe("Bookmark", func() {
7878
}
7979
})
8080

81-
Specify("session should not have any bookmark", func() {
82-
Expect(session.LastBookmark()).To(BeEmpty())
83-
})
84-
85-
Specify("when a node is created in auto-commit mode, last bookmark should be empty", func() {
86-
if server.Version.GreaterThanOrEqual(V350) {
87-
Skip("this test is targeted for server version less than neo4j 3.5.0")
88-
}
89-
90-
result, err = session.Run("CREATE (p:Person { name: 'Test'})", nil)
91-
Expect(err).To(BeNil())
92-
93-
summary, err = result.Consume()
94-
Expect(err).To(BeNil())
95-
96-
Expect(session.LastBookmark()).To(BeEmpty())
97-
})
98-
9981
Specify("when a node is created in auto-commit mode, last bookmark should not be empty", func() {
100-
if server.Version.GreaterThanOrEqual(V350) {
101-
Skip("this test is targeted for server version after neo4j 3.5.0")
102-
}
103-
10482
result, err = session.Run("CREATE (p:Person { name: 'Test'})", nil)
10583
Expect(err).To(BeNil())
10684

testkit-backend/backend.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,11 @@ func (b *backend) handleRequest(req map[string]interface{}) {
399399
case "SessionLastBookmarks":
400400
sessionState := b.sessionStates[data["sessionId"].(string)]
401401
bookmark := sessionState.session.LastBookmark()
402-
b.writeResponse("Bookmarks", map[string]interface{}{"bookmarks": []string{bookmark}})
402+
bookmarks := []string{}
403+
if bookmark != "" {
404+
bookmarks = append(bookmarks, bookmark)
405+
}
406+
b.writeResponse("Bookmarks", map[string]interface{}{"bookmarks": bookmarks})
403407

404408
case "TransactionRun":
405409
tx := b.transactions[data["txId"].(string)]
@@ -466,6 +470,15 @@ func (b *backend) handleRequest(req map[string]interface{}) {
466470
}
467471
b.writeResponse("NullRecord", nil)
468472
}
473+
case "ResultConsume":
474+
result := b.results[data["resultId"].(string)]
475+
_, err := result.Consume()
476+
if err != nil {
477+
b.writeError(err)
478+
return
479+
}
480+
b.writeResponse("Summary", nil)
481+
469482
default:
470483
b.writeError(errors.New("Unknown request: " + name))
471484
}

0 commit comments

Comments
 (0)