Skip to content

Commit 9a2fa53

Browse files
authored
Merge pull request #50 from ali-ince/1.7-pass-access-mode-tests
Add tests for passing access mode
2 parents 72f1ee3 + 1af7d99 commit 9a2fa53

23 files changed

+420
-397
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ Windows doesn't provide `pkg-config`, so have it installed by following [these i
2828

2929
#### Binaries
3030

31-
We're now providing _**experimental**_ binaries for `Linux`, `MacOS` and `Windows` [here](https://github.com/neo4j-drivers/seabolt/releases). Please remember that `OpenSSL` is still a requirement for all of these systems. In order to link seabolt statically make sure you have static OpenSSL libraries, too.
31+
We're now providing _**experimental**_ binaries for `Linux`, `MacOS` and `Windows` [here](https://github.com/neo4j-drivers/seabolt/releases). Please remember that `OpenSSL` is still a requirement for all of these systems.
3232

33-
Linux packages are being built on `Ubuntu 16.04` system and generated artifacts contain symbol references/absolute paths to dependent static/dynamic libraries which are only applicable to `Ubuntu 16.04` package versions/file system layout. _**It may be better to compile seabolt from scratch if you are on a different Linux distribution or version.**_
33+
Static linking against seabolt is only supported on **_Linux_** and **_MacOS_** at this time, and in order to get it working make sure you have static OpenSSL libraries, too.
3434

3535
#### Source
3636

@@ -56,6 +56,8 @@ Add the driver with `go get github.com/neo4j/neo4j-go-driver/neo4j`
5656

5757
We provide `seabolt_static` build tag to support static linking against seabolt and its dependencies. You can just pass `--tags seabolt_static` to your `go` toolset (like `go build --tags seabolt_static`) for your project and the output will not have any runtime dependency to `seabolt` and `openssl`.
5858

59+
_**Static linking is currently not supported on Windows.**_
60+
5961
## Setting RPATH on Linux/MacOS
6062

6163
Both Linux and MacOS dynamic loader support `RPATH` entries into executables so that they can locate their dependent shared libraries based on those entries. To have a `RUNPATH` entry to be added to your executable, you can pass `-ldflags "-r $(pkg-config --variable=libdir seabolt17)"` to your `go` toolset (like `go build -ldflags "-r $(pkg-config --variable=libdir seabolt17)"`) and it will add an `RPATH` entry to your executable that points to the location where seabolt shared library resides.

neo4j/test-stub/control/boltstub.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@ import (
2727
"path"
2828
"runtime"
2929
"sync/atomic"
30+
"testing"
3031
"time"
31-
32-
. "github.com/onsi/ginkgo"
3332
)
3433

3534
// StubServer represents a running instance of a scripted bolt stub server
@@ -69,20 +68,20 @@ func (server *StubServer) exitError() string {
6968
}
7069

7170
// NewStubServer launches the stub server on the given port with the given script
72-
func NewStubServer(port int, script string) *StubServer {
71+
func NewStubServer(t *testing.T, port int, script string) *StubServer {
7372
var testScriptsDir = os.TempDir()
7473

7574
if _, file, _, ok := runtime.Caller(1); ok {
7675
testScriptsDir = path.Join(path.Dir(file), "scripts")
7776
}
7877

7978
if len(testScriptsDir) == 0 {
80-
Fail("unable to locate bolt stub script folder")
79+
t.Fatalf("unable to locate bolt stub script folder")
8180
}
8281

8382
testScriptFile := path.Join(testScriptsDir, script)
8483
if _, err := os.Stat(testScriptFile); os.IsNotExist(err) {
85-
Fail(fmt.Sprintf("unable to locate bolt stub script file at '%s'", testScriptFile))
84+
t.Fatalf("unable to locate bolt stub script file at '%s'", testScriptFile)
8685
}
8786

8887
cmd := exec.Command("boltstub", fmt.Sprint(port), testScriptFile)
@@ -132,17 +131,17 @@ func NewStubServer(port int, script string) *StubServer {
132131
}
133132

134133
if server.exited() && server.exitError() != "" {
135-
Fail(server.exitError())
134+
t.Fatalf(server.exitError())
136135
}
137136

138-
Fail(fmt.Sprintf("unable to open a connection to boltstub server at [:%d]", server.port))
137+
t.Fatalf("unable to open a connection to boltstub server at [:%d]", server.port)
139138

140139
return nil
141140
}
142141

143142
// Finished expects the stub server to already be exited returns whether it was exited
144143
// with success code. If the process did not exit as expected, it returns false (or fails the test)
145-
func (server *StubServer) Finished() bool {
144+
func (server *StubServer) Finished(t *testing.T) bool {
146145
// Close our initial connection to make the stub server exit
147146
if server.conn != nil {
148147
server.conn.Close()
@@ -167,7 +166,7 @@ func (server *StubServer) Finished() bool {
167166

168167
// Check if an error occurred
169168
if server.exitError() != "" {
170-
Fail(server.exitError())
169+
t.Fatalf(server.exitError())
171170
}
172171

173172
return true

neo4j/test-stub/disconnect_test.go

Lines changed: 46 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -21,134 +21,55 @@ package test_stub
2121

2222
import (
2323
"path"
24+
"testing"
2425

26+
"github.com/neo4j-drivers/gobolt"
2527
"github.com/neo4j/neo4j-go-driver/neo4j/test-stub/control"
26-
"github.com/neo4j/neo4j-go-driver/neo4j/utils/test"
27-
. "github.com/onsi/ginkgo"
28-
. "github.com/onsi/gomega"
28+
"github.com/stretchr/testify/assert"
2929
)
3030

31-
var _ = Describe("Disconnect", func() {
32-
var stub *control.StubServer
33-
34-
AfterEach(func() {
35-
if stub != nil {
36-
Expect(stub.Finished()).To(BeTrue())
37-
38-
stub.Close()
39-
}
40-
})
41-
42-
Context("V1", func() {
43-
It("should return error when server disconnects after INIT", func() {
44-
stub = control.NewStubServer(9001, path.Join("v1", "disconnect_after_init.script"))
45-
46-
driver := newDriver("bolt://localhost:9001")
47-
defer driver.Close()
48-
49-
session := createSession(driver)
50-
defer session.Close()
51-
52-
result, err := session.Run("RETURN $x", map[string]interface{}{"x": 1})
53-
Expect(err).To(BeNil())
54-
55-
summary, err := result.Consume()
56-
57-
Expect(err).To(test.BeServiceUnavailableError())
58-
Expect(summary).To(BeNil())
59-
})
60-
61-
It("should return error when server disconnects after RUN", func() {
62-
stub = control.NewStubServer(9001, path.Join("v1", "disconnect_on_run.script"))
63-
64-
driver := newDriver("bolt://localhost:9001")
65-
defer driver.Close()
66-
67-
session := createSession(driver)
68-
defer session.Close()
69-
70-
result, err := session.Run("RETURN $x", map[string]interface{}{"x": 1})
71-
Expect(err).To(BeNil())
72-
73-
summary, err := result.Consume()
74-
75-
Expect(err).To(test.BeServiceUnavailableError())
76-
Expect(summary).To(BeNil())
77-
})
78-
79-
It("should return error when server disconnects after PULL_ALL", func() {
80-
stub = control.NewStubServer(9001, path.Join("v1", "disconnect_on_pull_all.script"))
81-
82-
driver := newDriver("bolt://localhost:9001")
83-
defer driver.Close()
84-
85-
session := createSession(driver)
86-
defer session.Close()
87-
88-
result, err := session.Run("RETURN $x", map[string]interface{}{"x": 1})
89-
Expect(err).To(BeNil())
90-
91-
summary, err := result.Consume()
92-
93-
Expect(err).To(test.BeServiceUnavailableError())
94-
Expect(summary).To(BeNil())
95-
})
96-
})
97-
98-
Context("V3", func() {
99-
It("should return error when server disconnects after HELLO", func() {
100-
stub = control.NewStubServer(9001, path.Join("v3", "disconnect_after_hello.script"))
101-
102-
driver := newDriver("bolt://localhost:9001")
103-
defer driver.Close()
104-
105-
session := createSession(driver)
106-
defer session.Close()
107-
108-
result, err := session.Run("RETURN $x", map[string]interface{}{"x": 1})
109-
Expect(err).To(BeNil())
110-
111-
summary, err := result.Consume()
112-
113-
Expect(err).To(test.BeServiceUnavailableError())
114-
Expect(summary).To(BeNil())
115-
})
116-
117-
It("should return error when server disconnects after RUN", func() {
118-
stub = control.NewStubServer(9001, path.Join("v3", "disconnect_on_run.script"))
119-
120-
driver := newDriver("bolt://localhost:9001")
121-
defer driver.Close()
122-
123-
session := createSession(driver)
124-
defer session.Close()
125-
126-
result, err := session.Run("RETURN $x", map[string]interface{}{"x": 1})
127-
Expect(err).To(BeNil())
128-
129-
summary, err := result.Consume()
130-
131-
Expect(err).To(test.BeServiceUnavailableError())
132-
Expect(summary).To(BeNil())
133-
})
134-
135-
It("should return error when server disconnects after PULL_ALL", func() {
136-
stub = control.NewStubServer(9001, path.Join("v3", "disconnect_on_pull_all.script"))
137-
138-
driver := newDriver("bolt://localhost:9001")
139-
defer driver.Close()
140-
141-
session := createSession(driver)
142-
defer session.Close()
143-
144-
result, err := session.Run("RETURN $x", map[string]interface{}{"x": 1})
145-
Expect(err).To(BeNil())
146-
147-
summary, err := result.Consume()
148-
149-
Expect(err).To(test.BeServiceUnavailableError())
150-
Expect(summary).To(BeNil())
31+
func Test_Disconnect(t *testing.T) {
32+
var cases = []struct {
33+
name string
34+
protocol string
35+
}{
36+
{"V1", "v1"},
37+
{"V3", "v3"},
38+
}
39+
40+
for _, testCase := range cases {
41+
t.Run(testCase.name, func(t *testing.T) {
42+
var verifyServiceUnavailable = func(t *testing.T, script string) {
43+
stub := control.NewStubServer(t, 9001, path.Join(testCase.protocol, script))
44+
defer stub.Finished(t)
45+
46+
driver := newDriver(t, "bolt://localhost:9001")
47+
defer driver.Close()
48+
49+
session := createWriteSession(t, driver)
50+
defer session.Close()
51+
52+
result, err := session.Run("RETURN $x", map[string]interface{}{"x": 1})
53+
assert.NoError(t, err)
54+
55+
summary, err := result.Consume()
56+
assert.Error(t, err)
57+
assert.True(t, gobolt.IsServiceUnavailable(err))
58+
assert.Nil(t, summary)
59+
}
60+
61+
t.Run("shouldReturnErrorWhenServerDisconnectsAfterInit", func(t *testing.T) {
62+
verifyServiceUnavailable(t, "disconnect_after_login.script")
63+
})
64+
65+
t.Run("shouldReturnErrorWhenServerDisconnectsAfterRun", func(t *testing.T) {
66+
verifyServiceUnavailable(t, "disconnect_on_run.script")
67+
})
68+
69+
t.Run("shouldReturnErrorWhenServerDisconnectsAfterPullAll", func(t *testing.T) {
70+
verifyServiceUnavailable(t, "disconnect_on_pull_all.script")
71+
})
15172
})
152-
})
73+
}
15374

154-
})
75+
}

neo4j/test-stub/ginkgo_test.go

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)