Skip to content

Commit

Permalink
cache 单元测试
Browse files Browse the repository at this point in the history
  • Loading branch information
xmdhs committed Oct 12, 2023
1 parent 876befd commit a3fee4d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 58 deletions.
38 changes: 38 additions & 0 deletions db/cache/cache_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package cache

import (
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestCache(t *testing.T) {
cl := []Cache{NewFastCache(100000), NewRedis("127.0.0.1:6379", "")}

for i, c := range cl {
key := []byte("key")
value := []byte("value")

require.Nil(t, c.Put(key, value, time.Now().Add(1*time.Hour)), i)

v, err := c.Get(key)
require.Nil(t, err, i)

assert.Equal(t, v, value, i)

require.Nil(t, c.Del(key), i)

v, err = c.Get(key)
require.Nil(t, err, i)
require.Nil(t, v, i)

require.Nil(t, c.Put(key, value, time.Now().Add(2*time.Second)), i)
time.Sleep(3 * time.Second)

v, err = c.Get(key)
require.Nil(t, err, i)
require.Nil(t, v, i)
}
}
20 changes: 0 additions & 20 deletions db/cache/fastcache_test.go

This file was deleted.

38 changes: 0 additions & 38 deletions db/cache/redis_test.go

This file was deleted.

0 comments on commit a3fee4d

Please sign in to comment.