MCPcopy
hub / github.com/coocood/freecache / TestInt64Key

Function TestInt64Key

cache_test.go:689–727  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

687}
688
689func TestInt64Key(t *testing.T) {
690 cache := NewCache(1024)
691 err := cache.SetInt(1, []byte("abc"), 3)
692 if err != nil {
693 t.Error("err should be nil")
694 }
695 err = cache.SetInt(2, []byte("cde"), 3)
696 if err != nil {
697 t.Error("err should be nil")
698 }
699 val, err := cache.GetInt(1)
700 if err != nil {
701 t.Error("err should be nil")
702 }
703 if !bytes.Equal(val, []byte("abc")) {
704 t.Error("value not equal")
705 }
706 time.Sleep(2 * time.Second)
707 val, expiry, err := cache.GetIntWithExpiration(1)
708 if err != nil {
709 t.Error("err should be nil")
710 }
711 if !bytes.Equal(val, []byte("abc")) {
712 t.Error("value not equal")
713 }
714 now := time.Now()
715 if expiry != uint32(now.Unix()+1) {
716 t.Errorf("Expiry should one second in the future but was %v", now)
717 }
718
719 affected := cache.DelInt(1)
720 if !affected {
721 t.Error("del should return affected true")
722 }
723 _, err = cache.GetInt(1)
724 if err != ErrNotFound {
725 t.Error("error should be ErrNotFound after being deleted")
726 }
727}
728
729func TestIterator(t *testing.T) {
730 cache := NewCache(1024)

Callers

nothing calls this directly

Calls 6

SetIntMethod · 0.95
GetIntMethod · 0.95
GetIntWithExpirationMethod · 0.95
DelIntMethod · 0.95
NewCacheFunction · 0.85
NowMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…