forked from italia/publiccode-parser-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchecks_test.go
42 lines (38 loc) · 1008 Bytes
/
checks_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
package publiccode
import (
"testing"
)
type testURL struct {
url string
toTest Domain
res bool
}
func TestHostsInDomain(t *testing.T) {
domain := Domain{
UseTokenFor: []string{
"github.com",
"api.github.com",
"raw.githubusercontent.com",
},
}
list := []testURL{
{"https://github.com", domain, true},
{"https://githubs.com", domain, false},
{"https://github.org", domain, false},
{"https://github", domain, false},
{"http://github.com", domain, true},
{"http:/github.com", domain, false},
{"https://api.github.com", domain, true},
{"https://api.github.com/org/repo/file", domain, true},
{"https://raw.githubusercontent.com/org/repo/master/pc.yml", domain, true},
{"https://raw.githubusercontent.com", domain, true},
{"", Domain{UseTokenFor: []string{}}, false},
{"", Domain{}, false},
}
for _, l := range list {
out := isHostInDomain(l.toTest, l.url)
if out != l.res {
t.Errorf("some evaluation went wrong %s with %s", l.toTest, l.url)
}
}
}