-
Notifications
You must be signed in to change notification settings - Fork 55
/
utils_test.go
98 lines (84 loc) · 2.13 KB
/
utils_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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package scim
import (
"github.com/elimity-com/scim/errors"
"reflect"
"testing"
)
func assertEqual(t *testing.T, expected, actual interface{}) {
if expected != actual {
t.Errorf("not equal: expected %v, actual %v", expected, actual)
}
}
func assertEqualSCIMErrors(t *testing.T, expected, actual *errors.ScimError) {
if expected.ScimType != actual.ScimType ||
expected.Detail != actual.Detail ||
expected.Status != actual.Status {
t.Errorf("wrong scim error: expected %v, actual %v", expected, actual)
}
}
func assertEqualStatusCode(t *testing.T, expected, actual int) {
if expected != actual {
t.Errorf("status code mismatch: expected %d, actual %d", expected, actual)
}
}
func assertEqualStrings(t *testing.T, expected, actual []string) {
assertLen(t, actual, len(expected))
for i, id := range expected {
if rID := actual[i]; rID != id {
t.Errorf("%s is not equal to %s", rID, id)
}
}
}
func assertFalse(t *testing.T, ok bool) {
if ok {
t.Error("value should be false")
}
}
func assertLen(t *testing.T, object interface{}, length int) {
ok, l := getLen(object)
if !ok {
t.Errorf("given object is not a slice/array")
}
if l != length {
t.Errorf("expected %d entities, got %d", length, l)
}
}
func assertNil(t *testing.T, object interface{}, name string) {
if object != nil {
t.Errorf("object should be nil: %s", name)
}
}
func assertNotEqual(t *testing.T, expected, actual interface{}) {
if expected == actual {
t.Errorf("%v and %v should not be equal", expected, actual)
}
}
func assertNotNil(t *testing.T, object interface{}, name string) {
if object == nil {
t.Errorf("missing object: %s", name)
}
}
func assertTrue(t *testing.T, ok bool) {
if !ok {
t.Error("value should be true")
}
}
func assertTypeOk(t *testing.T, ok bool, expectedType string) {
if !ok {
t.Errorf("type is not a(n) %s", expectedType)
}
}
func assertUnmarshalNoError(t *testing.T, err error) {
if err != nil {
t.Errorf("json unmarshalling failed: %s", err)
}
}
func getLen(x interface{}) (ok bool, length int) {
v := reflect.ValueOf(x)
defer func() {
if e := recover(); e != nil {
ok = false
}
}()
return true, v.Len()
}