-
Notifications
You must be signed in to change notification settings - Fork 0
/
entry_test.go
46 lines (37 loc) · 1.15 KB
/
entry_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package gocached_test
import (
"testing"
"time"
"github.com/lazharichir/gocached"
"github.com/stretchr/testify/assert"
)
func TestEntry(t *testing.T) {
expiryDate := time.Now().Add(1 * time.Hour)
ttl := 10 * time.Minute
entry := &gocached.Entry[string, int]{
Key: "foo",
Value: 42,
Written: time.Now(),
Options: gocached.EntryOptions{
ExpiryDate: &expiryDate,
TTL: &ttl,
},
}
// Test IsOutdated method
assert.False(t, entry.IsOutdated(), "Expected entry to not be outdated")
// Test isPastExpiryDate method
assert.False(t, entry.IsPastExpiryDate(), "Expected entry to not be past expiry date")
// Test isPastTTL method
assert.False(t, entry.IsPastTTL(), "Expected entry to not be past TTL")
}
func TestEntryOptions(t *testing.T) {
expiryDate := time.Now().Add(1 * time.Hour)
ttl := 10 * time.Minute
// Test EntryOptions
options := gocached.EntryOptions{
ExpiryDate: &expiryDate,
TTL: &ttl,
}
assert.Equal(t, expiryDate, *options.ExpiryDate, "Expected expiry date to be %v, got %v", expiryDate, *options.ExpiryDate)
assert.Equal(t, ttl, *options.TTL, "Expected TTL to be %v, got %v", ttl, *options.TTL)
}