From 5b838aee2299f63d6b2ca002c14ec142a657e2bf Mon Sep 17 00:00:00 2001 From: Yahav Itzhak Date: Tue, 17 Oct 2023 11:27:30 +0300 Subject: [PATCH] Fix TestAccessTokenCreate (#2264) --- access_test.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/access_test.go b/access_test.go index 299167a1b..b2ca85b91 100644 --- a/access_test.go +++ b/access_test.go @@ -178,7 +178,8 @@ var atcTestCases = []struct { name string args []string shouldExpire bool - expectedExpiry uint + // The expected expiry or -1 if we use the default expiry value + expectedExpiry int expectedScope string expectedRefreshable bool expectedReference bool @@ -187,7 +188,7 @@ var atcTestCases = []struct { name: "default", args: []string{"atc"}, shouldExpire: true, - expectedExpiry: defaultExpiry, + expectedExpiry: -1, expectedScope: userScope, expectedRefreshable: false, expectedReference: false, @@ -205,7 +206,7 @@ var atcTestCases = []struct { name: "refreshable, admin", args: []string{"atc", "--refreshable", "--grant-admin"}, shouldExpire: true, - expectedExpiry: defaultExpiry, + expectedExpiry: -1, expectedScope: "applied-permissions/admin", expectedRefreshable: true, expectedReference: false, @@ -223,7 +224,7 @@ var atcTestCases = []struct { name: "groups, description", args: []string{"atc", "--groups=group1,group2", "--description=description"}, shouldExpire: true, - expectedExpiry: defaultExpiry, + expectedExpiry: -1, expectedScope: "applied-permissions/groups:group1,group2", expectedRefreshable: false, expectedReference: false, @@ -244,7 +245,12 @@ func TestAccessTokenCreate(t *testing.T) { defer revokeToken(t, token.TokenId) if test.shouldExpire { - assert.EqualValues(t, test.expectedExpiry, *token.ExpiresIn) + if test.expectedExpiry == -1 { + // If expectedExpiry is -1, expect the default expiry + assert.Positive(t, *token.ExpiresIn) + } else { + assert.EqualValues(t, test.expectedExpiry, *token.ExpiresIn) + } } else { assert.Nil(t, token.ExpiresIn) }