2024-01-22 17:22:41: merge [master:56d3e06e49d7a75f142424293788a4f3b6245430];
This commit is contained in:
1 parent
7014f56cbb
commit
2b91caece0
60 files changed
+3558
No files matched your search
Vendored
+47
@@ -0,0 +1,47 @@
|
||||
package cache_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"isp-gate-service/cache"
|
||||
)
|
||||
|
||||
func TestGetBasic(t *testing.T) {
|
||||
require := require.New(t)
|
||||
|
||||
cache := cache.New()
|
||||
cache.Set("key", []byte("data"), 24*time.Hour)
|
||||
|
||||
data, ok := cache.Get("key")
|
||||
require.True(ok)
|
||||
require.EqualValues("data", data)
|
||||
|
||||
_, ok = cache.Get("key2")
|
||||
require.False(ok)
|
||||
}
|
||||
|
||||
func TestGetExpired(t *testing.T) {
|
||||
require := require.New(t)
|
||||
|
||||
cache := cache.New()
|
||||
cache.Set("key", []byte("data"), 500*time.Millisecond)
|
||||
|
||||
time.Sleep(1 * time.Second)
|
||||
|
||||
data, ok := cache.Get("key")
|
||||
require.False(ok)
|
||||
require.Nil(data)
|
||||
}
|
||||
|
||||
func TestNilValue(t *testing.T) {
|
||||
require := require.New(t)
|
||||
|
||||
cache := cache.New()
|
||||
cache.Set("key", nil, 24*time.Hour)
|
||||
|
||||
data, ok := cache.Get("key")
|
||||
require.True(ok)
|
||||
require.Nil(data)
|
||||
}
|
||||
Reference in new issue
Block a user