From 7642d7e9c1ba1f6ca4c1a27c5ab976b02355c9f7 Mon Sep 17 00:00:00 2001 From: Joakim Olsson Date: Thu, 30 Jun 2022 08:29:20 +0200 Subject: [PATCH] fix: ugly hack to ignore error trace --- mocks_test.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/mocks_test.go b/mocks_test.go index 7ff42f6..95fbc62 100644 --- a/mocks_test.go +++ b/mocks_test.go @@ -21,6 +21,7 @@ package apex import ( "fmt" + "regexp" "sync" "testing" @@ -50,7 +51,7 @@ func TestMock_Check(t *testing.T) { name: "different", fields: fields{Logged: []string{"same"}}, args: args{wantLogged: []string{"different"}}, - want: []string{"\n\tError Trace:\tmocks.go:67\n\t \t\t\t\tmocks_test.go:63\n\tError: \tNot equal: \n\t \texpected: []string{\"different\"}\n\t \tactual : []string{\"same\"}\n\t \t\n\t \tDiff:\n\t \t--- Expected\n\t \t+++ Actual\n\t \t@@ -1,3 +1,3 @@\n\t \t ([]string) (len=1) {\n\t \t- (string) (len=9) \"different\"\n\t \t+ (string) (len=4) \"same\"\n\t \t }\n\tTest: \t\n"}, + want: []string{"\n\tError: \tNot equal: \n\t \texpected: []string{\"different\"}\n\t \tactual : []string{\"same\"}\n\t \t\n\t \tDiff:\n\t \t--- Expected\n\t \t+++ Actual\n\t \t@@ -1,3 +1,3 @@\n\t \t ([]string) (len=1) {\n\t \t- (string) (len=9) \"different\"\n\t \t+ (string) (len=4) \"same\"\n\t \t }\n\tTest: \t\n"}, }, } for _, tt := range tests { @@ -78,5 +79,12 @@ type MockT struct { } func (m *MockT) Errorf(format string, args ...interface{}) { + re, err := regexp.Compile(`(?s)^\tError Trace:.*(\tError:.*)$`) + assert.NoError(m, err) + for i, a := range args { + if s, ok := a.(string); ok { + args[i] = re.ReplaceAllString(s, "$1") + } + } m.errors = append(m.errors, fmt.Sprintf(format, args...)) }