MCPcopy Create free account
hub / github.com/containers/image / TestNewBearerTokenFromHTTPResponseBody

Function TestNewBearerTokenFromHTTPResponseBody

docker/docker_client_test.go:109–141  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

107}
108
109func 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
143func TestNewBearerTokenFromHTTPResponseBodyIssuedAtZero(t *testing.T) {
144 zeroTime := time.Time{}.Format(time.RFC3339)

Callers

nothing calls this directly

Calls 3

testTokenHTTPResponseFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…