reference: TestParseRepositoryInfo: use subtests

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2023-04-29 18:54:42 +02:00
parent af36dd698f
commit b50c049fc6
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C

View file

@ -261,35 +261,41 @@ func TestParseRepositoryInfo(t *testing.T) {
}, },
} }
for _, tcase := range tcases { for i, tc := range tcases {
refStrings := []string{tcase.FamiliarName, tcase.FullName} tc := tc
if tcase.AmbiguousName != "" { refStrings := []string{tc.FamiliarName, tc.FullName}
refStrings = append(refStrings, tcase.AmbiguousName) if tc.AmbiguousName != "" {
refStrings = append(refStrings, tc.AmbiguousName)
} }
var refs []Named
for _, r := range refStrings { for _, r := range refStrings {
named, err := ParseNormalizedNamed(r) t.Run(strconv.Itoa(i)+"/"+r, func(t *testing.T) {
if err != nil { t.Parallel()
t.Fatal(err) named, err := ParseNormalizedNamed(r)
} if err != nil {
refs = append(refs, named) t.Fatalf("ref=%s: %v", r, err)
} }
t.Run("FamiliarName", func(t *testing.T) {
for _, r := range refs { if expected, actual := tc.FamiliarName, FamiliarName(named); expected != actual {
if expected, actual := tcase.FamiliarName, FamiliarName(r); expected != actual { t.Errorf("Invalid familiar name for %q. Expected %q, got %q", named, expected, actual)
t.Fatalf("Invalid normalized reference for %q. Expected %q, got %q", r, expected, actual) }
} })
if expected, actual := tcase.FullName, r.String(); expected != actual { t.Run("FullName", func(t *testing.T) {
t.Fatalf("Invalid canonical reference for %q. Expected %q, got %q", r, expected, actual) if expected, actual := tc.FullName, named.String(); expected != actual {
} t.Errorf("Invalid canonical reference for %q. Expected %q, got %q", named, expected, actual)
if expected, actual := tcase.Domain, Domain(r); expected != actual { }
t.Fatalf("Invalid domain for %q. Expected %q, got %q", r, expected, actual) })
} t.Run("Domain", func(t *testing.T) {
if expected, actual := tcase.RemoteName, Path(r); expected != actual { if expected, actual := tc.Domain, Domain(named); expected != actual {
t.Fatalf("Invalid remoteName for %q. Expected %q, got %q", r, expected, actual) t.Errorf("Invalid domain for %q. Expected %q, got %q", named, expected, actual)
} }
})
t.Run("RemoteName", func(t *testing.T) {
if expected, actual := tc.RemoteName, Path(named); expected != actual {
t.Errorf("Invalid remoteName for %q. Expected %q, got %q", named, expected, actual)
}
})
})
} }
} }
} }