blob: 669db61a9c73c8ab5f267a9ad1064553df1146de [file] [log] [blame]
Ash Wilson4a52e2a2014-08-29 09:28:00 -04001package tokens
2
Ash Wilsone058e342014-08-29 10:31:41 -04003import (
4 "testing"
5 "time"
6)
Ash Wilson4a52e2a2014-08-29 09:28:00 -04007
8func TestTokenID(t *testing.T) {
9 result := TokenCreateResult{tokenID: "1234"}
10
11 token, _ := result.TokenID()
12 if token != "1234" {
13 t.Errorf("Expected tokenID of 1234, got %s", token)
14 }
15}
Ash Wilsone058e342014-08-29 10:31:41 -040016
17func TestExpiresAt(t *testing.T) {
18 resp := map[string]interface{}{
19 "token": map[string]string{
20 "expires_at": "2013-02-02T18:30:59.000000Z",
21 },
22 }
23
24 result := TokenCreateResult{
25 tokenID: "1234",
26 response: resp,
27 }
28
29 expected, _ := time.Parse(time.UnixDate, "Sat Feb 2 18:30:59 UTC 2013")
30 actual, err := result.ExpiresAt()
31 if err != nil {
32 t.Errorf("Error extraction expiration time: %v", err)
33 }
34 if actual != expected {
35 t.Errorf("Expected expiration time %s, but was %s", expected.Format(time.UnixDate), actual.Format(time.UnixDate))
36 }
37}