Skip to content

Commit

Permalink
slightly refactor TestParseDigest, and remove RunTestCases
Browse files Browse the repository at this point in the history
Use a local loop over the test-cases, which allows running tests
individually in some IDE's, and show which test(s) failed.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
  • Loading branch information
thaJeztah committed Aug 17, 2023
1 parent 15f1367 commit b5c8031
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
10 changes: 8 additions & 2 deletions digest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
)

func TestParseDigest(t *testing.T) {
testdigest.RunTestCases(t, []testdigest.TestCase{
tests := []testdigest.TestCase{
{
Input: "sha256:e58fcf7418d4390dec8e8fb69d88c06ec07039d651fedd3aa72af9972e7d046b",
Algorithm: "sha256",
Expand Down Expand Up @@ -110,5 +110,11 @@ func TestParseDigest(t *testing.T) {
Input: "sha256:E58FCF7418D4390DEC8E8FB69D88C06EC07039D651FEDD3AA72AF9972E7D046B",
Err: digest.ErrDigestInvalidFormat,
},
})
}
for _, tc := range tests {
tc := tc
t.Run(tc.Input, func(t *testing.T) {
testdigest.RunTestCase(t, tc)
})
}
}
8 changes: 0 additions & 8 deletions testdigest/testdigest.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,3 @@ func RunTestCase(t *testing.T, testcase TestCase) {
t.Fatalf("%v != %v", newFromHex, digest)
}
}

func RunTestCases(t *testing.T, testcases []TestCase) {
for _, testcase := range testcases {
t.Run(testcase.Input, func(t *testing.T) {
RunTestCase(t, testcase)
})
}
}

0 comments on commit b5c8031

Please sign in to comment.