Ash Wilson | 4a52e2a | 2014-08-29 09:28:00 -0400 | [diff] [blame] | 1 | package tokens |
| 2 | |
Ash Wilson | e058e34 | 2014-08-29 10:31:41 -0400 | [diff] [blame] | 3 | import ( |
| 4 | "testing" |
| 5 | "time" |
| 6 | ) |
Ash Wilson | 4a52e2a | 2014-08-29 09:28:00 -0400 | [diff] [blame] | 7 | |
| 8 | func 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 Wilson | e058e34 | 2014-08-29 10:31:41 -0400 | [diff] [blame] | 16 | |
| 17 | func 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 | } |