mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
client: NegotiateAPIVersion: do not ignore (connection) errors from Ping
NegotiateAPIVersion was ignoring errors returned by Ping. The intent here was to handle API responses from a daemon that may be in an unhealthy state, however this case is already handled by Ping itself. Ping only returns an error when either failing to connect to the API (daemon not running or permissions errors), or when failing to parse the API response. Neither of those should be ignored in this code, or considered a successful "ping", so update the code to return Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@@ -354,6 +354,19 @@ func TestNegotiateAPVersionOverride(t *testing.T) {
|
||||
assert.Equal(t, client.ClientVersion(), expected)
|
||||
}
|
||||
|
||||
// TestNegotiateAPVersionConnectionFailure asserts that we do not modify the
|
||||
// API version when failing to connect.
|
||||
func TestNegotiateAPVersionConnectionFailure(t *testing.T) {
|
||||
const expected = "9.99"
|
||||
|
||||
client, err := NewClientWithOpts(WithHost("unix:///no-such-socket"))
|
||||
assert.NilError(t, err)
|
||||
|
||||
client.version = expected
|
||||
client.NegotiateAPIVersion(context.Background())
|
||||
assert.Equal(t, client.ClientVersion(), expected)
|
||||
}
|
||||
|
||||
func TestNegotiateAPIVersionAutomatic(t *testing.T) {
|
||||
var pingVersion string
|
||||
httpClient := newMockClient(func(req *http.Request) (*http.Response, error) {
|
||||
|
||||
Reference in New Issue
Block a user