-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathutils_test.go
49 lines (43 loc) · 920 Bytes
/
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
package main
import (
"testing"
"github.com/mmcdole/gofeed"
)
func TestDomain(t *testing.T) {
var tests = []struct {
input string
want string
}{
{"http://foo.com", "foo.com"},
{"https://www.foo.com", "foo.com"},
{"http://www.foo.com", "foo.com"},
{"http://foo.com/bar/baz", "foo.com"},
{"http://www.foo.com/bar/baz", "foo.com"},
}
for _, test := range tests {
t.Run(test.input, func(t *testing.T) {
item := &gofeed.Item{Link: test.input}
got := domain(item)
if got != test.want {
t.Errorf("domain() got = %v, want %v", got, test.want)
}
})
}
}
func TestDomainMalformed(t *testing.T) {
var tests = []string{
"foocom",
"",
"http://",
" no a url",
}
for _, test := range tests {
t.Run(test, func(t *testing.T) {
item := &gofeed.Item{Link: test}
got := domain(item)
if got != "" {
t.Errorf("domain() got = %v, want empty string", got)
}
})
}
}