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:
parent
65e4ea27cd
commit
25a336ab6a
1 changed files with 8 additions and 7 deletions
|
@ -113,9 +113,9 @@ func TestGetAPIPath(t *testing.T) {
|
|||
query url.Values
|
||||
expected string
|
||||
}{
|
||||
{"", "/containers/json", nil, "/containers/json"},
|
||||
{"", "/containers/json", url.Values{}, "/containers/json"},
|
||||
{"", "/containers/json", url.Values{"s": []string{"c"}}, "/containers/json?s=c"},
|
||||
{"", "/containers/json", nil, "/v" + api.DefaultVersion + "/containers/json"},
|
||||
{"", "/containers/json", url.Values{}, "/v" + api.DefaultVersion + "/containers/json"},
|
||||
{"", "/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", url.Values{}, "/v1.22/containers/json"},
|
||||
{"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()
|
||||
for _, tc := range testcases {
|
||||
client := Client{
|
||||
version: tc.version,
|
||||
basePath: "/",
|
||||
}
|
||||
client, err := NewClientWithOpts(
|
||||
WithVersion(tc.version),
|
||||
WithHost("tcp://localhost:2375"),
|
||||
)
|
||||
assert.NilError(t, err)
|
||||
actual := client.getAPIPath(ctx, tc.path, tc.query)
|
||||
assert.Check(t, is.Equal(actual, tc.expected))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue