alice-lg/pkg/caches/neighbors_test.go

44 lines
725 B
Go
Raw Permalink Normal View History

2018-07-11 14:56:38 +02:00
package caches
import (
2021-04-15 19:06:34 +02:00
"github.com/alice-lg/alice-lg/pkg/api"
"testing"
"time"
)
/*
NeighborsCache Tests
*/
func TestNeighborsCacheSetGet(t *testing.T) {
cache := NewNeighborsCache(false)
2021-10-15 17:17:11 +02:00
response := &api.NeighborsResponse{
Response: api.Response{
2021-10-27 18:04:35 +00:00
Meta: &api.Meta{
2021-10-15 17:17:11 +02:00
TTL: time.Now().UTC().Add(23 * time.Millisecond),
},
},
}
if cache.Get() != nil {
t.Error("There should not be anything cached yet!")
}
cache.Set(response)
fromCache := cache.Get()
if fromCache != response {
t.Error("Expected", response, "got", fromCache)
}
// Wait a bit
2018-07-11 15:09:44 +02:00
time.Sleep(33 * time.Millisecond)
fromCache = cache.Get()
if fromCache != nil {
t.Error("Expected empty cache result, got:", fromCache)
}
}