-
-
Notifications
You must be signed in to change notification settings - Fork 25
/
helper_test.go
30 lines (27 loc) · 933 Bytes
/
helper_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
package main
import "testing"
func TestGetRootDomain(t *testing.T) {
t.Parallel() // marks TLog as capable of running in parallel with other tests
tests := []struct {
input string
expected string
}{
{"1234.567.89.com", "89.com"},
{"asd.digital", "asd.digital"},
{"kndafs.adshg.andgjkSdg.jdnfdsa", "andgjkSdg.jdnfdsa"},
{"sub.root.gv.at", "root.gv.at"},
}
for _, tt := range tests {
tt := tt // NOTE: https://github.com/golang/go/wiki/CommonMistakes#using-goroutines-on-loop-iterator-variables
t.Run(tt.input, func(t *testing.T) {
t.Parallel() // marks each test case as capable of running in parallel with each other
result, err := getRootDomain(tt.input)
if err != nil {
t.Fatalf("%s should not error out. error: %v", tt.input, err)
}
if result != tt.expected {
t.Fatalf("wrong root domain detected. Input: %s Output: %s Expected: %s", tt.input, result, tt.expected)
}
})
}
}