Skip to content

Commit 4a8c2d1

Browse files
committed
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 <[email protected]>
1 parent 810dcd4 commit 4a8c2d1

File tree

1 file changed

+52
-25
lines changed

1 file changed

+52
-25
lines changed

registryurl/parse_test.go

Lines changed: 52 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,34 +13,61 @@ func TestHelperParseURL(t *testing.T) {
1313
expectedURL string
1414
err error
1515
}{
16-
{url: "foobar.docker.io", expectedURL: "//foobar.docker.io"},
17-
{url: "foobar.docker.io:2376", expectedURL: "//foobar.docker.io:2376"},
18-
{url: "//foobar.docker.io:2376", expectedURL: "//foobar.docker.io:2376"},
19-
{url: "http://foobar.docker.io:2376", expectedURL: "http://foobar.docker.io:2376"},
20-
{url: "https://foobar.docker.io:2376", expectedURL: "https://foobar.docker.io:2376"},
21-
{url: "https://foobar.docker.io:2376/some/path", expectedURL: "https://foobar.docker.io:2376/some/path"},
22-
{url: "https://foobar.docker.io:2376/some/other/path?foo=bar", expectedURL: "https://foobar.docker.io:2376/some/other/path"},
23-
{url: "/foobar.docker.io", err: errors.New("no hostname in URL")},
24-
{url: "ftp://foobar.docker.io:2376", err: errors.New("unsupported scheme: ftp")},
16+
{
17+
url: "foobar.docker.io",
18+
expectedURL: "//foobar.docker.io",
19+
},
20+
{
21+
url: "foobar.docker.io:2376",
22+
expectedURL: "//foobar.docker.io:2376",
23+
},
24+
{
25+
url: "//foobar.docker.io:2376",
26+
expectedURL: "//foobar.docker.io:2376",
27+
},
28+
{
29+
url: "http://foobar.docker.io:2376",
30+
expectedURL: "http://foobar.docker.io:2376",
31+
},
32+
{
33+
url: "https://foobar.docker.io:2376",
34+
expectedURL: "https://foobar.docker.io:2376",
35+
},
36+
{
37+
url: "https://foobar.docker.io:2376/some/path",
38+
expectedURL: "https://foobar.docker.io:2376/some/path",
39+
},
40+
{
41+
url: "https://foobar.docker.io:2376/some/other/path?foo=bar",
42+
expectedURL: "https://foobar.docker.io:2376/some/other/path",
43+
},
44+
{
45+
url: "/foobar.docker.io",
46+
err: errors.New("no hostname in URL"),
47+
},
48+
{
49+
url: "ftp://foobar.docker.io:2376",
50+
err: errors.New("unsupported scheme: ftp"),
51+
},
2552
}
2653

2754
for _, tc := range tests {
28-
u, err := Parse(tc.url)
55+
tc := tc
56+
t.Run(tc.url, func(t *testing.T) {
57+
u, err := Parse(tc.url)
2958

30-
if tc.err == nil && err != nil {
31-
t.Errorf("Error: failed to parse URL %q: %s", tc.url, err)
32-
continue
33-
}
34-
if tc.err != nil && err == nil {
35-
t.Errorf("Error: expected error %q, got none when parsing URL %q", tc.err, tc.url)
36-
continue
37-
}
38-
if tc.err != nil && err.Error() != tc.err.Error() {
39-
t.Errorf("Error: expected error %q, got %q when parsing URL %q", tc.err, err, tc.url)
40-
continue
41-
}
42-
if u != nil && u.String() != tc.expectedURL {
43-
t.Errorf("Error: expected URL: %q, but got %q for URL: %q", tc.expectedURL, u.String(), tc.url)
44-
}
59+
if tc.err == nil && err != nil {
60+
t.Fatalf("Error: failed to parse URL %q: %s", tc.url, err)
61+
}
62+
if tc.err != nil && err == nil {
63+
t.Fatalf("Error: expected error %q, got none when parsing URL %q", tc.err, tc.url)
64+
}
65+
if tc.err != nil && err.Error() != tc.err.Error() {
66+
t.Fatalf("Error: expected error %q, got %q when parsing URL %q", tc.err, err, tc.url)
67+
}
68+
if u != nil && u.String() != tc.expectedURL {
69+
t.Errorf("Error: expected URL: %q, but got %q for URL: %q", tc.expectedURL, u.String(), tc.url)
70+
}
71+
})
4572
}
4673
}

0 commit comments

Comments
 (0)