forked from TrueCloudLab/distribution
reference: use consistent names for test-tables
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
8900e90699
commit
fcbddfc6ae
3 changed files with 135 additions and 135 deletions
|
@ -146,7 +146,7 @@ func TestParseRepositoryInfo(t *testing.T) {
|
||||||
RemoteName, FamiliarName, FullName, AmbiguousName, Domain string
|
RemoteName, FamiliarName, FullName, AmbiguousName, Domain string
|
||||||
}
|
}
|
||||||
|
|
||||||
tcases := []tcase{
|
tests := []tcase{
|
||||||
{
|
{
|
||||||
RemoteName: "fooo/bar",
|
RemoteName: "fooo/bar",
|
||||||
FamiliarName: "fooo/bar",
|
FamiliarName: "fooo/bar",
|
||||||
|
@ -261,7 +261,7 @@ func TestParseRepositoryInfo(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, tc := range tcases {
|
for i, tc := range tests {
|
||||||
tc := tc
|
tc := tc
|
||||||
refStrings := []string{tc.FamiliarName, tc.FullName}
|
refStrings := []string{tc.FamiliarName, tc.FullName}
|
||||||
if tc.AmbiguousName != "" {
|
if tc.AmbiguousName != "" {
|
||||||
|
@ -367,7 +367,7 @@ func equalReference(r1, r2 Reference) bool {
|
||||||
|
|
||||||
func TestParseAnyReference(t *testing.T) {
|
func TestParseAnyReference(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
tcases := []struct {
|
tests := []struct {
|
||||||
Reference string
|
Reference string
|
||||||
Equivalent string
|
Equivalent string
|
||||||
Expected Reference
|
Expected Reference
|
||||||
|
@ -432,22 +432,22 @@ func TestParseAnyReference(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tcase := range tcases {
|
for _, tc := range tests {
|
||||||
var ref Reference
|
var ref Reference
|
||||||
var err error
|
var err error
|
||||||
ref, err = ParseAnyReference(tcase.Reference)
|
ref, err = ParseAnyReference(tc.Reference)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Error parsing reference %s: %v", tcase.Reference, err)
|
t.Fatalf("Error parsing reference %s: %v", tc.Reference, err)
|
||||||
}
|
}
|
||||||
if ref.String() != tcase.Equivalent {
|
if ref.String() != tc.Equivalent {
|
||||||
t.Fatalf("Unexpected string: %s, expected %s", ref.String(), tcase.Equivalent)
|
t.Fatalf("Unexpected string: %s, expected %s", ref.String(), tc.Equivalent)
|
||||||
}
|
}
|
||||||
|
|
||||||
expected := tcase.Expected
|
expected := tc.Expected
|
||||||
if expected == nil {
|
if expected == nil {
|
||||||
expected, err = Parse(tcase.Equivalent)
|
expected, err = Parse(tc.Equivalent)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Error parsing reference %s: %v", tcase.Equivalent, err)
|
t.Fatalf("Error parsing reference %s: %v", tc.Equivalent, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !equalReference(ref, expected) {
|
if !equalReference(ref, expected) {
|
||||||
|
@ -458,7 +458,7 @@ func TestParseAnyReference(t *testing.T) {
|
||||||
|
|
||||||
func TestNormalizedSplitHostname(t *testing.T) {
|
func TestNormalizedSplitHostname(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
testcases := []struct {
|
tests := []struct {
|
||||||
input string
|
input string
|
||||||
domain string
|
domain string
|
||||||
name string
|
name string
|
||||||
|
@ -519,22 +519,22 @@ func TestNormalizedSplitHostname(t *testing.T) {
|
||||||
name: "library/foo/bar",
|
name: "library/foo/bar",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, testcase := range testcases {
|
for _, tc := range tests {
|
||||||
failf := func(format string, v ...interface{}) {
|
failf := func(format string, v ...interface{}) {
|
||||||
t.Logf(strconv.Quote(testcase.input)+": "+format, v...)
|
t.Logf(strconv.Quote(tc.input)+": "+format, v...)
|
||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
|
|
||||||
named, err := ParseNormalizedNamed(testcase.input)
|
named, err := ParseNormalizedNamed(tc.input)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
failf("error parsing name: %s", err)
|
failf("error parsing name: %s", err)
|
||||||
}
|
}
|
||||||
domain, name := SplitHostname(named)
|
domain, name := SplitHostname(named)
|
||||||
if domain != testcase.domain {
|
if domain != tc.domain {
|
||||||
failf("unexpected domain: got %q, expected %q", domain, testcase.domain)
|
failf("unexpected domain: got %q, expected %q", domain, tc.domain)
|
||||||
}
|
}
|
||||||
if name != testcase.name {
|
if name != tc.name {
|
||||||
failf("unexpected name: got %q, expected %q", name, testcase.name)
|
failf("unexpected name: got %q, expected %q", name, tc.name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -553,7 +553,7 @@ func TestMatchError(t *testing.T) {
|
||||||
|
|
||||||
func TestMatch(t *testing.T) {
|
func TestMatch(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
matchCases := []struct {
|
tests := []struct {
|
||||||
reference string
|
reference string
|
||||||
pattern string
|
pattern string
|
||||||
expected bool
|
expected bool
|
||||||
|
@ -604,24 +604,24 @@ func TestMatch(t *testing.T) {
|
||||||
expected: true,
|
expected: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, c := range matchCases {
|
for _, tc := range tests {
|
||||||
named, err := ParseAnyReference(c.reference)
|
named, err := ParseAnyReference(tc.reference)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
actual, err := FamiliarMatch(c.pattern, named)
|
actual, err := FamiliarMatch(tc.pattern, named)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if actual != c.expected {
|
if actual != tc.expected {
|
||||||
t.Fatalf("expected %s match %s to be %v, was %v", c.reference, c.pattern, c.expected, actual)
|
t.Fatalf("expected %s match %s to be %v, was %v", tc.reference, tc.pattern, tc.expected, actual)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseDockerRef(t *testing.T) {
|
func TestParseDockerRef(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
testcases := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
input string
|
input string
|
||||||
expected string
|
expected string
|
||||||
|
@ -682,17 +682,17 @@ func TestParseDockerRef(t *testing.T) {
|
||||||
expected: "gcr.io/library/busybox@sha256:e6693c20186f837fc393390135d8a598a96a833917917789d63766cab6c59582",
|
expected: "gcr.io/library/busybox@sha256:e6693c20186f837fc393390135d8a598a96a833917917789d63766cab6c59582",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, test := range testcases {
|
for _, tc := range tests {
|
||||||
test := test
|
tc := tc
|
||||||
t.Run(test.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
normalized, err := ParseDockerRef(test.input)
|
normalized, err := ParseDockerRef(tc.input)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
output := normalized.String()
|
output := normalized.String()
|
||||||
if output != test.expected {
|
if output != tc.expected {
|
||||||
t.Fatalf("expected %q to be parsed as %v, got %v", test.input, test.expected, output)
|
t.Fatalf("expected %q to be parsed as %v, got %v", tc.input, tc.expected, output)
|
||||||
}
|
}
|
||||||
_, err = Parse(output)
|
_, err = Parse(output)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -12,9 +12,9 @@ import (
|
||||||
|
|
||||||
func TestReferenceParse(t *testing.T) {
|
func TestReferenceParse(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
// referenceTestcases is a unified set of testcases for
|
// tests is a unified set of testcases for
|
||||||
// testing the parsing of references
|
// testing the parsing of references
|
||||||
referenceTestcases := []struct {
|
tests := []struct {
|
||||||
// input is the repository name or name component testcase
|
// input is the repository name or name component testcase
|
||||||
input string
|
input string
|
||||||
// err is the error expected from Parse, or nil
|
// err is the error expected from Parse, or nil
|
||||||
|
@ -267,43 +267,43 @@ func TestReferenceParse(t *testing.T) {
|
||||||
err: ErrReferenceInvalidFormat,
|
err: ErrReferenceInvalidFormat,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, testcase := range referenceTestcases {
|
for _, tc := range tests {
|
||||||
testcase := testcase
|
tc := tc
|
||||||
t.Run(testcase.input, func(t *testing.T) {
|
t.Run(tc.input, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
repo, err := Parse(testcase.input)
|
repo, err := Parse(tc.input)
|
||||||
if testcase.err != nil {
|
if tc.err != nil {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Errorf("missing expected error: %v", testcase.err)
|
t.Errorf("missing expected error: %v", tc.err)
|
||||||
} else if testcase.err != err {
|
} else if tc.err != err {
|
||||||
t.Errorf("mismatched error: got %v, expected %v", err, testcase.err)
|
t.Errorf("mismatched error: got %v, expected %v", err, tc.err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
t.Errorf("unexpected parse error: %v", err)
|
t.Errorf("unexpected parse error: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if repo.String() != testcase.input {
|
if repo.String() != tc.input {
|
||||||
t.Errorf("mismatched repo: got %q, expected %q", repo.String(), testcase.input)
|
t.Errorf("mismatched repo: got %q, expected %q", repo.String(), tc.input)
|
||||||
}
|
}
|
||||||
|
|
||||||
if named, ok := repo.(Named); ok {
|
if named, ok := repo.(Named); ok {
|
||||||
if named.Name() != testcase.repository {
|
if named.Name() != tc.repository {
|
||||||
t.Errorf("unexpected repository: got %q, expected %q", named.Name(), testcase.repository)
|
t.Errorf("unexpected repository: got %q, expected %q", named.Name(), tc.repository)
|
||||||
}
|
}
|
||||||
domain, _ := SplitHostname(named)
|
domain, _ := SplitHostname(named)
|
||||||
if domain != testcase.domain {
|
if domain != tc.domain {
|
||||||
t.Errorf("unexpected domain: got %q, expected %q", domain, testcase.domain)
|
t.Errorf("unexpected domain: got %q, expected %q", domain, tc.domain)
|
||||||
}
|
}
|
||||||
} else if testcase.repository != "" || testcase.domain != "" {
|
} else if tc.repository != "" || tc.domain != "" {
|
||||||
t.Errorf("expected named type, got %T", repo)
|
t.Errorf("expected named type, got %T", repo)
|
||||||
}
|
}
|
||||||
|
|
||||||
tagged, ok := repo.(Tagged)
|
tagged, ok := repo.(Tagged)
|
||||||
if testcase.tag != "" {
|
if tc.tag != "" {
|
||||||
if ok {
|
if ok {
|
||||||
if tagged.Tag() != testcase.tag {
|
if tagged.Tag() != tc.tag {
|
||||||
t.Errorf("unexpected tag: got %q, expected %q", tagged.Tag(), testcase.tag)
|
t.Errorf("unexpected tag: got %q, expected %q", tagged.Tag(), tc.tag)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
t.Errorf("expected tagged type, got %T", repo)
|
t.Errorf("expected tagged type, got %T", repo)
|
||||||
|
@ -313,10 +313,10 @@ func TestReferenceParse(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
digested, ok := repo.(Digested)
|
digested, ok := repo.(Digested)
|
||||||
if testcase.digest != "" {
|
if tc.digest != "" {
|
||||||
if ok {
|
if ok {
|
||||||
if digested.Digest().String() != testcase.digest {
|
if digested.Digest().String() != tc.digest {
|
||||||
t.Errorf("unexpected digest: got %q, expected %q", digested.Digest().String(), testcase.digest)
|
t.Errorf("unexpected digest: got %q, expected %q", digested.Digest().String(), tc.digest)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
t.Errorf("expected digested type, got %T", repo)
|
t.Errorf("expected digested type, got %T", repo)
|
||||||
|
@ -332,7 +332,7 @@ func TestReferenceParse(t *testing.T) {
|
||||||
// should succeed are covered by TestSplitHostname, below.
|
// should succeed are covered by TestSplitHostname, below.
|
||||||
func TestWithNameFailure(t *testing.T) {
|
func TestWithNameFailure(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
testcases := []struct {
|
tests := []struct {
|
||||||
input string
|
input string
|
||||||
err error
|
err error
|
||||||
}{
|
}{
|
||||||
|
@ -361,13 +361,13 @@ func TestWithNameFailure(t *testing.T) {
|
||||||
err: ErrReferenceInvalidFormat,
|
err: ErrReferenceInvalidFormat,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, testcase := range testcases {
|
for _, tc := range tests {
|
||||||
testcase := testcase
|
tc := tc
|
||||||
t.Run(testcase.input, func(t *testing.T) {
|
t.Run(tc.input, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
_, err := WithName(testcase.input)
|
_, err := WithName(tc.input)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Errorf("no error parsing name. expected: %s", testcase.err)
|
t.Errorf("no error parsing name. expected: %s", tc.err)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -375,7 +375,7 @@ func TestWithNameFailure(t *testing.T) {
|
||||||
|
|
||||||
func TestSplitHostname(t *testing.T) {
|
func TestSplitHostname(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
testcases := []struct {
|
tests := []struct {
|
||||||
input string
|
input string
|
||||||
domain string
|
domain string
|
||||||
name string
|
name string
|
||||||
|
@ -411,20 +411,20 @@ func TestSplitHostname(t *testing.T) {
|
||||||
name: "foo",
|
name: "foo",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, testcase := range testcases {
|
for _, tc := range tests {
|
||||||
testcase := testcase
|
tc := tc
|
||||||
t.Run(testcase.input, func(t *testing.T) {
|
t.Run(tc.input, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
named, err := WithName(testcase.input)
|
named, err := WithName(tc.input)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("error parsing name: %s", err)
|
t.Errorf("error parsing name: %s", err)
|
||||||
}
|
}
|
||||||
domain, name := SplitHostname(named)
|
domain, name := SplitHostname(named)
|
||||||
if domain != testcase.domain {
|
if domain != tc.domain {
|
||||||
t.Errorf("unexpected domain: got %q, expected %q", domain, testcase.domain)
|
t.Errorf("unexpected domain: got %q, expected %q", domain, tc.domain)
|
||||||
}
|
}
|
||||||
if name != testcase.name {
|
if name != tc.name {
|
||||||
t.Errorf("unexpected name: got %q, expected %q", name, testcase.name)
|
t.Errorf("unexpected name: got %q, expected %q", name, tc.name)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -437,7 +437,7 @@ type serializationType struct {
|
||||||
|
|
||||||
func TestSerialization(t *testing.T) {
|
func TestSerialization(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
testcases := []struct {
|
tests := []struct {
|
||||||
description string
|
description string
|
||||||
input string
|
input string
|
||||||
name string
|
name string
|
||||||
|
@ -467,13 +467,13 @@ func TestSerialization(t *testing.T) {
|
||||||
digest: "sha256:1234567890098765432112345667890098765432112345667890098765432112",
|
digest: "sha256:1234567890098765432112345667890098765432112345667890098765432112",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, testcase := range testcases {
|
for _, tc := range tests {
|
||||||
testcase := testcase
|
tc := tc
|
||||||
t.Run(testcase.description, func(t *testing.T) {
|
t.Run(tc.description, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
m := map[string]string{
|
m := map[string]string{
|
||||||
"Description": testcase.description,
|
"Description": tc.description,
|
||||||
"Field": testcase.input,
|
"Field": tc.input,
|
||||||
}
|
}
|
||||||
b, err := json.Marshal(m)
|
b, err := json.Marshal(m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -482,37 +482,37 @@ func TestSerialization(t *testing.T) {
|
||||||
st := serializationType{}
|
st := serializationType{}
|
||||||
|
|
||||||
if err := json.Unmarshal(b, &st); err != nil {
|
if err := json.Unmarshal(b, &st); err != nil {
|
||||||
if testcase.err == nil {
|
if tc.err == nil {
|
||||||
t.Errorf("error unmarshalling: %v", err)
|
t.Errorf("error unmarshalling: %v", err)
|
||||||
}
|
}
|
||||||
if err != testcase.err {
|
if err != tc.err {
|
||||||
t.Errorf("wrong error, expected %v, got %v", testcase.err, err)
|
t.Errorf("wrong error, expected %v, got %v", tc.err, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
} else if testcase.err != nil {
|
} else if tc.err != nil {
|
||||||
t.Errorf("expected error unmarshalling: %v", testcase.err)
|
t.Errorf("expected error unmarshalling: %v", tc.err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if st.Description != testcase.description {
|
if st.Description != tc.description {
|
||||||
t.Errorf("wrong description, expected %q, got %q", testcase.description, st.Description)
|
t.Errorf("wrong description, expected %q, got %q", tc.description, st.Description)
|
||||||
}
|
}
|
||||||
|
|
||||||
ref := st.Field.Reference()
|
ref := st.Field.Reference()
|
||||||
|
|
||||||
if named, ok := ref.(Named); ok {
|
if named, ok := ref.(Named); ok {
|
||||||
if named.Name() != testcase.name {
|
if named.Name() != tc.name {
|
||||||
t.Errorf("unexpected repository: got %q, expected %q", named.Name(), testcase.name)
|
t.Errorf("unexpected repository: got %q, expected %q", named.Name(), tc.name)
|
||||||
}
|
}
|
||||||
} else if testcase.name != "" {
|
} else if tc.name != "" {
|
||||||
t.Errorf("expected named type, got %T", ref)
|
t.Errorf("expected named type, got %T", ref)
|
||||||
}
|
}
|
||||||
|
|
||||||
tagged, ok := ref.(Tagged)
|
tagged, ok := ref.(Tagged)
|
||||||
if testcase.tag != "" {
|
if tc.tag != "" {
|
||||||
if ok {
|
if ok {
|
||||||
if tagged.Tag() != testcase.tag {
|
if tagged.Tag() != tc.tag {
|
||||||
t.Errorf("unexpected tag: got %q, expected %q", tagged.Tag(), testcase.tag)
|
t.Errorf("unexpected tag: got %q, expected %q", tagged.Tag(), tc.tag)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
t.Errorf("expected tagged type, got %T", ref)
|
t.Errorf("expected tagged type, got %T", ref)
|
||||||
|
@ -522,10 +522,10 @@ func TestSerialization(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
digested, ok := ref.(Digested)
|
digested, ok := ref.(Digested)
|
||||||
if testcase.digest != "" {
|
if tc.digest != "" {
|
||||||
if ok {
|
if ok {
|
||||||
if digested.Digest().String() != testcase.digest {
|
if digested.Digest().String() != tc.digest {
|
||||||
t.Errorf("unexpected digest: got %q, expected %q", digested.Digest().String(), testcase.digest)
|
t.Errorf("unexpected digest: got %q, expected %q", digested.Digest().String(), tc.digest)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
t.Errorf("expected digested type, got %T", ref)
|
t.Errorf("expected digested type, got %T", ref)
|
||||||
|
@ -535,7 +535,7 @@ func TestSerialization(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
st = serializationType{
|
st = serializationType{
|
||||||
Description: testcase.description,
|
Description: tc.description,
|
||||||
Field: AsField(ref),
|
Field: AsField(ref),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -560,7 +560,7 @@ func TestSerialization(t *testing.T) {
|
||||||
|
|
||||||
func TestWithTag(t *testing.T) {
|
func TestWithTag(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
testcases := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
digest digest.Digest
|
digest digest.Digest
|
||||||
tag string
|
tag string
|
||||||
|
@ -593,28 +593,28 @@ func TestWithTag(t *testing.T) {
|
||||||
combined: "test.com:8000/foo:TAG5@sha256:1234567890098765432112345667890098765",
|
combined: "test.com:8000/foo:TAG5@sha256:1234567890098765432112345667890098765",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, testcase := range testcases {
|
for _, tc := range tests {
|
||||||
testcase := testcase
|
tc := tc
|
||||||
t.Run(testcase.combined, func(t *testing.T) {
|
t.Run(tc.combined, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
named, err := WithName(testcase.name)
|
named, err := WithName(tc.name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("error parsing name: %s", err)
|
t.Errorf("error parsing name: %s", err)
|
||||||
}
|
}
|
||||||
if testcase.digest != "" {
|
if tc.digest != "" {
|
||||||
canonical, err := WithDigest(named, testcase.digest)
|
canonical, err := WithDigest(named, tc.digest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("error adding digest")
|
t.Errorf("error adding digest")
|
||||||
}
|
}
|
||||||
named = canonical
|
named = canonical
|
||||||
}
|
}
|
||||||
|
|
||||||
tagged, err := WithTag(named, testcase.tag)
|
tagged, err := WithTag(named, tc.tag)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("WithTag failed: %s", err)
|
t.Errorf("WithTag failed: %s", err)
|
||||||
}
|
}
|
||||||
if tagged.String() != testcase.combined {
|
if tagged.String() != tc.combined {
|
||||||
t.Errorf("unexpected: got %q, expected %q", tagged.String(), testcase.combined)
|
t.Errorf("unexpected: got %q, expected %q", tagged.String(), tc.combined)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -622,7 +622,7 @@ func TestWithTag(t *testing.T) {
|
||||||
|
|
||||||
func TestWithDigest(t *testing.T) {
|
func TestWithDigest(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
testcases := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
digest digest.Digest
|
digest digest.Digest
|
||||||
tag string
|
tag string
|
||||||
|
@ -650,27 +650,27 @@ func TestWithDigest(t *testing.T) {
|
||||||
combined: "test.com:8000/foo:latest@sha256:1234567890098765432112345667890098765",
|
combined: "test.com:8000/foo:latest@sha256:1234567890098765432112345667890098765",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, testcase := range testcases {
|
for _, tc := range tests {
|
||||||
testcase := testcase
|
tc := tc
|
||||||
t.Run(testcase.combined, func(t *testing.T) {
|
t.Run(tc.combined, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
named, err := WithName(testcase.name)
|
named, err := WithName(tc.name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("error parsing name: %s", err)
|
t.Errorf("error parsing name: %s", err)
|
||||||
}
|
}
|
||||||
if testcase.tag != "" {
|
if tc.tag != "" {
|
||||||
tagged, err := WithTag(named, testcase.tag)
|
tagged, err := WithTag(named, tc.tag)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("error adding tag")
|
t.Errorf("error adding tag")
|
||||||
}
|
}
|
||||||
named = tagged
|
named = tagged
|
||||||
}
|
}
|
||||||
digested, err := WithDigest(named, testcase.digest)
|
digested, err := WithDigest(named, tc.digest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("WithDigest failed: %s", err)
|
t.Errorf("WithDigest failed: %s", err)
|
||||||
}
|
}
|
||||||
if digested.String() != testcase.combined {
|
if digested.String() != tc.combined {
|
||||||
t.Errorf("unexpected: got %q, expected %q", digested.String(), testcase.combined)
|
t.Errorf("unexpected: got %q, expected %q", digested.String(), tc.combined)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -678,7 +678,7 @@ func TestWithDigest(t *testing.T) {
|
||||||
|
|
||||||
func TestParseNamed(t *testing.T) {
|
func TestParseNamed(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
testcases := []struct {
|
tests := []struct {
|
||||||
input string
|
input string
|
||||||
domain string
|
domain string
|
||||||
name string
|
name string
|
||||||
|
@ -721,30 +721,30 @@ func TestParseNamed(t *testing.T) {
|
||||||
err: ErrNameNotCanonical,
|
err: ErrNameNotCanonical,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, testcase := range testcases {
|
for _, tc := range tests {
|
||||||
testcase := testcase
|
tc := tc
|
||||||
t.Run(testcase.input, func(t *testing.T) {
|
t.Run(tc.input, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
named, err := ParseNamed(testcase.input)
|
named, err := ParseNamed(tc.input)
|
||||||
if err != nil && testcase.err == nil {
|
if err != nil && tc.err == nil {
|
||||||
t.Errorf("error parsing name: %s", err)
|
t.Errorf("error parsing name: %s", err)
|
||||||
return
|
return
|
||||||
} else if err == nil && testcase.err != nil {
|
} else if err == nil && tc.err != nil {
|
||||||
t.Errorf("parsing succeeded: expected error %v", testcase.err)
|
t.Errorf("parsing succeeded: expected error %v", tc.err)
|
||||||
return
|
return
|
||||||
} else if err != testcase.err {
|
} else if err != tc.err {
|
||||||
t.Errorf("unexpected error %v, expected %v", err, testcase.err)
|
t.Errorf("unexpected error %v, expected %v", err, tc.err)
|
||||||
return
|
return
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
domain, name := SplitHostname(named)
|
domain, name := SplitHostname(named)
|
||||||
if domain != testcase.domain {
|
if domain != tc.domain {
|
||||||
t.Errorf("unexpected domain: got %q, expected %q", domain, testcase.domain)
|
t.Errorf("unexpected domain: got %q, expected %q", domain, tc.domain)
|
||||||
}
|
}
|
||||||
if name != testcase.name {
|
if name != tc.name {
|
||||||
t.Errorf("unexpected name: got %q, expected %q", name, testcase.name)
|
t.Errorf("unexpected name: got %q, expected %q", name, tc.name)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ func checkRegexp(t *testing.T, r *regexp.Regexp, m regexpMatch) {
|
||||||
|
|
||||||
func TestDomainRegexp(t *testing.T) {
|
func TestDomainRegexp(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
hostcases := []struct {
|
tests := []struct {
|
||||||
input string
|
input string
|
||||||
match bool
|
match bool
|
||||||
}{
|
}{
|
||||||
|
@ -162,7 +162,7 @@ func TestDomainRegexp(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
r := regexp.MustCompile(`^` + DomainRegexp.String() + `$`)
|
r := regexp.MustCompile(`^` + DomainRegexp.String() + `$`)
|
||||||
for _, tc := range hostcases {
|
for _, tc := range tests {
|
||||||
tc := tc
|
tc := tc
|
||||||
t.Run(tc.input, func(t *testing.T) {
|
t.Run(tc.input, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
@ -181,7 +181,7 @@ func TestFullNameRegexp(t *testing.T) {
|
||||||
anchoredNameRegexp, anchoredNameRegexp.NumSubexp())
|
anchoredNameRegexp, anchoredNameRegexp.NumSubexp())
|
||||||
}
|
}
|
||||||
|
|
||||||
testcases := []regexpMatch{
|
tests := []regexpMatch{
|
||||||
{
|
{
|
||||||
input: "",
|
input: "",
|
||||||
match: false,
|
match: false,
|
||||||
|
@ -465,7 +465,7 @@ func TestFullNameRegexp(t *testing.T) {
|
||||||
match: false,
|
match: false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, tc := range testcases {
|
for _, tc := range tests {
|
||||||
tc := tc
|
tc := tc
|
||||||
t.Run(tc.input, func(t *testing.T) {
|
t.Run(tc.input, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
@ -481,7 +481,7 @@ func TestReferenceRegexp(t *testing.T) {
|
||||||
ReferenceRegexp, ReferenceRegexp.NumSubexp())
|
ReferenceRegexp, ReferenceRegexp.NumSubexp())
|
||||||
}
|
}
|
||||||
|
|
||||||
testcases := []regexpMatch{
|
tests := []regexpMatch{
|
||||||
{
|
{
|
||||||
input: "registry.com:8080/myapp:tag",
|
input: "registry.com:8080/myapp:tag",
|
||||||
match: true,
|
match: true,
|
||||||
|
@ -540,7 +540,7 @@ func TestReferenceRegexp(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range testcases {
|
for _, tc := range tests {
|
||||||
tc := tc
|
tc := tc
|
||||||
t.Run(tc.input, func(t *testing.T) {
|
t.Run(tc.input, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
@ -551,7 +551,7 @@ func TestReferenceRegexp(t *testing.T) {
|
||||||
|
|
||||||
func TestIdentifierRegexp(t *testing.T) {
|
func TestIdentifierRegexp(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
fullCases := []struct {
|
tests := []struct {
|
||||||
input string
|
input string
|
||||||
match bool
|
match bool
|
||||||
}{
|
}{
|
||||||
|
@ -576,7 +576,7 @@ func TestIdentifierRegexp(t *testing.T) {
|
||||||
match: false,
|
match: false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, tc := range fullCases {
|
for _, tc := range tests {
|
||||||
tc := tc
|
tc := tc
|
||||||
t.Run(tc.input, func(t *testing.T) {
|
t.Run(tc.input, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
Loading…
Reference in a new issue