Skip to content

Commit

Permalink
Mark asserter methods as test helpers
Browse files Browse the repository at this point in the history
This object should be moved to a dedicated pacakge to avoid mixing actual code helpers and test helpers. This would make a clear distinctions between those two kind and avoid using test helpers in actual code by mistake.
It would also avoid reporting coverage on this code.
  • Loading branch information
upils committed Sep 19, 2023
1 parent aa6452b commit 7d7e885
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions internal/helper/asserter.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type Asserter struct {
// ends the test on a non-nil error. Otherwise, it lets the test continue running
// but marks it as failed
func (asserter *Asserter) AssertErrNil(err error, fatal bool) {
asserter.Helper()
if err != nil {
debug.PrintStack()
if fatal {
Expand All @@ -29,6 +30,7 @@ func (asserter *Asserter) AssertErrNil(err error, fatal bool) {
// AssertErrContains asserts that an error is non-nil, and that the error
// message string contains a sub-string that is passed in
func (asserter *Asserter) AssertErrContains(err error, errString string) {
asserter.Helper()
if err == nil {
debug.PrintStack()
asserter.Error("Expected an error, but got none")
Expand All @@ -42,6 +44,7 @@ func (asserter *Asserter) AssertErrContains(err error, errString string) {

// AssertEqual asserts that two objects are equal using go-cmp
func (asserter *Asserter) AssertEqual(want, got interface{}, cmpOpts ...cmp.Option) {
asserter.Helper()
diff := cmp.Diff(want, got, cmpOpts...)
if want != nil && diff != "" {
asserter.Errorf("mismatch (-want +got):\n%s", diff)

Check warning on line 50 in internal/helper/asserter.go

View check run for this annotation

Codecov / codecov/patch

internal/helper/asserter.go#L46-L50

Added lines #L46 - L50 were not covered by tests
Expand Down

0 comments on commit 7d7e885

Please sign in to comment.