Skip to content

Commit e1897cb

Browse files
committed
api/server/middleware:use API-consts in tests
Use the API consts to have more realistic values in tests. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent 0fef6e1 commit e1897cb

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

api/server/middleware/version_test.go

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,27 @@ package middleware // import "github.com/docker/docker/api/server/middleware"
22

33
import (
44
"context"
5+
"fmt"
56
"net/http"
67
"net/http/httptest"
78
"runtime"
89
"testing"
910

11+
"github.com/docker/docker/api"
1012
"github.com/docker/docker/api/server/httputils"
1113
"gotest.tools/v3/assert"
1214
is "gotest.tools/v3/assert/cmp"
1315
)
1416

1517
func TestVersionMiddlewareVersion(t *testing.T) {
16-
defaultVersion := "1.10.0"
17-
minVersion := "1.2.0"
18-
expectedVersion := defaultVersion
18+
expectedVersion := "<not set>"
1919
handler := func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
2020
v := httputils.VersionFromContext(ctx)
2121
assert.Check(t, is.Equal(expectedVersion, v))
2222
return nil
2323
}
2424

25-
m := NewVersionMiddleware(defaultVersion, defaultVersion, minVersion)
25+
m := NewVersionMiddleware("1.2.3", api.DefaultVersion, api.MinSupportedAPIVersion)
2626
h := m.WrapHandler(handler)
2727

2828
req, _ := http.NewRequest(http.MethodGet, "/containers/json", nil)
@@ -35,19 +35,19 @@ func TestVersionMiddlewareVersion(t *testing.T) {
3535
errString string
3636
}{
3737
{
38-
expectedVersion: "1.10.0",
38+
expectedVersion: api.DefaultVersion,
3939
},
4040
{
41-
reqVersion: "1.9.0",
42-
expectedVersion: "1.9.0",
41+
reqVersion: api.MinSupportedAPIVersion,
42+
expectedVersion: api.MinSupportedAPIVersion,
4343
},
4444
{
4545
reqVersion: "0.1",
46-
errString: "client version 0.1 is too old. Minimum supported API version is 1.2.0, please upgrade your client to a newer version",
46+
errString: fmt.Sprintf("client version 0.1 is too old. Minimum supported API version is %s, please upgrade your client to a newer version", api.MinSupportedAPIVersion),
4747
},
4848
{
4949
reqVersion: "9999.9999",
50-
errString: "client version 9999.9999 is too new. Maximum supported API version is 1.10.0",
50+
errString: fmt.Sprintf("client version 9999.9999 is too new. Maximum supported API version is %s", api.DefaultVersion),
5151
},
5252
}
5353

@@ -71,9 +71,7 @@ func TestVersionMiddlewareWithErrorsReturnsHeaders(t *testing.T) {
7171
return nil
7272
}
7373

74-
defaultVersion := "1.10.0"
75-
minVersion := "1.2.0"
76-
m := NewVersionMiddleware(defaultVersion, defaultVersion, minVersion)
74+
m := NewVersionMiddleware("1.2.3", api.DefaultVersion, api.MinSupportedAPIVersion)
7775
h := m.WrapHandler(handler)
7876

7977
req, _ := http.NewRequest(http.MethodGet, "/containers/json", nil)
@@ -85,8 +83,8 @@ func TestVersionMiddlewareWithErrorsReturnsHeaders(t *testing.T) {
8583
assert.Check(t, is.ErrorContains(err, ""))
8684

8785
hdr := resp.Result().Header
88-
assert.Check(t, is.Contains(hdr.Get("Server"), "Docker/"+defaultVersion))
86+
assert.Check(t, is.Contains(hdr.Get("Server"), "Docker/1.2.3"))
8987
assert.Check(t, is.Contains(hdr.Get("Server"), runtime.GOOS))
90-
assert.Check(t, is.Equal(hdr.Get("API-Version"), defaultVersion))
88+
assert.Check(t, is.Equal(hdr.Get("API-Version"), api.DefaultVersion))
9189
assert.Check(t, is.Equal(hdr.Get("OSType"), runtime.GOOS))
9290
}

0 commit comments

Comments
 (0)