Skip to content

Commit

Permalink
Add errors test case, check for sensitive attachments
Browse files Browse the repository at this point in the history
  • Loading branch information
Rheisen committed Mar 23, 2024
1 parent 5a2c672 commit 81e5aa3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions error_struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ func newBerr(errorType ErrorType, errorMessage string, attachments ...Attachment
next = fmt.Errorf("%s: %w", next, d.Value().(error))
case d.Type() == AttachmentMetadataType:
errorMetadata[d.Key()] = d.Value()
case d.Sensitive() == true:
errorMetadata[d.Key()] = d.Value()
default:
errorDetail[d.Key()] = d.Value()
}
Expand Down
29 changes: 29 additions & 0 deletions error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,35 @@ func TestTimeoutError(t *testing.T) {
testErrorFunc(t, berr.TimeoutErrorType, berr.Timeout, "request cancelled")
}

func TestErrorsFormatting(t *testing.T) {
const unimplementedErrorMessage = "store.GetData method not implemented"

const applicationErrorMessage = "unexpected problem querying database"

errs := berr.Errors{
berr.Unimplemented(unimplementedErrorMessage),
berr.Application(applicationErrorMessage),
}

errorString := errs.Error()

if !strings.Contains(errorString, unimplementedErrorMessage) {
t.Errorf("expected error string to contain '%s', found: %s\n", unimplementedErrorMessage, errorString)
}

if !strings.Contains(errorString, applicationErrorMessage) {
t.Errorf("expected error string to contain '%s', found: %s\n", applicationErrorMessage, errorString)
}

if !strings.HasPrefix(errorString, "[") {
t.Errorf("expected error string to start with '['\n")
}

if !strings.HasSuffix(errorString, "]") {
t.Errorf("expected error string to start with ']'\n")
}
}

func testErrorFunc(
t *testing.T,
errorType berr.ErrorType,
Expand Down

0 comments on commit 81e5aa3

Please sign in to comment.