|
@@ -0,0 +1,55 @@
|
|
1
|
+package main
|
|
2
|
+
|
|
3
|
+import (
|
|
4
|
+ "reflect"
|
|
5
|
+ "testing"
|
|
6
|
+)
|
|
7
|
+
|
|
8
|
+func Test_wildcardMatches(t *testing.T) {
|
|
9
|
+ type args struct {
|
|
10
|
+ wildcard string
|
|
11
|
+ domain string
|
|
12
|
+ }
|
|
13
|
+ tests := []struct {
|
|
14
|
+ name string
|
|
15
|
+ args args
|
|
16
|
+ want bool
|
|
17
|
+ }{
|
|
18
|
+ {"non-matching", args{"example.com", "example.org"}, false},
|
|
19
|
+ {"same level domain", args{"example.com", "example.com"}, false},
|
|
20
|
+ {"single level sub domain", args{"example.com", "foo.example.com"}, true},
|
|
21
|
+ {"multi level sub domain", args{"example.com", "bar.foo.example.com"}, false},
|
|
22
|
+ }
|
|
23
|
+ for _, tt := range tests {
|
|
24
|
+ t.Run(tt.name, func(t *testing.T) {
|
|
25
|
+ if got := wildcardMatches(tt.args.wildcard, tt.args.domain); got != tt.want {
|
|
26
|
+ t.Errorf("wildcardMatches() = %v, want %v", got, tt.want)
|
|
27
|
+ }
|
|
28
|
+ })
|
|
29
|
+ }
|
|
30
|
+}
|
|
31
|
+
|
|
32
|
+func Test_applyWildcards(t *testing.T) {
|
|
33
|
+ type args struct {
|
|
34
|
+ domains []string
|
|
35
|
+ wildcards []string
|
|
36
|
+ }
|
|
37
|
+ tests := []struct {
|
|
38
|
+ name string
|
|
39
|
+ args args
|
|
40
|
+ want []string
|
|
41
|
+ }{
|
|
42
|
+ {"no wildcards", args{[]string{"example.com", "example.org"}, []string{}}, []string{"example.com", "example.org"}},
|
|
43
|
+ {"non-matching wildcards", args{[]string{"example.com", "example.org"}, []string{"example.net"}}, []string{"example.com", "example.org"}},
|
|
44
|
+ {"single match", args{[]string{"foo.example.com", "example.org"}, []string{"example.com"}}, []string{"*.example.com", "example.org"}},
|
|
45
|
+ {"multiple matches", args{[]string{"foo.example.com", "example.org", "bar.example.com"}, []string{"example.com"}}, []string{"*.example.com", "example.org"}},
|
|
46
|
+ {"multiple wildcards", args{[]string{"foo.example.com", "baz.example.org", "bar.example.com"}, []string{"example.com", "example.org"}}, []string{"*.example.com", "*.example.org"}},
|
|
47
|
+ }
|
|
48
|
+ for _, tt := range tests {
|
|
49
|
+ t.Run(tt.name, func(t *testing.T) {
|
|
50
|
+ if got := applyWildcards(tt.args.domains, tt.args.wildcards); !reflect.DeepEqual(got, tt.want) {
|
|
51
|
+ t.Errorf("applyWildcards() = %v, want %v", got, tt.want)
|
|
52
|
+ }
|
|
53
|
+ })
|
|
54
|
+ }
|
|
55
|
+}
|