@@ -34,6 +34,13 @@ func assertNoRouter(t *testing.T, d Driver) {
34
34
t .Error ("Expected no router" )
35
35
}
36
36
}
37
+ func assertNoRouterAddress (t * testing.T , d Driver , address string ) {
38
+ t .Helper ()
39
+ direct := d .(* driver ).router .(* directRouter )
40
+ if direct .address != address {
41
+ t .Errorf ("Address mismatch %s vs %s" , address , direct .address )
42
+ }
43
+ }
37
44
38
45
func assertRouter (t * testing.T , d Driver ) {
39
46
t .Helper ()
@@ -52,46 +59,80 @@ func assertRouterContext(t *testing.T, d Driver, context map[string]string) {
52
59
}
53
60
}
54
61
55
- var uriSchemeTests = []struct {
56
- name string
57
- scheme string
58
- testing string
59
- router bool
60
- }{
61
- {"bolt://" , "bolt" , "bolt://localhost:7687" , false },
62
- {"bolt+s://" , "bolt" , "bolt://localhost:7687" , false },
63
- {"bolt+ssc://" , "bolt" , "bolt://localhost:7687" , false },
64
- {"neo4j://" , "neo4j" , "neo4j://localhost:7687" , true },
65
- {"neo4j+s://" , "neo4j" , "neo4j://localhost:7687" , true },
66
- {"neo4j+ssc://" , "neo4j" , "neo4j://localhost:7687" , true },
62
+ func assertSkipEncryption (t * testing.T , d Driver , skipEncryption bool ) {
63
+ t .Helper ()
64
+ c := d .(* driver ).connector
65
+ if c .SkipEncryption != skipEncryption {
66
+ t .Errorf ("SkipEncryption mismatch, %t vs %t" , skipEncryption , c .SkipEncryption )
67
+ }
68
+ }
69
+
70
+ func assertSkipVerify (t * testing.T , d Driver , skipVerify bool ) {
71
+ t .Helper ()
72
+ c := d .(* driver ).connector
73
+ if c .SkipVerify != skipVerify {
74
+ t .Errorf ("SkipVerify mismatch, %t vs %t" , skipVerify , c .SkipVerify )
75
+ }
67
76
}
68
77
69
- func TestDriverURISchemesX (t * testing.T ) {
78
+ func assertNetwork (t * testing.T , d Driver , network string ) {
79
+ t .Helper ()
80
+ c := d .(* driver ).connector
81
+ if c .Network != network {
82
+ t .Errorf ("Network mismatch, %s vs %s" , network , c .Network )
83
+ }
84
+ }
85
+
86
+ func TestDriverURISchemes (t * testing.T ) {
87
+ uriSchemeTests := []struct {
88
+ scheme string
89
+ testing string
90
+ router bool
91
+ skipEncryption bool
92
+ skipVerify bool
93
+ network string
94
+ address string
95
+ }{
96
+ {"bolt" , "bolt://localhost:7687" , false , true , false , "tcp" , "localhost:7687" },
97
+ {"bolt+s" , "bolt+s://localhost:7687" , false , false , false , "tcp" , "localhost:7687" },
98
+ {"bolt+ssc" , "bolt+ssc://localhost:7687" , false , false , true , "tcp" , "localhost:7687" },
99
+ {"bolt+unix" , "bolt+unix:///tmp/a.socket" , false , true , false , "unix" , "/tmp/a.socket" },
100
+ {"neo4j" , "neo4j://localhost:7687" , true , true , false , "tcp" , "" },
101
+ {"neo4j+s" , "neo4j+s://localhost:7687" , true , false , false , "tcp" , "" },
102
+ {"neo4j+ssc" , "neo4j+ssc://localhost:7687" , true , false , true , "tcp" , "" },
103
+ }
104
+
70
105
for _ , tt := range uriSchemeTests {
71
- t .Run (tt .name , func (t * testing.T ) {
106
+ t .Run (tt .scheme , func (t * testing.T ) {
72
107
driver , err := NewDriver (tt .testing , NoAuth ())
73
108
74
109
AssertNoError (t , err )
75
110
AssertStringEqual (t , driver .Target ().Scheme , tt .scheme )
76
111
if ! tt .router {
77
112
assertNoRouter (t , driver )
113
+ assertNoRouterAddress (t , driver , tt .address )
78
114
} else {
79
115
assertRouter (t , driver )
80
116
}
117
+ assertSkipEncryption (t , driver , tt .skipEncryption )
118
+ if ! tt .skipEncryption {
119
+ assertSkipVerify (t , driver , tt .skipVerify )
120
+ }
121
+ assertNetwork (t , driver , tt .network )
81
122
})
82
123
}
83
124
}
84
125
85
- var invalidURISchemeTests = []struct {
86
- name string
87
- scheme string
88
- testing string
89
- }{
90
- {"bolt+routing://" , "bolt+routing" , "bolt+routing://localhost:7687" },
91
- {"invalid://" , "invalid" , "invalid://localhost:7687" },
92
- }
126
+ func TestDriverInvalidURISchemes (t * testing.T ) {
127
+ invalidURISchemeTests := []struct {
128
+ name string
129
+ scheme string
130
+ testing string
131
+ }{
132
+ {"bolt+routing://" , "bolt+routing" , "bolt+routing://localhost:7687" },
133
+ {"invalid://" , "invalid" , "invalid://localhost:7687" },
134
+ }
93
135
94
- func TestDriverInvalidURISchemesX (t * testing.T ) {
95
136
for _ , tt := range invalidURISchemeTests {
96
137
t .Run (tt .name , func (t * testing.T ) {
97
138
_ , err := NewDriver (tt .testing , NoAuth ())
@@ -127,7 +168,6 @@ func TestDriverURIRoutingContext(t *testing.T) {
127
168
}
128
169
129
170
func TestDriverDefaultPort (t * testing.T ) {
130
-
131
171
t .Run ("neo4j://localhost should default to port 7687" , func (t1 * testing.T ) {
132
172
driver , err := NewDriver ("neo4j://localhost" , NoAuth ())
133
173
driverTarget := driver .Target ()
@@ -139,7 +179,6 @@ func TestDriverDefaultPort(t *testing.T) {
139
179
}
140
180
141
181
func TestNewDriverAndClose (t * testing.T ) {
142
-
143
182
driver , err := NewDriver ("bolt://localhost:7687" , NoAuth ())
144
183
AssertNoError (t , err )
145
184
@@ -172,19 +211,19 @@ func TestNewDriverAndClose(t *testing.T) {
172
211
}
173
212
}
174
213
175
- var driverSessionCreationTests = []struct {
176
- name string
177
- testing string
178
- mode AccessMode
179
- bookmarks []string
180
- }{
181
- {"case one" , "bolt://localhost:7687" , AccessModeWrite , []string (nil )},
182
- {"case two" , "bolt://localhost:7687" , AccessModeRead , []string (nil )},
183
- {"case three" , "bolt://localhost:7687" , AccessModeWrite , []string {"B1" , "B2" , "B3" }},
184
- {"case four" , "bolt://localhost:7687" , AccessModeRead , []string {"B1" , "B2" , "B3" , "B4" }},
185
- }
214
+ func TestDriverSessionCreation (t * testing.T ) {
215
+ driverSessionCreationTests := []struct {
216
+ name string
217
+ testing string
218
+ mode AccessMode
219
+ bookmarks []string
220
+ }{
221
+ {"Write" , "bolt://localhost:7687" , AccessModeWrite , []string (nil )},
222
+ {"Read" , "bolt://localhost:7687" , AccessModeRead , []string (nil )},
223
+ {"Write+bookmarks" , "bolt://localhost:7687" , AccessModeWrite , []string {"B1" , "B2" , "B3" }},
224
+ {"Read+bookmarks" , "bolt://localhost:7687" , AccessModeRead , []string {"B1" , "B2" , "B3" , "B4" }},
225
+ }
186
226
187
- func TestDriverSessionCreationX (t * testing.T ) {
188
227
for _ , tt := range driverSessionCreationTests {
189
228
t .Run (tt .name , func (t * testing.T ) {
190
229
driver , err := NewDriver (tt .testing , NoAuth ())
0 commit comments