Skip to content

Commit

Permalink
Fix BeLike expected error type
Browse files Browse the repository at this point in the history
Fix error message in case the expected type is not a string.

Refactor message printing to get rid of misspell warning.
  • Loading branch information
HeavyWombat committed Jun 5, 2024
1 parent ee72229 commit 7c94fb2
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions pkg/dyff/core_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,25 +88,35 @@ type extendedStringMatcher struct {
func (matcher *extendedStringMatcher) Match(actual interface{}) (success bool, err error) {
actualString, ok := actual.(string)
if !ok {
return false, fmt.Errorf("BeLike matcher expected a string, not %T", actual)
return false, fmt.Errorf("BeLike matcher expects a string, not %T", actual)
}

expectedString, ok := matcher.expected.(string)
if !ok {
return false, fmt.Errorf("BeLike matcher expected a string, not %T", actual)
return false, fmt.Errorf("BeLike matcher expects a string, not %T", matcher.expected)
}

return actualString == expectedString, nil
}

func (matcher *extendedStringMatcher) FailureMessage(actual interface{}) string {
return fmt.Sprintf("Expected\n\t%#v\nto be like\n\t%#v",
return fmt.Sprintf(
`Expected
%#v
to be like
%#v
`,
actual,
matcher.expected)
}

func (matcher *extendedStringMatcher) NegatedFailureMessage(actual interface{}) string {
return fmt.Sprintf("Expected\n\t%#v\nnot to be like\n\t%#v",
return fmt.Sprintf(
`Expected
%#v
not to be like
%#v
`,
actual,
matcher.expected,
)
Expand Down

0 comments on commit 7c94fb2

Please sign in to comment.