bitbucket.org/alima123/expires@v0.0.0-20191226173914-cddaf5cffb3d/cachemap_test.go (about) 1 package expires 2 3 import ( 4 "fmt" 5 "testing" 6 "time" 7 ) 8 9 func TestCacheMapDataExpires(t *testing.T) { 10 cm := CacheOpMap{} 11 cache := cm.LazyInitCachePoolOp("op") 12 cache.Store("key_1", NewDataExpires("value_1", 1*time.Second)) 13 14 time.Sleep(1 * time.Second) 15 data, ok := cache.Load("key_1") 16 if !ok { 17 t.FailNow() 18 } 19 fmt.Printf("data: %s\n", data.Data()) 20 } 21 22 func TestCacheOperation(t *testing.T) { 23 cm := CacheOpMap{} 24 data := cm.CacheOperation("op", "key_1", func() DataExpires { 25 return NewDataExpires("value_1", 1*time.Second) 26 }) 27 fmt.Printf("data: %s\n", data.Data()) 28 29 newData := cm.CacheOperation("op", "key_1", func() DataExpires { 30 return NewDataExpires("value_3", 1*time.Second) 31 }) 32 if data != newData { 33 t.FailNow() 34 } 35 fmt.Printf("data: %s\n", data.Data()) 36 }