MCPcopy
hub / github.com/crowdsecurity/crowdsec / TestCreateSetGet

Function TestCreateSetGet

pkg/cache/cache_test.go:11–31  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

9)
10
11func TestCreateSetGet(t *testing.T) {
12 err := CacheInit(CacheCfg{Name: "test", Size: 100, TTL: 1 * time.Second}, nil)
13 require.NoError(t, err)
14 //set & get
15 err = SetKey("test", "testkey0", "testvalue1", nil)
16 require.NoError(t, err)
17
18 ret, err := GetKey("test", "testkey0")
19 assert.Equal(t, "testvalue1", ret)
20 require.NoError(t, err)
21 //re-set
22 err = SetKey("test", "testkey0", "testvalue2", nil)
23 require.NoError(t, err)
24 assert.Equal(t, "testvalue1", ret)
25 require.NoError(t, err)
26 //expire
27 time.Sleep(1500 * time.Millisecond)
28 ret, err = GetKey("test", "testkey0")
29 assert.Empty(t, ret)
30 require.NoError(t, err)
31}

Callers

nothing calls this directly

Calls 4

CacheInitFunction · 0.85
SetKeyFunction · 0.85
GetKeyFunction · 0.85
EmptyMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…