reference: run tests with t.Parallel()

Not all tests have been rewritten to use sub-tests; for those
I enabled t.Parallel() for the parent test only.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2022-11-18 20:04:23 +01:00
parent 5703bcf17d
commit b6a040faf4
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
4 changed files with 34 additions and 0 deletions

View file

@ -8,6 +8,7 @@ import (
) )
func TestValidateReferenceName(t *testing.T) { func TestValidateReferenceName(t *testing.T) {
t.Parallel()
validRepoNames := []string{ validRepoNames := []string{
"docker/docker", "docker/docker",
"library/debian", "library/debian",
@ -70,6 +71,7 @@ func TestValidateReferenceName(t *testing.T) {
} }
func TestValidateRemoteName(t *testing.T) { func TestValidateRemoteName(t *testing.T) {
t.Parallel()
validRepositoryNames := []string{ validRepositoryNames := []string{
// Sanity check. // Sanity check.
"docker/docker", "docker/docker",
@ -139,6 +141,7 @@ func TestValidateRemoteName(t *testing.T) {
} }
func TestParseRepositoryInfo(t *testing.T) { func TestParseRepositoryInfo(t *testing.T) {
t.Parallel()
type tcase struct { type tcase struct {
RemoteName, FamiliarName, FullName, AmbiguousName, Domain string RemoteName, FamiliarName, FullName, AmbiguousName, Domain string
} }
@ -292,6 +295,7 @@ func TestParseRepositoryInfo(t *testing.T) {
} }
func TestParseReferenceWithTagAndDigest(t *testing.T) { func TestParseReferenceWithTagAndDigest(t *testing.T) {
t.Parallel()
shortRef := "busybox:latest@sha256:86e0e091d0da6bde2456dbb48306f3956bbeb2eae1b5b9a43045843f69fe4aaa" shortRef := "busybox:latest@sha256:86e0e091d0da6bde2456dbb48306f3956bbeb2eae1b5b9a43045843f69fe4aaa"
ref, err := ParseNormalizedNamed(shortRef) ref, err := ParseNormalizedNamed(shortRef)
if err != nil { if err != nil {
@ -313,6 +317,7 @@ func TestParseReferenceWithTagAndDigest(t *testing.T) {
} }
func TestInvalidReferenceComponents(t *testing.T) { func TestInvalidReferenceComponents(t *testing.T) {
t.Parallel()
if _, err := ParseNormalizedNamed("-foo"); err == nil { if _, err := ParseNormalizedNamed("-foo"); err == nil {
t.Fatal("Expected WithName to detect invalid name") t.Fatal("Expected WithName to detect invalid name")
} }
@ -355,6 +360,7 @@ func equalReference(r1, r2 Reference) bool {
} }
func TestParseAnyReference(t *testing.T) { func TestParseAnyReference(t *testing.T) {
t.Parallel()
tcases := []struct { tcases := []struct {
Reference string Reference string
Equivalent string Equivalent string
@ -445,6 +451,7 @@ func TestParseAnyReference(t *testing.T) {
} }
func TestNormalizedSplitHostname(t *testing.T) { func TestNormalizedSplitHostname(t *testing.T) {
t.Parallel()
testcases := []struct { testcases := []struct {
input string input string
domain string domain string
@ -527,6 +534,7 @@ func TestNormalizedSplitHostname(t *testing.T) {
} }
func TestMatchError(t *testing.T) { func TestMatchError(t *testing.T) {
t.Parallel()
named, err := ParseAnyReference("foo") named, err := ParseAnyReference("foo")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -538,6 +546,7 @@ func TestMatchError(t *testing.T) {
} }
func TestMatch(t *testing.T) { func TestMatch(t *testing.T) {
t.Parallel()
matchCases := []struct { matchCases := []struct {
reference string reference string
pattern string pattern string
@ -605,6 +614,7 @@ func TestMatch(t *testing.T) {
} }
func TestParseDockerRef(t *testing.T) { func TestParseDockerRef(t *testing.T) {
t.Parallel()
testcases := []struct { testcases := []struct {
name string name string
input string input string
@ -668,6 +678,7 @@ func TestParseDockerRef(t *testing.T) {
} }
for _, test := range testcases { for _, test := range testcases {
t.Run(test.name, func(t *testing.T) { t.Run(test.name, func(t *testing.T) {
t.Parallel()
normalized, err := ParseDockerRef(test.input) normalized, err := ParseDockerRef(test.input)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)

View file

@ -11,6 +11,7 @@ import (
) )
func TestReferenceParse(t *testing.T) { func TestReferenceParse(t *testing.T) {
t.Parallel()
// referenceTestcases is a unified set of testcases for // referenceTestcases is a unified set of testcases for
// testing the parsing of references // testing the parsing of references
referenceTestcases := []struct { referenceTestcases := []struct {
@ -269,6 +270,7 @@ func TestReferenceParse(t *testing.T) {
for _, testcase := range referenceTestcases { for _, testcase := range referenceTestcases {
testcase := testcase testcase := testcase
t.Run(testcase.input, func(t *testing.T) { t.Run(testcase.input, func(t *testing.T) {
t.Parallel()
repo, err := Parse(testcase.input) repo, err := Parse(testcase.input)
if testcase.err != nil { if testcase.err != nil {
if err == nil { if err == nil {
@ -329,6 +331,7 @@ func TestReferenceParse(t *testing.T) {
// TestWithNameFailure tests cases where WithName should fail. Cases where it // TestWithNameFailure tests cases where WithName should fail. Cases where it
// 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()
testcases := []struct { testcases := []struct {
input string input string
err error err error
@ -361,6 +364,7 @@ func TestWithNameFailure(t *testing.T) {
for _, testcase := range testcases { for _, testcase := range testcases {
testcase := testcase testcase := testcase
t.Run(testcase.input, func(t *testing.T) { t.Run(testcase.input, func(t *testing.T) {
t.Parallel()
_, err := WithName(testcase.input) _, err := WithName(testcase.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", testcase.err)
@ -370,6 +374,7 @@ func TestWithNameFailure(t *testing.T) {
} }
func TestSplitHostname(t *testing.T) { func TestSplitHostname(t *testing.T) {
t.Parallel()
testcases := []struct { testcases := []struct {
input string input string
domain string domain string
@ -409,6 +414,7 @@ func TestSplitHostname(t *testing.T) {
for _, testcase := range testcases { for _, testcase := range testcases {
testcase := testcase testcase := testcase
t.Run(testcase.input, func(t *testing.T) { t.Run(testcase.input, func(t *testing.T) {
t.Parallel()
named, err := WithName(testcase.input) named, err := WithName(testcase.input)
if err != nil { if err != nil {
t.Errorf("error parsing name: %s", err) t.Errorf("error parsing name: %s", err)
@ -430,6 +436,7 @@ type serializationType struct {
} }
func TestSerialization(t *testing.T) { func TestSerialization(t *testing.T) {
t.Parallel()
testcases := []struct { testcases := []struct {
description string description string
input string input string
@ -463,6 +470,7 @@ func TestSerialization(t *testing.T) {
for _, testcase := range testcases { for _, testcase := range testcases {
testcase := testcase testcase := testcase
t.Run(testcase.description, func(t *testing.T) { t.Run(testcase.description, func(t *testing.T) {
t.Parallel()
m := map[string]string{ m := map[string]string{
"Description": testcase.description, "Description": testcase.description,
"Field": testcase.input, "Field": testcase.input,
@ -551,6 +559,7 @@ func TestSerialization(t *testing.T) {
} }
func TestWithTag(t *testing.T) { func TestWithTag(t *testing.T) {
t.Parallel()
testcases := []struct { testcases := []struct {
name string name string
digest digest.Digest digest digest.Digest
@ -587,6 +596,7 @@ func TestWithTag(t *testing.T) {
for _, testcase := range testcases { for _, testcase := range testcases {
testcase := testcase testcase := testcase
t.Run(testcase.combined, func(t *testing.T) { t.Run(testcase.combined, func(t *testing.T) {
t.Parallel()
named, err := WithName(testcase.name) named, err := WithName(testcase.name)
if err != nil { if err != nil {
t.Errorf("error parsing name: %s", err) t.Errorf("error parsing name: %s", err)
@ -611,6 +621,7 @@ func TestWithTag(t *testing.T) {
} }
func TestWithDigest(t *testing.T) { func TestWithDigest(t *testing.T) {
t.Parallel()
testcases := []struct { testcases := []struct {
name string name string
digest digest.Digest digest digest.Digest
@ -642,6 +653,7 @@ func TestWithDigest(t *testing.T) {
for _, testcase := range testcases { for _, testcase := range testcases {
testcase := testcase testcase := testcase
t.Run(testcase.combined, func(t *testing.T) { t.Run(testcase.combined, func(t *testing.T) {
t.Parallel()
named, err := WithName(testcase.name) named, err := WithName(testcase.name)
if err != nil { if err != nil {
t.Errorf("error parsing name: %s", err) t.Errorf("error parsing name: %s", err)
@ -665,6 +677,7 @@ func TestWithDigest(t *testing.T) {
} }
func TestParseNamed(t *testing.T) { func TestParseNamed(t *testing.T) {
t.Parallel()
testcases := []struct { testcases := []struct {
input string input string
domain string domain string
@ -711,6 +724,7 @@ func TestParseNamed(t *testing.T) {
for _, testcase := range testcases { for _, testcase := range testcases {
testcase := testcase testcase := testcase
t.Run(testcase.input, func(t *testing.T) { t.Run(testcase.input, func(t *testing.T) {
t.Parallel()
named, err := ParseNamed(testcase.input) named, err := ParseNamed(testcase.input)
if err != nil && testcase.err == nil { if err != nil && testcase.err == nil {
t.Errorf("error parsing name: %s", err) t.Errorf("error parsing name: %s", err)

View file

@ -35,6 +35,7 @@ func checkRegexp(t *testing.T, r *regexp.Regexp, m regexpMatch) {
} }
func TestDomainRegexp(t *testing.T) { func TestDomainRegexp(t *testing.T) {
t.Parallel()
hostcases := []struct { hostcases := []struct {
input string input string
match bool match bool
@ -164,6 +165,7 @@ func TestDomainRegexp(t *testing.T) {
for _, tc := range hostcases { for _, tc := range hostcases {
tc := tc tc := tc
t.Run(tc.input, func(t *testing.T) { t.Run(tc.input, func(t *testing.T) {
t.Parallel()
match := r.MatchString(tc.input) match := r.MatchString(tc.input)
if match != tc.match { if match != tc.match {
t.Errorf("Expected match=%t, got %t", tc.match, match) t.Errorf("Expected match=%t, got %t", tc.match, match)
@ -173,6 +175,7 @@ func TestDomainRegexp(t *testing.T) {
} }
func TestFullNameRegexp(t *testing.T) { func TestFullNameRegexp(t *testing.T) {
t.Parallel()
if anchoredNameRegexp.NumSubexp() != 2 { if anchoredNameRegexp.NumSubexp() != 2 {
t.Fatalf("anchored name regexp should have two submatches: %v, %v != 2", t.Fatalf("anchored name regexp should have two submatches: %v, %v != 2",
anchoredNameRegexp, anchoredNameRegexp.NumSubexp()) anchoredNameRegexp, anchoredNameRegexp.NumSubexp())
@ -465,12 +468,14 @@ func TestFullNameRegexp(t *testing.T) {
for _, tc := range testcases { for _, tc := range testcases {
tc := tc tc := tc
t.Run(tc.input, func(t *testing.T) { t.Run(tc.input, func(t *testing.T) {
t.Parallel()
checkRegexp(t, anchoredNameRegexp, tc) checkRegexp(t, anchoredNameRegexp, tc)
}) })
} }
} }
func TestReferenceRegexp(t *testing.T) { func TestReferenceRegexp(t *testing.T) {
t.Parallel()
if ReferenceRegexp.NumSubexp() != 3 { if ReferenceRegexp.NumSubexp() != 3 {
t.Fatalf("anchored name regexp should have three submatches: %v, %v != 3", t.Fatalf("anchored name regexp should have three submatches: %v, %v != 3",
ReferenceRegexp, ReferenceRegexp.NumSubexp()) ReferenceRegexp, ReferenceRegexp.NumSubexp())
@ -538,12 +543,14 @@ func TestReferenceRegexp(t *testing.T) {
for _, tc := range testcases { for _, tc := range testcases {
tc := tc tc := tc
t.Run(tc.input, func(t *testing.T) { t.Run(tc.input, func(t *testing.T) {
t.Parallel()
checkRegexp(t, ReferenceRegexp, tc) checkRegexp(t, ReferenceRegexp, tc)
}) })
} }
} }
func TestIdentifierRegexp(t *testing.T) { func TestIdentifierRegexp(t *testing.T) {
t.Parallel()
fullCases := []struct { fullCases := []struct {
input string input string
match bool match bool
@ -572,6 +579,7 @@ func TestIdentifierRegexp(t *testing.T) {
for _, tc := range fullCases { for _, tc := range fullCases {
tc := tc tc := tc
t.Run(tc.input, func(t *testing.T) { t.Run(tc.input, func(t *testing.T) {
t.Parallel()
match := anchoredIdentifierRegexp.MatchString(tc.input) match := anchoredIdentifierRegexp.MatchString(tc.input)
if match != tc.match { if match != tc.match {
t.Errorf("Expected match=%t, got %t", tc.match, match) t.Errorf("Expected match=%t, got %t", tc.match, match)

View file

@ -25,6 +25,7 @@ import (
) )
func TestReferenceSorting(t *testing.T) { func TestReferenceSorting(t *testing.T) {
t.Parallel()
digested := func(seed int64) string { digested := func(seed int64) string {
b, err := io.ReadAll(io.LimitReader(rand.New(rand.NewSource(seed)), 64)) b, err := io.ReadAll(io.LimitReader(rand.New(rand.NewSource(seed)), 64))
if err != nil { if err != nil {