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)
| 17 | // Some of this is just exercising the code paths to make sure there are no |
| 18 | // panics. |
| 19 | func 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. |
nothing calls this directly
no test coverage detected
searching dependent graphs…