-
Notifications
You must be signed in to change notification settings - Fork 0
/
nop_test.go
50 lines (40 loc) · 1.1 KB
/
nop_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
47
48
49
50
// Copyright The ActForGood Authors.
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://github.com/actforgood/xcache/blob/main/LICENSE.
package xcache_test
import (
"context"
"errors"
"testing"
"github.com/actforgood/xcache"
)
func init() {
var _ xcache.Cache = (*xcache.Nop)(nil) // test Nop is a Cache
}
func TestNop(t *testing.T) {
t.Parallel()
// arrange
var (
subject = xcache.Nop{}
key = "test-nop-key"
value = []byte("test ignored value")
ctx = context.Background()
exp = xcache.NoExpire
)
// act & assert save
resultErr := subject.Save(ctx, key, value, exp)
requireNil(t, resultErr)
// act & assert load
resultValue, resultErr := subject.Load(ctx, key)
assertTrue(t, errors.Is(resultErr, xcache.ErrNotFound))
assertNil(t, resultValue)
// act & assert ttl
resultExp, resultErr := subject.TTL(ctx, key)
assertNil(t, resultErr)
assertTrue(t, resultExp < 0)
// act & assert stats
resultStats, resultErr := subject.Stats(ctx)
assertEqual(t, xcache.Stats{}, resultStats)
assertNil(t, resultErr)
}