...
1
2
3
4
5 package gzhttp
6
7 import (
8 "reflect"
9 "testing"
10 )
11
12 func assertEqual(t testing.TB, want, got interface{}) {
13 t.Helper()
14 if !reflect.DeepEqual(want, got) {
15 t.Fatalf("want %#v, got %#v", want, got)
16 }
17 }
18
19 func assertNotEqual(t testing.TB, want, got interface{}) {
20 t.Helper()
21 if reflect.DeepEqual(want, got) {
22 t.Fatalf("did not want %#v, got %#v", want, got)
23 }
24 }
25
26 func assertNil(t testing.TB, object interface{}) {
27 if isNil(object) {
28 return
29 }
30 t.Helper()
31 t.Fatalf("Expected value to be nil.")
32 }
33
34 func assertNotNil(t testing.TB, object interface{}) {
35 if !isNil(object) {
36 return
37 }
38 t.Helper()
39 t.Fatalf("Expected value not to be nil.")
40 }
41
42
43 func isNil(object interface{}) bool {
44 if object == nil {
45 return true
46 }
47
48 value := reflect.ValueOf(object)
49 kind := value.Kind()
50 isNilableKind := containsKind(
51 []reflect.Kind{
52 reflect.Chan, reflect.Func,
53 reflect.Interface, reflect.Map,
54 reflect.Ptr, reflect.Slice},
55 kind)
56
57 if isNilableKind && value.IsNil() {
58 return true
59 }
60
61 return false
62 }
63
64
65 func containsKind(kinds []reflect.Kind, kind reflect.Kind) bool {
66 for i := 0; i < len(kinds); i++ {
67 if kind == kinds[i] {
68 return true
69 }
70 }
71
72 return false
73 }
74
View as plain text