Skip to content

Commit

Permalink
add TestKeys
Browse files Browse the repository at this point in the history
  • Loading branch information
knbr13 committed May 22, 2024
1 parent f6c5331 commit c686793
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions mcache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,30 @@ func TestCopyTo(t *testing.T) {
func TestKeys(t *testing.T) {
c := NewManual[string, string](10, 0)

c.Set("key1", "value1")
c.Set("key2", "value2")
c.SetWithTimeout("key3", "value3", 1)
c.SetWithTimeout("key4", "value4", 1)
c.SetWithTimeout("key5", "value5", 1)
c.Set("key6", "value6")

keys := c.Keys()

if len(keys) != 3 {
t.Errorf("Unexpected number of keys returned")
}

expectedKeys := map[string]bool{"key1": true, "key2": true, "key6": true}
for _, key := range keys {
if !expectedKeys[key] {
t.Errorf("Unexpected key %s returned", key)
}
}
}

func TestAllKeys(t *testing.T) {
c := NewManual[string, string](10, 0)

c.Set("key1", "value1")
c.Set("key2", "value2")

Expand All @@ -202,9 +226,12 @@ func TestKeys(t *testing.T) {
func TestPurge(t *testing.T) {
c := NewManual[string, string](10, time.Millisecond*100)

c.Set("1", "one")
c.Set("2", "two")
c.SetWithTimeout("3", "three", time.Second)
c.Set("key1", "value1")
c.Set("key2", "value2")
c.SetWithTimeout("key3", "value3", 1)
c.SetWithTimeout("key4", "value4", 1)
c.SetWithTimeout("key5", "value5", 1)
c.Set("key6", "value6")

c.Purge()

Expand Down

0 comments on commit c686793

Please sign in to comment.