-
Notifications
You must be signed in to change notification settings - Fork 92
/
util_test.go
66 lines (59 loc) · 1.38 KB
/
util_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
package couchbase
import (
"testing"
)
func TestCleanupHost(t *testing.T) {
tests := []struct {
name, full, suffix, exp string
}{
{"empty", "", "", ""},
{"empty suffix", "aprefix", "", "aprefix"},
{"empty host", "", "asuffix", ""},
{"matched suffix", "server1.example.com:11210", ".example.com:11210", "server1"},
}
for _, test := range tests {
got := CleanupHost(test.full, test.suffix)
if got != test.exp {
t.Errorf("Error on %v: got %q, expected %q",
test.name, got, test.exp)
}
}
}
func TestFindCommonSuffix(t *testing.T) {
tests := []struct {
name, exp string
strings []string
}{
{"empty", "", nil},
{"one", "", []string{"blah"}},
{"two", ".com", []string{"blah.com", "foo.com"}},
}
for _, test := range tests {
got := FindCommonSuffix(test.strings)
if got != test.exp {
t.Errorf("Error on %v: got %q, expected %q",
test.name, got, test.exp)
}
}
}
func TestParseURL(t *testing.T) {
tests := []struct {
in string
works bool
}{
{"", false},
{"http://whatever/", true},
{"http://%/", false},
}
for _, test := range tests {
got, err := ParseURL(test.in)
switch {
case err == nil && test.works,
!(err == nil || test.works):
case err == nil && !test.works:
t.Errorf("Expected failure on %v, got %v", test.in, got)
case test.works && err != nil:
t.Errorf("Expected success on %v, got %v", test.in, err)
}
}
}