-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidator_test.go
More file actions
56 lines (53 loc) · 1.02 KB
/
validator_test.go
File metadata and controls
56 lines (53 loc) · 1.02 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
54
55
56
package samhook
import "testing"
func TestValidateWebhookURL(t *testing.T) {
tests := []struct {
name string
url string
wantErr bool
}{
{
name: "有效的 HTTPS URL",
url: "https://example.com/webhook",
wantErr: false,
},
{
name: "有效的 HTTP URL",
url: "http://example.com/webhook",
wantErr: false,
},
{
name: "空 URL",
url: "",
wantErr: true,
},
{
name: "無效的 URL 格式",
url: "not-a-valid-url",
wantErr: true,
},
{
name: "無協議的 URL",
url: "example.com/webhook",
wantErr: true,
},
{
name: "FTP 協議(不允許)",
url: "ftp://example.com/webhook",
wantErr: true,
},
{
name: "無主機的 URL",
url: "https://",
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := ValidateWebhookURL(tt.url)
if (err != nil) != tt.wantErr {
t.Errorf("ValidateWebhookURL() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}