Skip to content

Commit

Permalink
test: errors/errorsutil: update TestErrorWithLocation()
Browse files Browse the repository at this point in the history
  • Loading branch information
grokify committed Dec 30, 2024
1 parent c144613 commit 88f9c62
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions errors/errorsutil/error_with_location_test.go
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
package errorsutil

import (
"errors"
"strings"
"testing"
"time"
)

var errorWithLocationTests = []struct {
fn func() error
errMsgSuffix string
}{
{func() error { _, err := time.Parse(time.RFC3339, "Mon, 2024-12-31"); return err }, `github.com/grokify/mogo/errors/errorsutil/error_with_location_test.go:22)`},
{func() error { return errors.New("test err") }, `github.com/grokify/mogo/errors/errorsutil/error_with_location_test.go:22)`},
}

func TestErrorWithLocation(t *testing.T) {
for _, tt := range errorWithLocationTests {
try := tt.fn()
if try == nil {
tryErr := tt.fn()
if tryErr == nil {
panic("no error")
}
tryWithLocation := NewErrorWithLocation(try.Error())
tryWithLocation := NewErrorWithLocation(tryErr.Error())
if !strings.HasSuffix(tryWithLocation.Error(), tt.errMsgSuffix) {
t.Errorf("errorsutil.NewErrorWithLocation(\"%s\"): mismatch want suffix [%s] got [%s]", try.Error(), tt.errMsgSuffix, tryWithLocation.Error())
t.Errorf("errorsutil.NewErrorWithLocation(\"%s\"): mismatch want suffix [%s] got [%s]", tryErr.Error(), tt.errMsgSuffix, tryWithLocation.Error())
}
}
}

0 comments on commit 88f9c62

Please sign in to comment.