-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathinstance_test.go
50 lines (41 loc) · 1.15 KB
/
instance_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
package chatnio
import (
"testing"
)
var instance *Instance
func init() {
instance = NewInstanceFromEnv("CHATNIO_TOKEN")
}
func TestInstance_GetEndpoint(t *testing.T) {
if len(instance.GetEndpoint()) == 0 {
t.Error("endpoint is not not correct")
}
}
func TestInstance_GetChatEndpoint(t *testing.T) {
if len(instance.GetChatEndpoint()) == 0 {
t.Error("chat endpoint is not correct")
}
}
func TestInstance_GetHeaders(t *testing.T) {
headers := instance.GetHeaders()
if headers["Authorization"] != "Bearer "+instance.GetApiKey() {
t.Error("authorization header is not correct")
}
}
func TestInstance_Mix(t *testing.T) {
if len(instance.Mix("/test")) == 0 {
t.Error("mix is not correct")
}
}
func TestInstance_IsAuthenticated(t *testing.T) {
if len(instance.ApiKey) > 0 && !instance.IsAuthenticated() {
t.Error("authentication is not correct")
}
}
func TestInstance_GetChatApiKey(t *testing.T) {
if instance.IsAuthenticated() && instance.GetChatApiKey() != instance.ApiKey {
t.Error("chat api key is not correct")
} else if !instance.IsAuthenticated() && instance.GetChatApiKey() != "anonymous" {
t.Error("chat api key is not correct")
}
}