From 376642565f12f88b4c83889bd16ad392c03ff29d Mon Sep 17 00:00:00 2001 From: Angira Kekteeva Date: Sun, 15 Aug 2021 01:03:20 +0300 Subject: [PATCH] [#206] Add unit tests Signed-off-by: Angira Kekteeva --- api/cache/object_cache_test.go | 40 ++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 api/cache/object_cache_test.go diff --git a/api/cache/object_cache_test.go b/api/cache/object_cache_test.go new file mode 100644 index 00000000..b9ee9294 --- /dev/null +++ b/api/cache/object_cache_test.go @@ -0,0 +1,40 @@ +package cache + +import ( + "testing" + "time" + + objecttest "github.com/nspcc-dev/neofs-api-go/pkg/object/test" + "github.com/stretchr/testify/require" +) + +const ( + cachesize = 10 + lifetime = time.Second * 5 +) + +func TestCache(t *testing.T) { + var ( + address = objecttest.Address() + object = objecttest.Object() + ) + + t.Run("check get", func(t *testing.T) { + cache := New(cachesize, lifetime) + err := cache.Put(address, *object) + require.NoError(t, err) + + actual := cache.Get(address) + require.Equal(t, object, actual) + }) + + t.Run("check delete", func(t *testing.T) { + cache := New(cachesize, lifetime) + err := cache.Put(address, *object) + require.NoError(t, err) + + cache.Delete(address) + actual := cache.Get(address) + require.Nil(t, actual) + }) +}