-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbot_test.go
42 lines (40 loc) · 1.07 KB
/
bot_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
package wecombot
import "testing"
func TestExtractKey(t *testing.T) {
type args struct {
webhookURL string
}
tests := []struct {
name string
args args
wantKey string
}{
{
name: "URL中包含key参数",
args: args{webhookURL: "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=aaa-bbb-ccc-ddd-eee-fff"},
wantKey: "aaa-bbb-ccc-ddd-eee-fff",
},
{
name: "URL中包含大写的KEY参数",
args: args{webhookURL: "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?KEY=aaa-bbb-ccc-ddd-eee-fff"},
wantKey: "",
},
{
name: "URL中key参数为空",
args: args{webhookURL: "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key="},
wantKey: "",
},
{
name: "URL中不包含key参数",
args: args{webhookURL: "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?hello=world"},
wantKey: "",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if gotKey := ExtractKey(tt.args.webhookURL); gotKey != tt.wantKey {
t.Errorf("ExtractKey() = %v, want %v", gotKey, tt.wantKey)
}
})
}
}