MCPcopy
hub / github.com/moby/moby / TestPingFail

Function TestPingFail

client/ping_test.go:19–46  ·  view source on GitHub ↗

TestPingFail tests that when a server sends a non-successful response that we can still grab API details, when set. Some of this is just exercising the code paths to make sure there are no panics.

(t *testing.T)

Source from the content-addressed store, hash-verified

17// Some of this is just exercising the code paths to make sure there are no
18// panics.
19func TestPingFail(t *testing.T) {
20 var withHeader bool
21 client, err := New(WithBaseMockClient(func(req *http.Request) (*http.Response, error) {
22 var hdr http.Header
23 if withHeader {
24 hdr = http.Header{}
25 hdr.Set("Api-Version", "awesome")
26 hdr.Set("Docker-Experimental", "true")
27 hdr.Set("Swarm", "inactive")
28 }
29 return mockResponse(http.StatusInternalServerError, hdr, "some error with the server")(req)
30 }))
31 assert.NilError(t, err)
32
33 ping, err := client.Ping(t.Context(), PingOptions{})
34 assert.Check(t, is.ErrorContains(err, "some error with the server"))
35 assert.Check(t, is.Equal(false, ping.Experimental))
36 assert.Check(t, is.Equal("", ping.APIVersion))
37 var si *SwarmStatus
38 assert.Check(t, is.Equal(si, ping.SwarmStatus))
39
40 withHeader = true
41 ping2, err := client.Ping(t.Context(), PingOptions{})
42 assert.Check(t, is.ErrorContains(err, "some error with the server"))
43 assert.Check(t, is.Equal(true, ping2.Experimental))
44 assert.Check(t, is.Equal("awesome", ping2.APIVersion))
45 assert.Check(t, is.Equal(SwarmStatus{NodeState: "inactive"}, *ping2.SwarmStatus))
46}
47
48// TestPingWithError tests the case where there is a protocol error in the ping.
49// This test is mostly just testing that there are no panics in this code path.

Callers

nothing calls this directly

Calls 8

WithBaseMockClientFunction · 0.85
mockResponseFunction · 0.85
CheckMethod · 0.80
EqualMethod · 0.80
NewFunction · 0.70
SetMethod · 0.65
PingMethod · 0.65
ContextMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…