Skip to content

Commit 349abc6

Browse files
committed
client: fix TestPingWithError
This test was added in 27ef09a, which changed the Ping handling to ignore internal server errors. That case is tested in TestPingFail, which verifies that we accept the Ping response if a 500 status code was received. The TestPingWithError test was added to verify behavior if a protocol (connection) error occurred; however the mock-client returned both a response, and an error; the error returned would only happen if a connection error occurred, which means that the server would not provide a reply. Running the test also shows that returning a response is unexpected, and ignored: === RUN TestPingWithError 2024/02/23 14:16:49 RoundTripper returned a response & error; ignoring response 2024/02/23 14:16:49 RoundTripper returned a response & error; ignoring response --- PASS: TestPingWithError (0.00s) PASS This patch updates the test to remove the response. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 24fe934 commit 349abc6

1 file changed

Lines changed: 2 additions & 8 deletions

File tree

client/ping_test.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,12 @@ func TestPingFail(t *testing.T) {
5353
func TestPingWithError(t *testing.T) {
5454
client := &Client{
5555
client: newMockClient(func(req *http.Request) (*http.Response, error) {
56-
resp := &http.Response{StatusCode: http.StatusInternalServerError}
57-
resp.Header = http.Header{}
58-
resp.Header.Set("API-Version", "awesome")
59-
resp.Header.Set("Docker-Experimental", "true")
60-
resp.Header.Set("Swarm", "active/manager")
61-
resp.Body = io.NopCloser(strings.NewReader("some error with the server"))
62-
return resp, errors.New("some error")
56+
return nil, errors.New("some connection error")
6357
}),
6458
}
6559

6660
ping, err := client.Ping(context.Background())
67-
assert.Check(t, is.ErrorContains(err, "some error"))
61+
assert.Check(t, is.ErrorContains(err, "some connection error"))
6862
assert.Check(t, is.Equal(false, ping.Experimental))
6963
assert.Check(t, is.Equal("", ping.APIVersion))
7064
var si *swarm.Status

0 commit comments

Comments
 (0)