Use the generic Set to replace deprecated methods (#5623)

This commit is contained in:
Xinzhao Xu
2023-04-07 11:15:35 +08:00
committed by GitHub
parent 634988f529
commit 708de806f8
16 changed files with 99 additions and 110 deletions

View File

@@ -66,8 +66,8 @@ func dump(client Interface) (map[string]string, error) {
func TestDeleteAndExpireCache(t *testing.T) {
var testCases = []struct {
description string
deleteKeys sets.String
expireKeys sets.String
deleteKeys sets.Set[string]
expireKeys sets.Set[string]
expireDuration time.Duration // never use a 0(NeverExpires) duration with expireKeys, recommend time.Millisecond * 500.
expected map[string]string
}{
@@ -88,7 +88,7 @@ func TestDeleteAndExpireCache(t *testing.T) {
"foo2": "val2",
"foo3": "val3",
},
deleteKeys: sets.NewString("bar1", "bar2"),
deleteKeys: sets.New("bar1", "bar2"),
},
{
description: "Should get only keys start with bar",
@@ -97,7 +97,7 @@ func TestDeleteAndExpireCache(t *testing.T) {
"bar2": "val2",
},
expireDuration: time.Millisecond * 500,
expireKeys: sets.NewString("foo1", "foo2", "foo3"),
expireKeys: sets.New("foo1", "foo2", "foo3"),
},
}
@@ -111,14 +111,14 @@ func TestDeleteAndExpireCache(t *testing.T) {
}
if len(testCase.deleteKeys) != 0 {
err = cacheClient.Del(testCase.deleteKeys.List()...)
err = cacheClient.Del(testCase.deleteKeys.UnsortedList()...)
if err != nil {
t.Fatalf("Error delete keys, %v", err)
}
}
if len(testCase.expireKeys) != 0 && testCase.expireDuration != 0 {
for _, key := range testCase.expireKeys.List() {
for _, key := range testCase.expireKeys.UnsortedList() {
err = cacheClient.Expire(key, testCase.expireDuration)
if err != nil {
t.Fatalf("Error expire keys, %v", err)