mirror of
https://github.com/vmware-tanzu/pinniped.git
synced 2026-09-26 09:54:21 +00:00
Sort idpcache keys to make things as deterministic as possible.
Signed-off-by: Matt Moyer <moyerm@vmware.com>
This commit is contained in:
@@ -6,6 +6,7 @@ package idpcache
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -46,6 +47,24 @@ func TestCache(t *testing.T) {
|
||||
cache.Delete(key)
|
||||
}
|
||||
require.Zero(t, len(cache.Keys()))
|
||||
|
||||
// Fill the cache back up with a fixed set of keys, but inserted in shuffled order.
|
||||
keysInExpectedOrder := []Key{
|
||||
{APIGroup: "a", Kind: "a", Namespace: "a", Name: "a"},
|
||||
{APIGroup: "b", Kind: "a", Namespace: "a", Name: "a"},
|
||||
{APIGroup: "b", Kind: "b", Namespace: "a", Name: "a"},
|
||||
{APIGroup: "b", Kind: "b", Namespace: "b", Name: "a"},
|
||||
{APIGroup: "b", Kind: "b", Namespace: "b", Name: "b"},
|
||||
}
|
||||
for tries := 0; tries < 10; tries++ {
|
||||
cache := New()
|
||||
for _, i := range rand.Perm(len(keysInExpectedOrder)) {
|
||||
cache.Store(keysInExpectedOrder[i], nil)
|
||||
}
|
||||
|
||||
// Expect that they come back out in sorted order.
|
||||
require.Equal(t, keysInExpectedOrder, cache.Keys())
|
||||
}
|
||||
}
|
||||
|
||||
func TestAuthenticateTokenCredentialRequest(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user