-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhelper_test.go
85 lines (77 loc) · 1.84 KB
/
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package domainverifier
import (
"errors"
"testing"
"time"
)
func TestIsValidDomain(t *testing.T) {
type args struct {
domain string
}
testCases := []struct {
name string
args args
want bool
}{
{"valid domain", args{"app-v1.fr.domain.live"}, true},
{"invalid domain", args{"domain com"}, false},
{"empty domain name", args{""}, false},
}
for _, tt := range testCases {
t.Run(tt.name, func(t *testing.T) {
got := IsValidDomainName(tt.args.domain)
if got != tt.want {
t.Errorf("expected: %v, got: %v", tt.want, got)
}
})
}
}
func TestIsSecure(t *testing.T) {
type args struct {
domain string
timeout time.Duration
}
testCases := []struct {
name string
args args
want bool
wantErr error
}{
{"secure domain", args{"google.com", 5 * time.Second}, true, nil},
{"insecure domain", args{"go.com", 5 * time.Second}, false, nil},
{"invalid domain", args{"domain com", 5 * time.Second}, false,
errors.New("invalid domain name")},
{"unreachable domain", args{"unreachabledomain.com", 5 * time.Second}, false,
errors.New("unreachable domain")},
}
for _, tt := range testCases {
t.Run(tt.name, func(t *testing.T) {
secure, err := IsSecure(tt.args.domain, tt.args.timeout)
if err == nil && tt.wantErr != nil {
t.Errorf("expected error: %v, got: %v", tt.wantErr, err)
}
if secure != tt.want {
t.Errorf("expected: %v, got: %v", tt.want, secure)
}
})
}
}
func TestSanitizeString(t *testing.T) {
testCases := []struct {
args string
want string
}{
{" abc 123 ", "abc123"},
{"abc@123", "abc123"},
{"abc#123", "abc123"},
{"Abc 123", "abc123"},
{"Abc_123", "abc123"},
{"Abc-123", "abc123"},
}
for _, tt := range testCases {
got := sanitizeString(tt.args)
if got != tt.want {
t.Errorf("For input %q, expected %q, but got %q", tt.args, tt.want, got)
}
}
}