(t *testing.T)
| 107 | } |
| 108 | |
| 109 | func TestNewBearerTokenFromHTTPResponseBody(t *testing.T) { |
| 110 | for _, c := range []struct { |
| 111 | input string |
| 112 | expected *bearerToken // or nil if a failure is expected |
| 113 | }{ |
| 114 | { // Invalid JSON |
| 115 | input: "IAmNotJson", |
| 116 | expected: nil, |
| 117 | }, |
| 118 | { // "token" |
| 119 | input: `{"token":"IAmAToken","expires_in":100,"issued_at":"2018-01-01T10:00:02+00:00"}`, |
| 120 | expected: &bearerToken{token: "IAmAToken", expirationTime: time.Unix(1514800802+100, 0)}, |
| 121 | }, |
| 122 | { // "access_token" |
| 123 | input: `{"access_token":"IAmAToken","expires_in":100,"issued_at":"2018-01-01T10:00:02+00:00"}`, |
| 124 | expected: &bearerToken{token: "IAmAToken", expirationTime: time.Unix(1514800802+100, 0)}, |
| 125 | }, |
| 126 | { // Small expiry |
| 127 | input: `{"token":"IAmAToken","expires_in":1,"issued_at":"2018-01-01T10:00:02+00:00"}`, |
| 128 | expected: &bearerToken{token: "IAmAToken", expirationTime: time.Unix(1514800802+60, 0)}, |
| 129 | }, |
| 130 | } { |
| 131 | token, err := newBearerTokenFromHTTPResponseBody(testTokenHTTPResponse(t, c.input)) |
| 132 | if c.expected == nil { |
| 133 | assert.Error(t, err, c.input) |
| 134 | } else { |
| 135 | require.NoError(t, err, c.input) |
| 136 | assert.Equal(t, c.expected.token, token.token, c.input) |
| 137 | assert.True(t, c.expected.expirationTime.Equal(token.expirationTime), |
| 138 | "expected [%s] to equal [%s], it did not", token.expirationTime, c.expected.expirationTime) |
| 139 | } |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | func TestNewBearerTokenFromHTTPResponseBodyIssuedAtZero(t *testing.T) { |
| 144 | zeroTime := time.Time{}.Format(time.RFC3339) |
nothing calls this directly
no test coverage detected
searching dependent graphs…