This repository has been archived by the owner on Apr 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebutil_test.go
76 lines (71 loc) · 1.75 KB
/
webutil_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
package webutil
import (
"reflect"
"strings"
"testing"
)
func TestStringsSliceContains(t *testing.T) {
for _, c := range [][3]interface{}{
{[]string(nil), "", false},
{[]string{}, "", false},
{[]string(nil), "foobar", false},
{[]string{}, "foobar", false},
{[]string{"foo", "bar"}, "foo", true},
} {
if StringsSliceContains(c[0].([]string), c[1].(string)) != c[2] {
t.Errorf("%#v in %#v", c[1], c[0])
}
}
}
func TestZeroToNil(t *testing.T) {
for _, c := range [][2]interface{}{
{nil, nil},
{0, nil},
{1, 1},
{"", nil},
{"foobar", "foobar"},
{[]string(nil), nil},
{[]string{}, nil},
{[]string{"foo", "bar"}, []string{"foo", "bar"}},
{map[string]string(nil), nil},
{map[string]string{}, nil},
{map[string]string{"foo": "bar", "bar": "foo"}, map[string]string{"foo": "bar", "bar": "foo"}},
{struct{ Field string }{}, nil},
{struct{ Field string }{"foobar"}, struct{ Field string }{"foobar"}},
} {
if g := ZeroToNil(c[0]); !reflect.DeepEqual(g, c[1]) {
t.Errorf("%#v: want %#v, got %#v", c[0], c[1], g)
}
}
}
func TestIsZero(t *testing.T) {
for _, c := range [][2]interface{}{
{nil, true},
{0, true},
{1, false},
{"", true},
{"foobar", false},
{[]string(nil), true},
{[]string{}, true},
{[]string{"foo", "bar"}, false},
{map[string]string(nil), true},
{map[string]string{}, true},
{map[string]string{"foo": "bar", "bar": "foo"}, false},
{struct{ Field string }{}, true},
{struct{ Field string }{"foobar"}, false},
} {
if IsZero(c[0]) != c[1] {
t.Errorf("%#v", c[0])
}
}
}
func TestChecksumMD5(t *testing.T) {
w := "3858f62230ac3c915f300c664312c63f"
g, err := ChecksumMD5(strings.NewReader("foobar"))
if err != nil {
t.Fatal(err)
}
if w != g {
t.Errorf("want %#v, got %#v", w, g)
}
}