github.com/argoproj/argo-cd/v2@v2.10.9/server/cache/cache_test.go (about) 1 package cache 2 3 import ( 4 "testing" 5 "time" 6 7 "github.com/spf13/cobra" 8 "github.com/stretchr/testify/assert" 9 10 . "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1" 11 cacheutil "github.com/argoproj/argo-cd/v2/util/cache" 12 appstatecache "github.com/argoproj/argo-cd/v2/util/cache/appstate" 13 ) 14 15 type fixtures struct { 16 *Cache 17 } 18 19 func newFixtures() *fixtures { 20 return &fixtures{NewCache( 21 appstatecache.NewCache( 22 cacheutil.NewCache(cacheutil.NewInMemoryCache(1*time.Hour)), 23 1*time.Minute, 24 ), 25 1*time.Minute, 26 1*time.Minute, 27 1*time.Minute, 28 )} 29 } 30 31 func TestCache_GetRepoConnectionState(t *testing.T) { 32 cache := newFixtures().Cache 33 // cache miss 34 _, err := cache.GetRepoConnectionState("my-repo") 35 assert.Equal(t, ErrCacheMiss, err) 36 // populate cache 37 err = cache.SetRepoConnectionState("my-repo", &ConnectionState{Status: "my-state"}) 38 assert.NoError(t, err) 39 // cache miss 40 _, err = cache.GetRepoConnectionState("other-repo") 41 assert.Equal(t, ErrCacheMiss, err) 42 // cache hit 43 value, err := cache.GetRepoConnectionState("my-repo") 44 assert.NoError(t, err) 45 assert.Equal(t, ConnectionState{Status: "my-state"}, value) 46 } 47 48 func TestAddCacheFlagsToCmd(t *testing.T) { 49 cache, err := AddCacheFlagsToCmd(&cobra.Command{})() 50 assert.NoError(t, err) 51 assert.Equal(t, 1*time.Hour, cache.connectionStatusCacheExpiration) 52 assert.Equal(t, 3*time.Minute, cache.oidcCacheExpiration) 53 }