Skip to content

Commit

Permalink
Allow multiple error messages to match another test case
Browse files Browse the repository at this point in the history
  • Loading branch information
toddgaunt-gs committed Apr 5, 2024
1 parent 524f2bf commit 7e5757c
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions cmd/estclient/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ func TestCACerts(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
buf := bytes.NewBuffer([]byte{})
err := cacerts(buf, makeCmdFlagSet(t, cacertsCmd, tc.args))
VerifyErrorTextContainsOneOf(t, err, tc.err)
verifyErrorTextContainsOneOf(t, err, tc.err)
if tc.err != nil {
return
}
Expand All @@ -326,14 +326,18 @@ func TestCSRAttrs(t *testing.T) {
name string
args []string
length int
err error
err []error
}{
{
name: "NoAnchor",
args: []string{
"-" + serverFlag, uri,
},
err: errors.New("certificate signed by unknown authority"),
err: []error{
errors.New("failed to verify certificate"),
errors.New("certificate is not trusted"),
errors.New("certificate signed by unknown authority"),
},
},
{
name: "Insecure",
Expand Down Expand Up @@ -368,7 +372,9 @@ func TestCSRAttrs(t *testing.T) {
"-" + apsFlag, "triggererrors",
"-" + explicitAnchorFlag, cafile,
},
err: errors.New("internal server error"),
err: []error{
errors.New("internal server error"),
},
},
}

Expand All @@ -378,7 +384,7 @@ func TestCSRAttrs(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
buf := bytes.NewBuffer([]byte{})
err := csrattrs(buf, makeCmdFlagSet(t, csrattrsCmd, tc.args))
verifyErrorTextContains(t, err, tc.err)
verifyErrorTextContainsOneOf(t, err, tc.err)

if tc.err != nil {
return
Expand Down Expand Up @@ -955,10 +961,10 @@ func verifyErrorTextContains(t *testing.T, got, want error) {
}
}

// VerifyErrorTextContainsOneOf tests if the error text contains one of the strings.
// verifyErrorTextContainsOneOf tests if the error text contains one of the strings.
// This is useful for testing errors that output different text on different
// platforms or between versions.
func VerifyErrorTextContainsOneOf(t *testing.T, got error, wants []error) {
func verifyErrorTextContainsOneOf(t *testing.T, got error, wants []error) {
t.Helper()

if got == nil && len(wants) == 0 {
Expand Down

0 comments on commit 7e5757c

Please sign in to comment.