Skip to content

Commit

Permalink
Split TestValidateKey into invalid/valid tests
Browse files Browse the repository at this point in the history
Pedantically this avoids testing isNamespaced on invalid
keys, where it is undefined; more importantly it allows
making the tests more readable, as we add more tests, without
a sea of misaligned true/false values.

Signed-off-by: Miloslav Trmač <[email protected]>
  • Loading branch information
mtrmac committed Sep 11, 2021
1 parent 2341e52 commit 8d8db25
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions pkg/docker/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -859,24 +859,26 @@ func TestRemoveAuthentication(t *testing.T) {
}

func TestValidateKey(t *testing.T) {
// Invalid keys
for _, key := range []string{
"https://my-registry.local",
} {
_, err := validateKey(key)
assert.Error(t, err, key)
}

// Valid keys
for _, tc := range []struct {
key string
shouldError bool
isNamespaced bool
}{
{"my-registry.local", false, false},
{"https://my-registry.local", true, false},
{"my-registry.local/path", false, true},
{"quay.io/a/b/c/d", false, true},
{"my-registry.local", false},
{"my-registry.local/path", true},
{"quay.io/a/b/c/d", true},
} {

isNamespaced, err := validateKey(tc.key)
if tc.shouldError {
assert.Error(t, err)
} else {
assert.NoError(t, err)
}
assert.Equal(t, tc.isNamespaced, isNamespaced)
require.NoError(t, err, tc.key)
assert.Equal(t, tc.isNamespaced, isNamespaced, tc.key)
}
}

Expand Down

0 comments on commit 8d8db25

Please sign in to comment.