mirror of
https://github.com/argoproj/argo-cd.git
synced 2026-02-20 01:28:45 +01:00
Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
40 lines
708 B
Go
40 lines
708 B
Go
package cache
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
type testStruct struct {
|
|
Foo string
|
|
Bar []byte
|
|
}
|
|
|
|
func TestCache(t *testing.T) {
|
|
c := NewInMemoryCache(time.Hour)
|
|
var obj testStruct
|
|
err := c.Get("key", &obj)
|
|
assert.Equal(t, err, ErrCacheMiss)
|
|
cacheObj := testStruct{
|
|
Foo: "foo",
|
|
Bar: []byte("bar"),
|
|
}
|
|
_ = c.Set(&Item{
|
|
Key: "key",
|
|
Object: &cacheObj,
|
|
})
|
|
cacheObj.Foo = "baz"
|
|
err = c.Get("key", &obj)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, "foo", obj.Foo)
|
|
assert.Equal(t, "bar", string(obj.Bar))
|
|
|
|
err = c.Delete("key")
|
|
require.NoError(t, err)
|
|
err = c.Get("key", &obj)
|
|
assert.Equal(t, err, ErrCacheMiss)
|
|
}
|