mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
client: refactor ServerVersion to return ServerVersionResult
Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Austin Vazquez <austin.vazquez@docker.com> Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
committed by
Sebastiaan van Stijn
parent
32f90ab113
commit
860307c4ea
@@ -953,7 +953,7 @@ func TestEmptyPortBindingsBC(t *testing.T) {
|
||||
|
||||
// Skip this subtest if the daemon doesn't support the client version.
|
||||
// TODO(aker): drop this once the Engine supports API version >= 1.53
|
||||
_, err := apiClient.ServerVersion(ctx)
|
||||
_, err := apiClient.ServerVersion(ctx, client.ServerVersionOptions{})
|
||||
if err != nil && strings.Contains(err.Error(), fmt.Sprintf("client version %s is too new", version)) {
|
||||
t.Skipf("requires API %s", version)
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ func TestAuthZPluginAllowRequest(t *testing.T) {
|
||||
assertURIRecorded(t, ctrl.requestsURIs, "/containers/create")
|
||||
assertURIRecorded(t, ctrl.requestsURIs, fmt.Sprintf("/containers/%s/start", cID))
|
||||
|
||||
_, err := c.ServerVersion(ctx)
|
||||
_, err := c.ServerVersion(ctx, client.ServerVersionOptions{})
|
||||
assert.NilError(t, err)
|
||||
assert.Equal(t, 1, ctrl.versionReqCount)
|
||||
assert.Equal(t, 1, ctrl.versionResCount)
|
||||
@@ -137,7 +137,7 @@ func TestAuthZPluginTLS(t *testing.T) {
|
||||
c, err := newTLSAPIClient(testDaemonHTTPSAddr, cacertPath, clientCertPath, clientKeyPath)
|
||||
assert.NilError(t, err)
|
||||
|
||||
_, err = c.ServerVersion(ctx)
|
||||
_, err = c.ServerVersion(ctx, client.ServerVersionOptions{})
|
||||
assert.NilError(t, err)
|
||||
|
||||
assert.Equal(t, "client", ctrl.reqUser)
|
||||
@@ -165,7 +165,7 @@ func TestAuthZPluginDenyRequest(t *testing.T) {
|
||||
c := d.NewClientT(t)
|
||||
|
||||
// Ensure command is blocked
|
||||
_, err := c.ServerVersion(ctx)
|
||||
_, err := c.ServerVersion(ctx, client.ServerVersionOptions{})
|
||||
assert.Assert(t, err != nil)
|
||||
assert.Equal(t, 1, ctrl.versionReqCount)
|
||||
assert.Equal(t, 0, ctrl.versionResCount)
|
||||
@@ -211,7 +211,7 @@ func TestAuthZPluginDenyResponse(t *testing.T) {
|
||||
c := d.NewClientT(t)
|
||||
|
||||
// Ensure command is blocked
|
||||
_, err := c.ServerVersion(ctx)
|
||||
_, err := c.ServerVersion(ctx, client.ServerVersionOptions{})
|
||||
assert.Assert(t, err != nil)
|
||||
assert.Equal(t, 1, ctrl.versionReqCount)
|
||||
assert.Equal(t, 1, ctrl.versionResCount)
|
||||
@@ -304,7 +304,7 @@ func TestAuthZPluginErrorResponse(t *testing.T) {
|
||||
c := d.NewClientT(t)
|
||||
|
||||
// Ensure command is blocked
|
||||
_, err := c.ServerVersion(ctx)
|
||||
_, err := c.ServerVersion(ctx, client.ServerVersionOptions{})
|
||||
assert.Assert(t, err != nil)
|
||||
assert.Equal(t, fmt.Sprintf("Error response from daemon: plugin %s failed with error: %s: %s", testAuthZPlugin, authorization.AuthZApiResponse, errorMessage), err.Error())
|
||||
}
|
||||
@@ -317,7 +317,7 @@ func TestAuthZPluginErrorRequest(t *testing.T) {
|
||||
c := d.NewClientT(t)
|
||||
|
||||
// Ensure command is blocked
|
||||
_, err := c.ServerVersion(ctx)
|
||||
_, err := c.ServerVersion(ctx, client.ServerVersionOptions{})
|
||||
assert.Assert(t, err != nil)
|
||||
assert.Equal(t, fmt.Sprintf("Error response from daemon: plugin %s failed with error: %s: %s", testAuthZPlugin, authorization.AuthZApiRequest, errorMessage), err.Error())
|
||||
}
|
||||
@@ -331,7 +331,7 @@ func TestAuthZPluginEnsureNoDuplicatePluginRegistration(t *testing.T) {
|
||||
|
||||
c := d.NewClientT(t)
|
||||
|
||||
_, err := c.ServerVersion(ctx)
|
||||
_, err := c.ServerVersion(ctx, client.ServerVersionOptions{})
|
||||
assert.NilError(t, err)
|
||||
|
||||
// assert plugin is only called once..
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/moby/moby/api/types"
|
||||
"github.com/moby/moby/client"
|
||||
"github.com/moby/moby/v2/internal/testutil/request"
|
||||
"gotest.tools/v3/assert"
|
||||
@@ -16,26 +17,45 @@ func TestVersion(t *testing.T) {
|
||||
ctx := setupTest(t)
|
||||
apiClient := testEnv.APIClient()
|
||||
|
||||
version, err := apiClient.ServerVersion(ctx)
|
||||
version, err := apiClient.ServerVersion(ctx, client.ServerVersionOptions{})
|
||||
assert.NilError(t, err)
|
||||
assert.Check(t, len(version.Components) > 0, "expected at least one component in version.Components")
|
||||
|
||||
assert.Check(t, version.APIVersion != "")
|
||||
assert.Check(t, version.Version != "")
|
||||
assert.Check(t, version.MinAPIVersion != "")
|
||||
assert.Check(t, is.Equal(testEnv.DaemonInfo.ExperimentalBuild, version.Experimental))
|
||||
assert.Check(t, is.Equal(testEnv.DaemonInfo.OSType, version.Os))
|
||||
var engine types.ComponentVersion
|
||||
var found bool
|
||||
|
||||
for _, comp := range version.Components {
|
||||
if comp.Name == "Engine" {
|
||||
engine = comp
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
assert.Check(t, found, "Engine component not found in version.Components")
|
||||
assert.Equal(t, engine.Name, "Engine")
|
||||
assert.Check(t, engine.Version != "")
|
||||
assert.Equal(t, engine.Details["ApiVersion"], version.APIVersion)
|
||||
assert.Equal(t, engine.Details["MinAPIVersion"], version.MinAPIVersion)
|
||||
assert.Check(t, is.Equal(testEnv.DaemonInfo.OSType, engine.Details["Os"]))
|
||||
|
||||
experimentalStr := engine.Details["Experimental"]
|
||||
experimentalBool, err := strconv.ParseBool(experimentalStr)
|
||||
assert.NilError(t, err, "Experimental field in Engine details is not a valid boolean string")
|
||||
assert.Equal(t, testEnv.DaemonInfo.ExperimentalBuild, experimentalBool)
|
||||
}
|
||||
|
||||
func TestAPIClientVersionOldNotSupported(t *testing.T) {
|
||||
ctx := setupTest(t)
|
||||
major, minor, _ := strings.Cut(testEnv.DaemonVersion.MinAPIVersion, ".")
|
||||
minApiVersion := testEnv.DaemonMinAPIVersion
|
||||
major, minor, _ := strings.Cut(minApiVersion, ".")
|
||||
vMinInt, err := strconv.Atoi(minor)
|
||||
assert.NilError(t, err)
|
||||
vMinInt--
|
||||
version := fmt.Sprintf("%s.%d", major, vMinInt)
|
||||
apiClient := request.NewAPIClient(t, client.WithVersion(version))
|
||||
|
||||
expectedErrorMessage := fmt.Sprintf("Error response from daemon: client version %s is too old. Minimum supported API version is %s, please upgrade your client to a newer version", version, testEnv.DaemonVersion.MinAPIVersion)
|
||||
_, err = apiClient.ServerVersion(ctx)
|
||||
expectedErrorMessage := fmt.Sprintf("Error response from daemon: client version %s is too old. Minimum supported API version is %s, please upgrade your client to a newer version", version, minApiVersion)
|
||||
_, err = apiClient.ServerVersion(ctx, client.ServerVersionOptions{})
|
||||
assert.Error(t, err, expectedErrorMessage)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user