Skip to content

Commit

Permalink
update stacktrace testing regex
Browse files Browse the repository at this point in the history
  • Loading branch information
bisakhmondal committed Mar 31, 2022
1 parent b090b04 commit 68d88e2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
13 changes: 7 additions & 6 deletions pkg/errors/errors_test.go
Expand Up @@ -17,8 +17,8 @@ func TestNew(t *testing.T) {
err := New(msg)
testutil.Equals(t, err.Error(), msg, "the root error message must match")

reg := regexp.MustCompile(msg + `[ \n]+> github\.com\/thanos-io\/thanos\/pkg\/errors\.TestNew .*\/thanos\/pkg\/errors\/errors_test\.go:17`)
testutil.Equals(t, reg.MatchString(fmt.Sprintf("%+v", err)), true, "the stack trace must match")
reg := regexp.MustCompile(msg + `[ \n]+> github\.com\/thanos-io\/thanos\/pkg\/errors\.TestNew .*\/pkg\/errors\/errors_test\.go:17`)
testutil.Equals(t, reg.MatchString(fmt.Sprintf("%+v", err)), true, "matching stacktrace in errors.New")
}

func TestNewFormatted(t *testing.T) {
Expand All @@ -27,7 +27,7 @@ func TestNewFormatted(t *testing.T) {

err := New(fmtMsg, "value")
testutil.Equals(t, err.Error(), expectedMsg, "the root error message must match")
reg := regexp.MustCompile(expectedMsg + `[ \n]+> github\.com\/thanos-io\/thanos\/pkg\/errors\.TestNewFormatted .*\/thanos\/pkg\/errors\/errors_test\.go:28`)
reg := regexp.MustCompile(expectedMsg + `[ \n]+> github\.com\/thanos-io\/thanos\/pkg\/errors\.TestNewFormatted .*\/pkg\/errors\/errors_test\.go:28`)
testutil.Equals(t, reg.MatchString(fmt.Sprintf("%+v", err)), true, "the stack trace must match")
}

Expand All @@ -38,10 +38,11 @@ func TestWrap(t *testing.T) {
expectedMsg := wrapper + ": " + msg
testutil.Equals(t, err.Error(), expectedMsg, "the root error message must match")

reg := regexp.MustCompile(`test_wrapper[ \n]+> github\.com\/thanos-io\/thanos\/pkg\/errors\.TestWrap .*\/thanos\/pkg\/errors\/errors_test\.go:36
[[:ascii:]]+test_error_message[ \n]+> github\.com\/thanos-io\/thanos\/pkg\/errors\.TestWrap .*\/thanos\/pkg\/errors\/errors_test\.go:35`)
reg := regexp.MustCompile(`test_wrapper[ \n]+> github\.com\/thanos-io\/thanos\/pkg\/errors\.TestWrap .*\/pkg\/errors\/errors_test\.go:36
[[:ascii:]]+test_error_message[ \n]+> github\.com\/thanos-io\/thanos\/pkg\/errors\.TestWrap .*\/pkg\/errors\/errors_test\.go:35`)

testutil.Equals(t, reg.MatchString(fmt.Sprintf("%+v", err)), true, "the stack trace must match")
t.Logf("%+v", err)
testutil.Equals(t, reg.MatchString(fmt.Sprintf("%+v", err)), true, "matching stacktrace in errors.Wrap")
}

func TestUnwrap(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/errors/stacktrace_test.go
Expand Up @@ -11,7 +11,7 @@ func caller() stacktrace {

func TestStacktraceOutput(t *testing.T) {
st := caller()
expectedPhrase := "thanos/pkg/errors/stacktrace_test.go:13"
expectedPhrase := "/pkg/errors/stacktrace_test.go:13"
if !strings.Contains(st.String(), expectedPhrase) {
t.Fatalf("expected %v phrase into the stacktrace, received stacktrace: \n%v", expectedPhrase, st.String())
}
Expand Down

0 comments on commit 68d88e2

Please sign in to comment.