Skip to content

Commit

Permalink
filters/auth: fix assert usage in tokeninfocache tests (#3240)
Browse files Browse the repository at this point in the history
Second argument of assert.Equal should be expected value.

Signed-off-by: Alexander Yastrebov <alexander.yastrebov@zalando.de>
  • Loading branch information
AlexanderYastrebov authored Sep 19, 2024
1 parent 7f6f037 commit d161ac5
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions filters/auth/tokeninfocache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ func TestTokeninfoCache(t *testing.T) {
require.NoError(t, err)

assert.Equal(t, int32(1), authRequests)
assert.Equal(t, info["uid"], token)
assert.Equal(t, info["expires_in"], float64(600), "expected TokenTTLSeconds")
assert.Equal(t, token, info["uid"])
assert.Equal(t, float64(600), info["expires_in"], "expected TokenTTLSeconds")

// Second request after "sleeping" fractional number of seconds
const delay = float64(5.7)
Expand All @@ -110,8 +110,8 @@ func TestTokeninfoCache(t *testing.T) {
require.NoError(t, err)

assert.Equal(t, int32(1), authRequests, "expected no request to auth sever")
assert.Equal(t, info["uid"], token)
assert.Equal(t, info["expires_in"], float64(595), "expected TokenTTLSeconds - truncate(delay)")
assert.Equal(t, token, info["uid"])
assert.Equal(t, float64(595), info["expires_in"], "expected TokenTTLSeconds - truncate(delay)")

// Third request after "sleeping" longer than cache TTL
clock.add(CacheTTL)
Expand All @@ -120,8 +120,8 @@ func TestTokeninfoCache(t *testing.T) {
require.NoError(t, err)

assert.Equal(t, int32(2), authRequests, "expected new request to auth sever")
assert.Equal(t, info["uid"], token)
assert.Equal(t, info["expires_in"], float64(294), "expected truncate(TokenTTLSeconds - CacheTTL - delay)")
assert.Equal(t, token, info["uid"])
assert.Equal(t, float64(294), info["expires_in"], "expected truncate(TokenTTLSeconds - CacheTTL - delay)")

// Fourth request with a new token evicts cached value
token = newTestTokeninfoToken(clock.now()).String()
Expand All @@ -130,8 +130,8 @@ func TestTokeninfoCache(t *testing.T) {
require.NoError(t, err)

assert.Equal(t, int32(3), authRequests, "expected new request to auth sever")
assert.Equal(t, info["uid"], token)
assert.Equal(t, info["expires_in"], float64(600), "expected TokenTTLSeconds")
assert.Equal(t, token, info["uid"])
assert.Equal(t, float64(600), info["expires_in"], "expected TokenTTLSeconds")
}

// Tests race between reading and writing cache for the same token
Expand Down

0 comments on commit d161ac5

Please sign in to comment.