@@ -50,16 +50,8 @@ var _ driver.Handshaker = &testHandshaker{}
50
50
func TestConnection (t * testing.T ) {
51
51
t .Run ("connection" , func (t * testing.T ) {
52
52
t .Run ("newConnection" , func (t * testing.T ) {
53
- t .Run ("config error" , func (t * testing.T ) {
54
- want := errors .New ("config error" )
55
- _ , got := newConnection (address .Address ("" ), ConnectionOption (func (* connectionConfig ) error { return want }))
56
- if ! cmp .Equal (got , want , cmp .Comparer (compareErrors )) {
57
- t .Errorf ("errors do not match. got %v; want %v" , got , want )
58
- }
59
- })
60
53
t .Run ("no default idle timeout" , func (t * testing.T ) {
61
- conn , err := newConnection (address .Address ("" ))
62
- assert .Nil (t , err , "newConnection error: %v" , err )
54
+ conn := newConnection (address .Address ("" ))
63
55
wantTimeout := time .Duration (0 )
64
56
assert .Equal (t , wantTimeout , conn .idleTimeout , "expected idle timeout %v, got %v" , wantTimeout ,
65
57
conn .idleTimeout )
@@ -69,13 +61,10 @@ func TestConnection(t *testing.T) {
69
61
t .Run ("dialer error" , func (t * testing.T ) {
70
62
err := errors .New ("dialer error" )
71
63
var want error = ConnectionError {Wrapped : err , init : true }
72
- conn , got := newConnection (address .Address ("" ), WithDialer (func (Dialer ) Dialer {
64
+ conn := newConnection (address .Address ("" ), WithDialer (func (Dialer ) Dialer {
73
65
return DialerFunc (func (context.Context , string , string ) (net.Conn , error ) { return nil , err })
74
66
}))
75
- if got != nil {
76
- t .Errorf ("newConnection shouldn't error. got %v; want nil" , got )
77
- }
78
- got = conn .connect (context .Background ())
67
+ got := conn .connect (context .Background ())
79
68
if ! cmp .Equal (got , want , cmp .Comparer (compareErrors )) {
80
69
t .Errorf ("errors do not match. got %v; want %v" , got , want )
81
70
}
@@ -85,7 +74,7 @@ func TestConnection(t *testing.T) {
85
74
t .Run ("handshaker error" , func (t * testing.T ) {
86
75
err := errors .New ("handshaker error" )
87
76
var want error = ConnectionError {Wrapped : err , init : true }
88
- conn , got := newConnection (address .Address ("" ),
77
+ conn := newConnection (address .Address ("" ),
89
78
WithHandshaker (func (Handshaker ) Handshaker {
90
79
return & testHandshaker {
91
80
finishHandshake : func (context.Context , driver.Connection ) error {
@@ -99,10 +88,7 @@ func TestConnection(t *testing.T) {
99
88
})
100
89
}),
101
90
)
102
- if got != nil {
103
- t .Errorf ("newConnection shouldn't error. got %v; want nil" , got )
104
- }
105
- got = conn .connect (context .Background ())
91
+ got := conn .connect (context .Background ())
106
92
if ! cmp .Equal (got , want , cmp .Comparer (compareErrors )) {
107
93
t .Errorf ("errors do not match. got %v; want %v" , got , want )
108
94
}
@@ -117,7 +103,7 @@ func TestConnection(t *testing.T) {
117
103
t .Run ("connect succeeds" , func (t * testing.T ) {
118
104
// In the case where connect finishes successfully, it unpins the CancelFunc.
119
105
120
- conn , err := newConnection (address .Address ("" ),
106
+ conn := newConnection (address .Address ("" ),
121
107
WithDialer (func (Dialer ) Dialer {
122
108
return DialerFunc (func (context.Context , string , string ) (net.Conn , error ) {
123
109
return & net.TCPConn {}, nil
@@ -127,9 +113,8 @@ func TestConnection(t *testing.T) {
127
113
return & testHandshaker {}
128
114
}),
129
115
)
130
- assert .Nil (t , err , "newConnection error: %v" , err )
131
116
132
- err = conn .connect (context .Background ())
117
+ err : = conn .connect (context .Background ())
133
118
assert .Nil (t , err , "error establishing connection: %v" , err )
134
119
assert .Nil (t , conn .cancelConnectContext , "cancellation function was not cleared" )
135
120
})
@@ -140,7 +125,7 @@ func TestConnection(t *testing.T) {
140
125
// Create a connection that will block in connect until doneChan is closed. This prevents
141
126
// connect from succeeding and unpinning the CancelFunc.
142
127
doneChan := make (chan struct {})
143
- conn , err := newConnection (address .Address ("" ),
128
+ conn := newConnection (address .Address ("" ),
144
129
WithDialer (func (Dialer ) Dialer {
145
130
return DialerFunc (func (context.Context , string , string ) (net.Conn , error ) {
146
131
<- doneChan
@@ -151,7 +136,6 @@ func TestConnection(t *testing.T) {
151
136
return & testHandshaker {}
152
137
}),
153
138
)
154
- assert .Nil (t , err , "newConnection error: %v" , err )
155
139
156
140
// Call connect in a goroutine because it will block.
157
141
var wg sync.WaitGroup
@@ -170,8 +154,7 @@ func TestConnection(t *testing.T) {
170
154
})
171
155
t .Run ("tls" , func (t * testing.T ) {
172
156
t .Run ("connection source is set to default if unspecified" , func (t * testing.T ) {
173
- conn , err := newConnection (address .Address ("" ))
174
- assert .Nil (t , err , "newConnection error: %v" , err )
157
+ conn := newConnection (address .Address ("" ))
175
158
assert .NotNil (t , conn .config .tlsConnectionSource , "expected tlsConnectionSource to be set but was not" )
176
159
})
177
160
t .Run ("server name" , func (t * testing.T ) {
@@ -208,8 +191,7 @@ func TestConnection(t *testing.T) {
208
191
return testTLSConnectionSource
209
192
}),
210
193
}
211
- conn , err := newConnection (tc .addr , connOpts ... )
212
- assert .Nil (t , err , "newConnection error: %v" , err )
194
+ conn := newConnection (tc .addr , connOpts ... )
213
195
214
196
_ = conn .connect (context .Background ())
215
197
assert .NotNil (t , sentCfg , "expected TLS config to be set, but was not" )
@@ -250,8 +232,7 @@ func TestConnection(t *testing.T) {
250
232
return tc .connectTimeout
251
233
}),
252
234
}
253
- conn , err := newConnection ("" , connOpts ... )
254
- assert .Nil (t , err , "newConnection error: %v" , err )
235
+ conn := newConnection ("" , connOpts ... )
255
236
256
237
ctx , cancel := context .WithTimeout (context .Background (), tc .contextTimeout )
257
238
defer cancel ()
@@ -291,8 +272,7 @@ func TestConnection(t *testing.T) {
291
272
return hangingTLSConnectionSource
292
273
}),
293
274
}
294
- conn , err := newConnection ("" , connOpts ... )
295
- assert .Nil (t , err , "newConnection error: %v" , err )
275
+ conn := newConnection ("" , connOpts ... )
296
276
297
277
ctx , cancel := context .WithTimeout (context .Background (), tc .contextTimeout )
298
278
defer cancel ()
@@ -336,11 +316,10 @@ func TestConnection(t *testing.T) {
336
316
return handshaker
337
317
}),
338
318
}
339
- conn , err := newConnection ("" , connOpts ... )
340
- assert .Nil (t , err , "newConnection error: %v" , err )
319
+ conn := newConnection ("" , connOpts ... )
341
320
342
321
bgCtx := context .Background ()
343
- err = conn .connect (bgCtx )
322
+ err : = conn .connect (bgCtx )
344
323
assert .Nil (t , err , "connect error: %v" , err )
345
324
346
325
assertNoContextTimeout := func (t * testing.T , ctx context.Context ) {
@@ -697,7 +676,7 @@ func TestConnection(t *testing.T) {
697
676
})
698
677
t .Run ("close" , func (t * testing.T ) {
699
678
t .Run ("can close a connection that failed handshaking" , func (t * testing.T ) {
700
- conn , err := newConnection (address .Address ("" ),
679
+ conn := newConnection (address .Address ("" ),
701
680
WithHandshaker (func (Handshaker ) Handshaker {
702
681
return & testHandshaker {
703
682
finishHandshake : func (context.Context , driver.Connection ) error {
@@ -711,9 +690,8 @@ func TestConnection(t *testing.T) {
711
690
})
712
691
}),
713
692
)
714
- assert .Nil (t , err , "newConnection error: %v" , err )
715
693
716
- err = conn .connect (context .Background ())
694
+ err : = conn .connect (context .Background ())
717
695
assert .NotNil (t , err , "expected handshake error from connect, got nil" )
718
696
connState := atomic .LoadInt64 (& conn .connected )
719
697
assert .Equal (t , disconnected , connState , "expected connection state %v, got %v" , disconnected , connState )
0 commit comments