github.com/projecteru2/core@v0.0.0-20240321043226-06bcc1c23f58/utils/cache_test.go (about) 1 package utils 2 3 import ( 4 "testing" 5 "time" 6 7 enginemocks "github.com/projecteru2/core/engine/mocks" 8 9 "github.com/stretchr/testify/assert" 10 ) 11 12 func TestCache(t *testing.T) { 13 c := NewEngineCache(2*time.Second, time.Second) 14 15 host := "1.1.1.1" 16 cli := &enginemocks.API{} 17 c.Set(host, cli) 18 assert.Equal(t, c.Get(host), cli) 19 c.Delete(host) 20 assert.Nil(t, c.Get(host)) 21 time.Sleep(3 * time.Second) 22 assert.Nil(t, c.Get(host)) 23 }