forked from eryajf/chatgpt-dingtalk
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtools_test.go
76 lines (71 loc) ยท 1.84 KB
/
tools_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
package public
import (
"github.com/eryajf/chatgpt-dingtalk/config"
"testing"
)
func TestCheckRequestWithCredentials_Pass_WithNilConfig(t *testing.T) {
Config = &config.Configuration{
Credentials: nil,
}
clientId, pass := CheckRequestWithCredentials("ts", "sg")
if !pass {
t.Errorf("pass should be true, but false")
return
}
if len(clientId) > 0 {
t.Errorf("client id should be empty")
return
}
}
func TestCheckRequestWithCredentials_Pass_WithEmptyConfig(t *testing.T) {
Config = &config.Configuration{
Credentials: []config.Credential{},
}
clientId, pass := CheckRequestWithCredentials("ts", "sg")
if !pass {
t.Errorf("pass should be true, but false")
return
}
if len(clientId) > 0 {
t.Errorf("client id should be empty")
return
}
}
func TestCheckRequestWithCredentials_Pass_WithValidConfig(t *testing.T) {
Config = &config.Configuration{
Credentials: []config.Credential{
config.Credential{
ClientID: "client-id-for-test",
ClientSecret: "client-secret-for-test",
},
},
}
clientId, pass := CheckRequestWithCredentials("1684493546276", "nwBJQmaBLv9+5/sSS/66jcFc1/kGY5wo38L88LOGfRU=")
if !pass {
t.Errorf("pass should be true, but false")
return
}
if clientId != "client-id-for-test" {
t.Errorf("client id should be \"%s\", but \"%s\"", "client-id-for-test", clientId)
return
}
}
func TestCheckRequestWithCredentials_Failed_WithInvalidConfig(t *testing.T) {
Config = &config.Configuration{
Credentials: []config.Credential{
config.Credential{
ClientID: "client-id-for-test",
ClientSecret: "invalid-client-secret-for-test",
},
},
}
clientId, pass := CheckRequestWithCredentials("1684493546276", "nwBJQmaBLv9+5/sSS/66jcFc1/kGY5wo38L88LOGfRU=")
if pass {
t.Errorf("pass should be false, but true")
return
}
if clientId != "" {
t.Errorf("client id should be empty")
return
}
}