Skip to content

Commit

Permalink
Improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
s12v committed Jul 30, 2018
1 parent ea5fa8f commit 856e5f0
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import (
"time"
)

func TestDefaultCache_Get(t *testing.T) {
func TestDefaultCache_GetWithExpiration(t *testing.T) {
c := &defaultCache{
cache.New(1, 0),
cache.New(time.Minute, 0),
}

c.cache.Set("key", "val", time.Minute)
val, expTime, found := c.cache.GetWithExpiration("key")
c.Set("key", "val")
val, expTime, found := c.GetWithExpiration("key")

if expTime.Before(time.Now()) {
t.Fatalf("expTime should be after now: %v", expTime)
Expand All @@ -27,14 +27,14 @@ func TestDefaultCache_Get(t *testing.T) {
}
}

func TestDefaultCache_GetExpired(t *testing.T) {
func TestDefaultCache_GetWithExpiration_Expired(t *testing.T) {
c := &defaultCache{
cache.New(1, 0),
cache.New(time.Nanosecond, 0),
}

c.cache.Set("key", "val", time.Nanosecond)
c.Set("key", "val")
time.Sleep(10 * time.Millisecond)
val, expTime, found := c.cache.GetWithExpiration("key")
val, expTime, found := c.GetWithExpiration("key")

if expTime.After(time.Now()) {
t.Fatalf("expTime should be before now: %v", expTime)
Expand Down

0 comments on commit 856e5f0

Please sign in to comment.