From 1b7daaf858e14c7ceca0652d8549a2b4ca54ce82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Mon, 29 May 2023 22:04:55 +0200 Subject: [PATCH] Add tests for bearerToken.expirationTime MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit That's the value that really matters, not the inputs; and we will remove the inputs from bearerToken. Signed-off-by: Miloslav Trmač --- docker/docker_client_test.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/docker/docker_client_test.go b/docker/docker_client_test.go index 5d566900b..c01957f4b 100644 --- a/docker/docker_client_test.go +++ b/docker/docker_client_test.go @@ -117,15 +117,15 @@ func TestNewBearerTokenFromHTTPResponseBody(t *testing.T) { }, { // "token" input: `{"token":"IAmAToken","expires_in":100,"issued_at":"2018-01-01T10:00:02+00:00"}`, - expected: &bearerToken{token: "IAmAToken", ExpiresIn: 100, IssuedAt: time.Unix(1514800802, 0)}, + expected: &bearerToken{token: "IAmAToken", ExpiresIn: 100, IssuedAt: time.Unix(1514800802, 0), expirationTime: time.Unix(1514800802+100, 0)}, }, { // "access_token" input: `{"access_token":"IAmAToken","expires_in":100,"issued_at":"2018-01-01T10:00:02+00:00"}`, - expected: &bearerToken{token: "IAmAToken", ExpiresIn: 100, IssuedAt: time.Unix(1514800802, 0)}, + expected: &bearerToken{token: "IAmAToken", ExpiresIn: 100, IssuedAt: time.Unix(1514800802, 0), expirationTime: time.Unix(1514800802+100, 0)}, }, { // Small expiry input: `{"token":"IAmAToken","expires_in":1,"issued_at":"2018-01-01T10:00:02+00:00"}`, - expected: &bearerToken{token: "IAmAToken", ExpiresIn: 60, IssuedAt: time.Unix(1514800802, 0)}, + expected: &bearerToken{token: "IAmAToken", ExpiresIn: 60, IssuedAt: time.Unix(1514800802, 0), expirationTime: time.Unix(1514800802+60, 0)}, }, } { token, err := newBearerTokenFromHTTPResponseBody(testTokenHTTPResponse(t, c.input)) @@ -137,6 +137,8 @@ func TestNewBearerTokenFromHTTPResponseBody(t *testing.T) { assert.Equal(t, c.expected.ExpiresIn, token.ExpiresIn, c.input) assert.True(t, c.expected.IssuedAt.Equal(token.IssuedAt), "expected [%s] to equal [%s], it did not", token.IssuedAt, c.expected.IssuedAt) + assert.True(t, c.expected.expirationTime.Equal(token.expirationTime), + "expected [%s] to equal [%s], it did not", token.expirationTime, c.expected.expirationTime) } } } @@ -148,6 +150,9 @@ func TestNewBearerTokenFromHTTPResponseBodyIssuedAtZero(t *testing.T) { token, err := newBearerTokenFromHTTPResponseBody(testTokenHTTPResponse(t, tokenBlob)) require.NoError(t, err) assert.False(t, token.IssuedAt.Before(now), "expected [%s] not to be before [%s]", token.IssuedAt, now) + expectedExpiration := now.Add(time.Duration(100) * time.Second) + require.False(t, token.expirationTime.Before(expectedExpiration), + "expected [%s] not to be before [%s]", token.expirationTime, expectedExpiration) } func TestUserAgent(t *testing.T) {