forked from form3tech-oss/interview-accountapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_utils.go
48 lines (39 loc) · 900 Bytes
/
test_utils.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
package interview_accountapi
import (
"fmt"
"testing"
)
func assertPrimitiveSlices[T string | int | byte](a, b []T) bool {
if a != nil && b == nil {
return false
}
if a == nil && b != nil {
return false
}
if a == nil && b == nil {
return true
}
if len(a) != len(b) {
return false
}
for i, v := range a {
if v != b[i] {
return false
}
}
return true
}
func assertPrimitivePointers[P string | bool | int | int64 | byte](t *testing.T, actual *P, expected *P, varName string) {
if actual == nil && expected != nil {
t.Errorf("Actual %s should not be nil", varName)
}
if actual != nil && expected == nil {
t.Errorf("Actual %s payload should be nil", varName)
}
if actual != nil && expected != nil {
if *actual != *expected {
t.Errorf("%s doesn't match, expected=%s, got=%s", varName,
fmt.Sprintf("%v", *expected), fmt.Sprintf("%v", *actual))
}
}
}