forked from getsentry/sentry-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers_test.go
52 lines (41 loc) · 1.17 KB
/
helpers_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package sentry
import (
"fmt"
"reflect"
"testing"
)
func assertEqual(t *testing.T, got, want interface{}, userMessage ...interface{}) {
t.Helper()
if !reflect.DeepEqual(got, want) {
logFailedAssertion(t, formatUnequalValues(got, want), userMessage...)
}
}
func assertNotEqual(t *testing.T, got, want interface{}, userMessage ...interface{}) {
t.Helper()
if reflect.DeepEqual(got, want) {
logFailedAssertion(t, formatUnequalValues(got, want), userMessage...)
}
}
func logFailedAssertion(t *testing.T, summary string, userMessage ...interface{}) {
t.Helper()
text := summary
if len(userMessage) > 0 {
if message, ok := userMessage[0].(string); ok {
if message != "" && len(userMessage) > 1 {
text = fmt.Sprintf(message, userMessage[1:]...) + text
} else if message != "" {
text = fmt.Sprint(message) + text
}
}
}
t.Error(text)
}
func formatUnequalValues(got, want interface{}) string {
var a, b string
if reflect.TypeOf(got) != reflect.TypeOf(want) {
a, b = fmt.Sprintf("%T(%#v)", got, got), fmt.Sprintf("%T(%#v)", want, want)
} else {
a, b = fmt.Sprintf("%#v", got), fmt.Sprintf("%#v", want)
}
return fmt.Sprintf("\ngot: %s\nwant: %s", a, b)
}