github.com/argoproj/argo-cd@v1.8.7/util/cache/client_test.go (about) 1 package cache 2 3 import ( 4 "testing" 5 "time" 6 7 "github.com/stretchr/testify/assert" 8 ) 9 10 type testStruct struct { 11 Foo string 12 Bar []byte 13 } 14 15 func TestCache(t *testing.T) { 16 c := NewInMemoryCache(time.Hour) 17 var obj testStruct 18 err := c.Get("key", &obj) 19 assert.Equal(t, err, ErrCacheMiss) 20 cacheObj := testStruct{ 21 Foo: "foo", 22 Bar: []byte("bar"), 23 } 24 _ = c.Set(&Item{ 25 Key: "key", 26 Object: &cacheObj, 27 }) 28 cacheObj.Foo = "baz" 29 err = c.Get("key", &obj) 30 assert.Nil(t, err) 31 assert.EqualValues(t, obj.Foo, "foo") 32 assert.EqualValues(t, string(obj.Bar), "bar") 33 34 err = c.Delete("key") 35 assert.Nil(t, err) 36 err = c.Get("key", &obj) 37 assert.Equal(t, err, ErrCacheMiss) 38 }