mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #39043 from thaJeztah/dont_pin_version_if_empty
Fix empty WithVersion blocking version negotiation
This commit is contained in:
commit
8aa3262f29
2 changed files with 26 additions and 3 deletions
|
@ -265,6 +265,26 @@ func TestNegotiateAPVersionOverride(t *testing.T) {
|
|||
assert.Check(t, is.Equal(expected, client.version))
|
||||
}
|
||||
|
||||
// TestNegotiateAPIVersionWithEmptyVersion asserts that initializing a client
|
||||
// with an empty version string does still allow API-version negotiation
|
||||
func TestNegotiateAPIVersionWithEmptyVersion(t *testing.T) {
|
||||
client, err := NewClientWithOpts(WithVersion(""))
|
||||
assert.NilError(t, err)
|
||||
|
||||
client.NegotiateAPIVersionPing(types.Ping{APIVersion: "1.35"})
|
||||
assert.Equal(t, client.version, "1.35")
|
||||
}
|
||||
|
||||
// TestNegotiateAPIVersionWithFixedVersion asserts that initializing a client
|
||||
// with an fixed version disables API-version negotiation
|
||||
func TestNegotiateAPIVersionWithFixedVersion(t *testing.T) {
|
||||
client, err := NewClientWithOpts(WithVersion("1.35"))
|
||||
assert.NilError(t, err)
|
||||
|
||||
client.NegotiateAPIVersionPing(types.Ping{APIVersion: "1.31"})
|
||||
assert.Equal(t, client.version, "1.35")
|
||||
}
|
||||
|
||||
type roundTripFunc func(*http.Request) (*http.Response, error)
|
||||
|
||||
func (rtf roundTripFunc) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||
|
|
|
@ -139,11 +139,14 @@ func WithTLSClientConfig(cacertPath, certPath, keyPath string) Opt {
|
|||
}
|
||||
}
|
||||
|
||||
// WithVersion overrides the client version with the specified one
|
||||
// WithVersion overrides the client version with the specified one. If an empty
|
||||
// version is specified, the value will be ignored to allow version negotiation.
|
||||
func WithVersion(version string) Opt {
|
||||
return func(c *Client) error {
|
||||
c.version = version
|
||||
c.manualOverride = true
|
||||
if version != "" {
|
||||
c.version = version
|
||||
c.manualOverride = true
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue