mirror of
https://github.com/docker/docker-credential-helpers.git
synced 2026-06-13 16:01:28 +05:30
registryurl: use sub-tests
Also reformat the test-table to easier see what fields are used for each test in the table. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
+52
-25
@@ -13,34 +13,61 @@ func TestHelperParseURL(t *testing.T) {
|
|||||||
expectedURL string
|
expectedURL string
|
||||||
err error
|
err error
|
||||||
}{
|
}{
|
||||||
{url: "foobar.docker.io", expectedURL: "//foobar.docker.io"},
|
{
|
||||||
{url: "foobar.docker.io:2376", expectedURL: "//foobar.docker.io:2376"},
|
url: "foobar.docker.io",
|
||||||
{url: "//foobar.docker.io:2376", expectedURL: "//foobar.docker.io:2376"},
|
expectedURL: "//foobar.docker.io",
|
||||||
{url: "http://foobar.docker.io:2376", expectedURL: "http://foobar.docker.io:2376"},
|
},
|
||||||
{url: "https://foobar.docker.io:2376", expectedURL: "https://foobar.docker.io:2376"},
|
{
|
||||||
{url: "https://foobar.docker.io:2376/some/path", expectedURL: "https://foobar.docker.io:2376/some/path"},
|
url: "foobar.docker.io:2376",
|
||||||
{url: "https://foobar.docker.io:2376/some/other/path?foo=bar", expectedURL: "https://foobar.docker.io:2376/some/other/path"},
|
expectedURL: "//foobar.docker.io:2376",
|
||||||
{url: "/foobar.docker.io", err: errors.New("no hostname in URL")},
|
},
|
||||||
{url: "ftp://foobar.docker.io:2376", err: errors.New("unsupported scheme: ftp")},
|
{
|
||||||
|
url: "//foobar.docker.io:2376",
|
||||||
|
expectedURL: "//foobar.docker.io:2376",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
url: "http://foobar.docker.io:2376",
|
||||||
|
expectedURL: "http://foobar.docker.io:2376",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
url: "https://foobar.docker.io:2376",
|
||||||
|
expectedURL: "https://foobar.docker.io:2376",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
url: "https://foobar.docker.io:2376/some/path",
|
||||||
|
expectedURL: "https://foobar.docker.io:2376/some/path",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
url: "https://foobar.docker.io:2376/some/other/path?foo=bar",
|
||||||
|
expectedURL: "https://foobar.docker.io:2376/some/other/path",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
url: "/foobar.docker.io",
|
||||||
|
err: errors.New("no hostname in URL"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
url: "ftp://foobar.docker.io:2376",
|
||||||
|
err: errors.New("unsupported scheme: ftp"),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range tests {
|
for _, tc := range tests {
|
||||||
u, err := Parse(tc.url)
|
tc := tc
|
||||||
|
t.Run(tc.url, func(t *testing.T) {
|
||||||
|
u, err := Parse(tc.url)
|
||||||
|
|
||||||
if tc.err == nil && err != nil {
|
if tc.err == nil && err != nil {
|
||||||
t.Errorf("Error: failed to parse URL %q: %s", tc.url, err)
|
t.Fatalf("Error: failed to parse URL %q: %s", tc.url, err)
|
||||||
continue
|
}
|
||||||
}
|
if tc.err != nil && err == nil {
|
||||||
if tc.err != nil && err == nil {
|
t.Fatalf("Error: expected error %q, got none when parsing URL %q", tc.err, tc.url)
|
||||||
t.Errorf("Error: expected error %q, got none when parsing URL %q", tc.err, tc.url)
|
}
|
||||||
continue
|
if tc.err != nil && err.Error() != tc.err.Error() {
|
||||||
}
|
t.Fatalf("Error: expected error %q, got %q when parsing URL %q", tc.err, err, tc.url)
|
||||||
if tc.err != nil && err.Error() != tc.err.Error() {
|
}
|
||||||
t.Errorf("Error: expected error %q, got %q when parsing URL %q", tc.err, err, tc.url)
|
if u != nil && u.String() != tc.expectedURL {
|
||||||
continue
|
t.Errorf("Error: expected URL: %q, but got %q for URL: %q", tc.expectedURL, u.String(), tc.url)
|
||||||
}
|
}
|
||||||
if u != nil && u.String() != tc.expectedURL {
|
})
|
||||||
t.Errorf("Error: expected URL: %q, but got %q for URL: %q", tc.expectedURL, u.String(), tc.url)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user