From 0f2829fbf8732e8fd3f5d1e75ff9080c3ecce634 Mon Sep 17 00:00:00 2001 From: Bisakh Mondal Date: Thu, 31 Mar 2022 10:32:24 +0530 Subject: [PATCH] update stacktrace testing regex Signed-off-by: Bisakh Mondal --- pkg/errors/errors_test.go | 13 +++++++------ pkg/errors/stacktrace_test.go | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/pkg/errors/errors_test.go b/pkg/errors/errors_test.go index 8f744731eaf..b079e3180ed 100644 --- a/pkg/errors/errors_test.go +++ b/pkg/errors/errors_test.go @@ -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) { @@ -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") } @@ -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) { diff --git a/pkg/errors/stacktrace_test.go b/pkg/errors/stacktrace_test.go index a8aa067a54d..4567780992e 100644 --- a/pkg/errors/stacktrace_test.go +++ b/pkg/errors/stacktrace_test.go @@ -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()) }