test: add unit test for Items (#2703)

Signed-off-by: Guangwen Feng <fenggw-fnst@fujitsu.com>
This commit is contained in:
Guangwen Feng 2023-09-06 16:10:35 +08:00 committed by GitHub
parent 170a7f2186
commit 6c07550032
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 0 deletions

View File

@ -24,6 +24,8 @@ import (
"sync"
"testing"
"time"
testifyassert "github.com/stretchr/testify/assert"
)
var (
@ -185,6 +187,16 @@ func TestCacheKeys(t *testing.T) {
}
}
func TestItems(t *testing.T) {
tc := New(DefaultExpiration, 0)
tc.Set(v1, "1", 1)
tc.Set(v2, "2", DefaultExpiration)
tc.Set(v3, "3", DefaultExpiration)
m := tc.Items()
assert := testifyassert.New(t)
assert.Equal(map[string]Item{"bar": {Object: "2", Expiration: 0}, "baz": {Object: "3", Expiration: 0}}, m)
}
func TestItemCount(t *testing.T) {
tc := New(DefaultExpiration, 0)
tc.Set(v1, "1", DefaultExpiration)