-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathclient_test.go
76 lines (70 loc) · 2.89 KB
/
client_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 g8
import "testing"
func TestClient_HasPermission(t *testing.T) {
client := NewClientWithPermissions("token", []string{"a", "b"})
if !client.HasPermission("a") {
t.Errorf("client has permissions %s, therefore HasPermission(a) should've been true", client.Permissions)
}
if !client.HasPermission("b") {
t.Errorf("client has permissions %s, therefore HasPermission(b) should've been true", client.Permissions)
}
if client.HasPermission("c") {
t.Errorf("client has permissions %s, therefore HasPermission(c) should've been false", client.Permissions)
}
if client.HasPermission("ab") {
t.Errorf("client has permissions %s, therefore HasPermission(ab) should've been false", client.Permissions)
}
}
func TestClient_HasPermissions(t *testing.T) {
client := NewClientWithPermissions("token", []string{"a", "b"})
if !client.HasPermissions(nil) {
t.Errorf("client has permissions %s, therefore HasPermissions(nil) should've been true", client.Permissions)
}
if !client.HasPermissions([]string{"a"}) {
t.Errorf("client has permissions %s, therefore HasPermissions([a]) should've been true", client.Permissions)
}
if !client.HasPermissions([]string{"b"}) {
t.Errorf("client has permissions %s, therefore HasPermissions([b]) should've been true", client.Permissions)
}
if !client.HasPermissions([]string{"a", "b"}) {
t.Errorf("client has permissions %s, therefore HasPermissions([a, b]) should've been true", client.Permissions)
}
if client.HasPermissions([]string{"a", "b", "c"}) {
t.Errorf("client has permissions %s, therefore HasPermissions([a, b, c]) should've been false", client.Permissions)
}
}
func TestClient_WithData(t *testing.T) {
client := NewClient("token")
if client.Data != nil {
t.Error("expected client data to be nil")
}
client.WithData(5)
if client.Data != 5 {
t.Errorf("expected client data to be 5, got %d", client.Data)
}
client.WithData(map[string]string{"key": "value"})
if data, ok := client.Data.(map[string]string); !ok || data["key"] != "value" {
t.Errorf("expected client data to be map[string]string{key: value}, got %v", client.Data)
}
}
func TestNewClientWithData(t *testing.T) {
client := NewClientWithData("token", 5)
if client.Data != 5 {
t.Errorf("expected client data to be 5, got %d", client.Data)
}
}
func TestNewClientWithPermissionsAndData(t *testing.T) {
client := NewClientWithPermissionsAndData("token", []string{"a", "b"}, 5)
if client.Data != 5 {
t.Errorf("expected client data to be 5, got %d", client.Data)
}
if !client.HasPermission("a") {
t.Errorf("client has permissions %s, therefore HasPermission(a) should've been true", client.Permissions)
}
if !client.HasPermission("b") {
t.Errorf("client has permissions %s, therefore HasPermission(b) should've been true", client.Permissions)
}
if client.HasPermission("c") {
t.Errorf("client has permissions %s, therefore HasPermission(c) should've been false", client.Permissions)
}
}