100-go-mistakes/11-testing/87-time-api/listing1/main_test.go
2021-12-27 15:56:17 +01:00

22 lines
481 B
Go

package listing1
import (
"testing"
"time"
)
func TestCache_TrimBefore(t *testing.T) {
events := []Event{
{Timestamp: time.Now().Add(-20 * time.Millisecond)},
{Timestamp: time.Now().Add(-10 * time.Millisecond)},
{Timestamp: time.Now().Add(10 * time.Millisecond)},
}
cache := &Cache{}
cache.Add(events)
cache.TrimBefore(15 * time.Millisecond)
got := cache.GetAll()
expected := 2
if len(got) != expected {
t.Fatalf("expected %d, got %d", expected, len(got))
}
}