Skip to content

Commit d68e815

Browse files
author
Richa Gangwar
committed
wsclient: Add test to getClientServer() in client tests, make comments as complete sentences
1 parent 59cffd2 commit d68e815

File tree

1 file changed

+25
-26
lines changed

1 file changed

+25
-26
lines changed

ecs-agent/wsclient/client_test.go

+25-26
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const dockerEndpoint = "/var/run/docker.sock"
4646

4747
// Close closes the underlying connection. Implement Close() in this file
4848
// as ClientServerImpl doesn't implement it. This is needed by the
49-
// TestSetReadDeadline* tests
49+
// TestSetReadDeadline* tests.
5050
func (cs *ClientServerImpl) Close() error {
5151
return cs.Disconnect()
5252
}
@@ -57,15 +57,15 @@ func TestClientProxy(t *testing.T) {
5757
defer os.Unsetenv("HTTP_PROXY")
5858

5959
types := []interface{}{ecsacs.AckRequest{}}
60-
cs := getClientServer("http://www.amazon.com", types)
60+
cs := getTestClientServer("http://www.amazon.com", types)
6161
err := cs.Connect()
6262
assert.Error(t, err)
6363
assert.True(t, strings.Contains(err.Error(), proxy_url), "proxy not found: %s", err.Error())
6464
}
6565

6666
// TestConcurrentWritesDontPanic will force a panic in the websocket library if
67-
// the implemented methods don't handle concurrency correctly
68-
// See https://godoc.org/github.com/gorilla/websocket#hdr-Concurrency
67+
// the implemented methods don't handle concurrency correctly.
68+
// See https://godoc.org/github.com/gorilla/websocket#hdr-Concurrency.
6969
func TestConcurrentWritesDontPanic(t *testing.T) {
7070
closeWS := make(chan []byte)
7171
defer close(closeWS)
@@ -86,7 +86,7 @@ func TestConcurrentWritesDontPanic(t *testing.T) {
8686
req := ecsacs.AckRequest{Cluster: aws.String("test"), ContainerInstance: aws.String("test"), MessageId: aws.String("test")}
8787

8888
types := []interface{}{ecsacs.AckRequest{}}
89-
cs := getClientServer(mockServer.URL, types)
89+
cs := getTestClientServer(mockServer.URL, types)
9090
require.NoError(t, cs.Connect())
9191

9292
executeTenRequests := func() {
@@ -96,16 +96,15 @@ func TestConcurrentWritesDontPanic(t *testing.T) {
9696
}
9797

9898
// Make requests from two separate routines to try and force a
99-
// concurrent write
99+
// concurrent write.
100100
go executeTenRequests()
101101
go executeTenRequests()
102102

103103
t.Log("Waiting for all 20 requests to succeed")
104104
waitForRequests.Wait()
105105
}
106106

107-
func getClientServer(url string, msgType []interface{}) *ClientServerImpl {
108-
107+
func getTestClientServer(url string, msgType []interface{}) *ClientServerImpl {
109108
testCreds := credentials.NewStaticCredentials("test-id", "test-secret", "test-token")
110109

111110
return &ClientServerImpl{
@@ -124,7 +123,7 @@ func getClientServer(url string, msgType []interface{}) *ClientServerImpl {
124123
}
125124

126125
// TestProxyVariableCustomValue ensures that a user is able to override the
127-
// proxy variable by setting an environment variable
126+
// proxy variable by setting an environment variable.
128127
func TestProxyVariableCustomValue(t *testing.T) {
129128
closeWS := make(chan []byte)
130129
defer close(closeWS)
@@ -136,13 +135,13 @@ func TestProxyVariableCustomValue(t *testing.T) {
136135
testString := "Custom no proxy string"
137136
os.Setenv("NO_PROXY", testString)
138137
types := []interface{}{ecsacs.AckRequest{}}
139-
require.NoError(t, getClientServer(mockServer.URL, types).Connect())
138+
require.NoError(t, getTestClientServer(mockServer.URL, types).Connect())
140139

141140
assert.Equal(t, os.Getenv("NO_PROXY"), testString, "NO_PROXY should match user-supplied variable")
142141
}
143142

144143
// TestProxyVariableDefaultValue verifies that NO_PROXY gets overridden if it
145-
// isn't already set
144+
// isn't already set.
146145
func TestProxyVariableDefaultValue(t *testing.T) {
147146
closeWS := make(chan []byte)
148147
defer close(closeWS)
@@ -153,15 +152,15 @@ func TestProxyVariableDefaultValue(t *testing.T) {
153152

154153
os.Unsetenv("NO_PROXY")
155154
types := []interface{}{ecsacs.AckRequest{}}
156-
getClientServer(mockServer.URL, types).Connect()
155+
getTestClientServer(mockServer.URL, types).Connect()
157156

158157
expectedEnvVar := "169.254.169.254,169.254.170.2," + dockerEndpoint
159158

160159
assert.Equal(t, os.Getenv("NO_PROXY"), expectedEnvVar, "Variable NO_PROXY expected to be overwritten when no default value supplied")
161160
}
162161

163162
// TestHandleMessagePermissibleCloseCode ensures that permissible close codes
164-
// are wrapped in io.EOF
163+
// are wrapped in io.EOF.
165164
func TestHandleMessagePermissibleCloseCode(t *testing.T) {
166165
closeWS := make(chan []byte)
167166
defer close(closeWS)
@@ -172,7 +171,7 @@ func TestHandleMessagePermissibleCloseCode(t *testing.T) {
172171
mockServer.StartTLS()
173172

174173
types := []interface{}{ecsacs.AckRequest{}}
175-
cs := getClientServer(mockServer.URL, types)
174+
cs := getTestClientServer(mockServer.URL, types)
176175
require.NoError(t, cs.Connect())
177176
assert.True(t, cs.IsReady(), "expected websocket connection to be ready")
178177

@@ -185,7 +184,7 @@ func TestHandleMessagePermissibleCloseCode(t *testing.T) {
185184
}
186185

187186
// TestHandleMessageUnexpectedCloseCode checks that unexpected close codes will
188-
// be returned as is (not wrapped in io.EOF)
187+
// be returned as is (not wrapped in io.EOF).
189188
func TestHandleMessageUnexpectedCloseCode(t *testing.T) {
190189
closeWS := make(chan []byte)
191190
defer close(closeWS)
@@ -195,7 +194,7 @@ func TestHandleMessageUnexpectedCloseCode(t *testing.T) {
195194
mockServer.StartTLS()
196195

197196
types := []interface{}{ecsacs.AckRequest{}}
198-
cs := getClientServer(mockServer.URL, types)
197+
cs := getTestClientServer(mockServer.URL, types)
199198
require.NoError(t, cs.Connect())
200199
assert.True(t, cs.IsReady(), "expected websocket connection to be ready")
201200

@@ -209,7 +208,7 @@ func TestHandleMessageUnexpectedCloseCode(t *testing.T) {
209208
}
210209

211210
// TestHandlNonHTTPSEndpoint verifies that the wsclient can handle communication over
212-
// an HTTP (so WS) connection
211+
// an HTTP (so WS) connection.
213212
func TestHandleNonHTTPSEndpoint(t *testing.T) {
214213
closeWS := make(chan []byte)
215214
defer close(closeWS)
@@ -219,7 +218,7 @@ func TestHandleNonHTTPSEndpoint(t *testing.T) {
219218
defer mockServer.Close()
220219

221220
types := []interface{}{ecsacs.AckRequest{}}
222-
cs := getClientServer(mockServer.URL, types)
221+
cs := getTestClientServer(mockServer.URL, types)
223222
require.NoError(t, cs.Connect())
224223
assert.True(t, cs.IsReady(), "expected websocket connection to be ready")
225224

@@ -231,7 +230,7 @@ func TestHandleNonHTTPSEndpoint(t *testing.T) {
231230
}
232231

233232
// TestHandleIncorrectHttpScheme checks that an incorrect URL scheme results in
234-
// an error
233+
// an error.
235234
func TestHandleIncorrectURLScheme(t *testing.T) {
236235
closeWS := make(chan []byte)
237236
defer close(closeWS)
@@ -244,16 +243,16 @@ func TestHandleIncorrectURLScheme(t *testing.T) {
244243
mockServerURL.Scheme = "notaparticularlyrealscheme"
245244

246245
types := []interface{}{ecsacs.AckRequest{}}
247-
cs := getClientServer(mockServerURL.String(), types)
246+
cs := getTestClientServer(mockServerURL.String(), types)
248247
err := cs.Connect()
249248

250249
assert.Error(t, err, "Expected error for incorrect URL scheme")
251250
}
252251

253252
// TestWebsocketScheme checks that websocketScheme handles valid and invalid mappings
254-
// correctly
253+
// correctly.
255254
func TestWebsocketScheme(t *testing.T) {
256-
// test valid schemes
255+
// Test valid schemes.
257256
validMappings := map[string]string{
258257
"http": "ws",
259258
"https": "wss",
@@ -266,7 +265,7 @@ func TestWebsocketScheme(t *testing.T) {
266265
assert.Equal(t, actualOutput, expectedOutput, "Valid http schemes should map to a websocket scheme")
267266
}
268267

269-
// test an invalid mapping
268+
// Test an invalid mapping.
270269
_, err := websocketScheme("highly-likely-to-be-junk")
271270
assert.Error(t, err, "Expected error for invalid http scheme")
272271
}
@@ -322,7 +321,7 @@ func TestAddRequestPayloadHandler(t *testing.T) {
322321

323322
types := []interface{}{ecsacs.PayloadMessage{}}
324323
messageError := make(chan error)
325-
cs := getClientServer(mockServer.URL, types)
324+
cs := getTestClientServer(mockServer.URL, types)
326325
cs.conn = conn
327326

328327
defer cs.Close()
@@ -365,7 +364,7 @@ func TestMakeUnrecognizedRequest(t *testing.T) {
365364
mockServer.StartTLS()
366365

367366
types := []interface{}{ecsacs.PayloadMessage{}}
368-
cs := getClientServer(mockServer.URL, types)
367+
cs := getTestClientServer(mockServer.URL, types)
369368
cs.conn = conn
370369

371370
defer cs.Close()
@@ -389,7 +388,7 @@ func TestWriteCloseMessage(t *testing.T) {
389388
mockServer.StartTLS()
390389

391390
types := []interface{}{ecsacs.PayloadMessage{}}
392-
cs := getClientServer(mockServer.URL, types)
391+
cs := getTestClientServer(mockServer.URL, types)
393392
cs.Connect()
394393

395394
defer cs.Close()

0 commit comments

Comments
 (0)