forked from g0rbe/truenas-acme-hetzner
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_test.go
More file actions
53 lines (48 loc) · 1.19 KB
/
main_test.go
File metadata and controls
53 lines (48 loc) · 1.19 KB
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
package main
import (
"testing"
)
func TestGetDomain(t *testing.T) {
tests := []struct {
input string
expected string
}{
{"example.com", "example.com"},
{"sub.example.com", "example.com"},
{"_acme-challenge.sub.example.com", "example.com"},
{"example.com.", "example.com"},
{"deep.nested.sub.example.co.uk", "example.co.uk"},
{"example.co.uk", "example.co.uk"},
{"test.example.org", "example.org"},
}
for _, tt := range tests {
t.Run(tt.input, func(t *testing.T) {
got := getDomain(tt.input)
if got != tt.expected {
t.Errorf("getDomain(%q) = %q, want %q", tt.input, got, tt.expected)
}
})
}
}
func TestGetSub(t *testing.T) {
tests := []struct {
input string
expected string
}{
{"example.com", ""},
{"sub.example.com", "sub"},
{"_acme-challenge.sub.example.com", "_acme-challenge.sub"},
{"example.com.", ""},
{"deep.nested.example.com", "deep.nested"},
{"_acme-challenge.example.com", "_acme-challenge"},
{"a.b.c.example.co.uk", "a.b.c"},
}
for _, tt := range tests {
t.Run(tt.input, func(t *testing.T) {
got := getSub(tt.input)
if got != tt.expected {
t.Errorf("getSub(%q) = %q, want %q", tt.input, got, tt.expected)
}
})
}
}