integration-cli: TestAPIClientVersionOldNotSupported: use daemon API version

Use the minimum API version as advertised by the test-daemon, instead of the
hard-coded API version from code.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2023-12-04 22:58:47 +01:00
parent 97549d923c
commit 7f68e3107e
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C

View file

@ -10,7 +10,6 @@ import (
"strings"
"testing"
"github.com/docker/docker/api"
"github.com/docker/docker/api/types/versions"
"github.com/docker/docker/runconfig"
"github.com/docker/docker/testutil"
@ -52,21 +51,18 @@ func (s *DockerAPISuite) TestAPIClientVersionOldNotSupported(c *testing.T) {
if testEnv.DaemonInfo.OSType != runtime.GOOS {
c.Skip("Daemon platform doesn't match test platform")
}
if api.MinVersion == api.DefaultVersion {
c.Skip("API MinVersion==DefaultVersion")
}
v := strings.Split(api.MinVersion, ".")
vMinInt, err := strconv.Atoi(v[1])
major, minor, _ := strings.Cut(testEnv.DaemonVersion.MinAPIVersion, ".")
vMinInt, err := strconv.Atoi(minor)
assert.NilError(c, err)
vMinInt--
v[1] = strconv.Itoa(vMinInt)
version := strings.Join(v, ".")
version := fmt.Sprintf("%s.%d", major, vMinInt)
resp, body, err := request.Get(testutil.GetContext(c), "/v"+version+"/version")
assert.NilError(c, err)
defer body.Close()
assert.Equal(c, resp.StatusCode, http.StatusBadRequest)
expected := fmt.Sprintf("client version %s is too old. Minimum supported API version is %s, please upgrade your client to a newer version", version, api.MinVersion)
expected := fmt.Sprintf("client version %s is too old. Minimum supported API version is %s, please upgrade your client to a newer version", version, testEnv.DaemonVersion.MinAPIVersion)
content, err := io.ReadAll(body)
assert.NilError(c, err)
assert.Equal(c, strings.TrimSpace(string(content)), expected)