1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

client: TestGetAPIPath(): update test to use more realistic results

This test was setting the non-exported `Client.basePath` directly, however,
it was setting it to a value that would never realistically happen, because
`NewClientWithOpts()` initializes the Client with the default API version:
ea5b4765d9/client/client.go (L119-L130)

Which is used by `getAPIPath()` to construct the URL/path:
ea5b4765d9/client/client.go (L176-L190)

While this didn't render the test "invalid", using a Client that's constructed
in the usual way, makes it more representative.

Given that we deprecated (but still support) the non-versioned API paths, with
the exception of the `/_ping` API endpoint, we should probably change `getAPIPath()`
to default to the "current version", instead of allowing it to use an empty string.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2022-03-07 11:12:32 +01:00
parent 65e4ea27cd
commit 25a336ab6a
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C

View file

@ -113,9 +113,9 @@ func TestGetAPIPath(t *testing.T) {
query url.Values query url.Values
expected string expected string
}{ }{
{"", "/containers/json", nil, "/containers/json"}, {"", "/containers/json", nil, "/v" + api.DefaultVersion + "/containers/json"},
{"", "/containers/json", url.Values{}, "/containers/json"}, {"", "/containers/json", url.Values{}, "/v" + api.DefaultVersion + "/containers/json"},
{"", "/containers/json", url.Values{"s": []string{"c"}}, "/containers/json?s=c"}, {"", "/containers/json", url.Values{"s": []string{"c"}}, "/v" + api.DefaultVersion + "/containers/json?s=c"},
{"1.22", "/containers/json", nil, "/v1.22/containers/json"}, {"1.22", "/containers/json", nil, "/v1.22/containers/json"},
{"1.22", "/containers/json", url.Values{}, "/v1.22/containers/json"}, {"1.22", "/containers/json", url.Values{}, "/v1.22/containers/json"},
{"1.22", "/containers/json", url.Values{"s": []string{"c"}}, "/v1.22/containers/json?s=c"}, {"1.22", "/containers/json", url.Values{"s": []string{"c"}}, "/v1.22/containers/json?s=c"},
@ -127,10 +127,11 @@ func TestGetAPIPath(t *testing.T) {
ctx := context.TODO() ctx := context.TODO()
for _, tc := range testcases { for _, tc := range testcases {
client := Client{ client, err := NewClientWithOpts(
version: tc.version, WithVersion(tc.version),
basePath: "/", WithHost("tcp://localhost:2375"),
} )
assert.NilError(t, err)
actual := client.getAPIPath(ctx, tc.path, tc.query) actual := client.getAPIPath(ctx, tc.path, tc.query)
assert.Check(t, is.Equal(actual, tc.expected)) assert.Check(t, is.Equal(actual, tc.expected))
} }