fix: ugly hack to ignore error trace

This commit is contained in:
2022-06-30 08:29:20 +02:00
parent 359692e6ea
commit 7642d7e9c1
+9 -1
View File
@@ -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...))
}