Skip to content

Commit

Permalink
Fix TestAccessTokenCreate (#2264)
Browse files Browse the repository at this point in the history
  • Loading branch information
yahavi authored Oct 17, 2023
1 parent 2225072 commit 5b838ae
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions access_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -187,7 +188,7 @@ var atcTestCases = []struct {
name: "default",
args: []string{"atc"},
shouldExpire: true,
expectedExpiry: defaultExpiry,
expectedExpiry: -1,
expectedScope: userScope,
expectedRefreshable: false,
expectedReference: false,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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)
}
Expand Down

0 comments on commit 5b838ae

Please sign in to comment.