-
Notifications
You must be signed in to change notification settings - Fork 72
/
token_test.go
69 lines (56 loc) · 1.56 KB
/
token_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
// Copyright © 2016 Aaron Longwell
//
// Use of this source code is governed by an MIT license.
// Details in the LICENSE file.
package trello
import (
"testing"
"time"
)
func TestGetToken(t *testing.T) {
token := testToken(t)
if token.Identifier != "Name of Application" {
t.Errorf("Expected 'Name of Application' blah, got '%s'.", token.Identifier)
}
if token.DateExpires != nil {
t.Error("token.DateExpires should have been nil for this token.")
}
if len(token.Permissions) != 3 {
t.Errorf("Expected 3 permissions, got %d.", len(token.Permissions))
}
boardPerm := token.Permissions[1]
if boardPerm.IDModel != "*" || boardPerm.Read != true {
t.Error("Expected read permissions on all boards.")
}
}
func TestGetExpiringToken(t *testing.T) {
client := testClient()
client.BaseURL = mockResponse("tokens", "token-expiring.json").URL
token, err := client.GetToken("tOkenId", Defaults())
if err != nil {
t.Error(err)
}
if token.DateExpires == nil {
t.Error("Token should have an expiration date.")
}
if token.DateExpires.Format(time.Kitchen) != "4:25AM" {
t.Errorf("Expected 4:25AM expiration time. Got %s.", token.DateExpires.Format(time.Kitchen))
}
}
func TestTokenSetClient(t *testing.T) {
tok := Token{}
client := testClient()
tok.SetClient(client)
if tok.client == nil {
t.Error("Expected non-nil Member.client")
}
}
func testToken(t *testing.T) *Token {
client := testClient()
client.BaseURL = mockResponse("tokens", "token.json").URL
token, err := client.GetToken("tOkenId", Defaults())
if err != nil {
t.Error(err)
}
return token
}