-
Notifications
You must be signed in to change notification settings - Fork 0
/
cache_test.go
62 lines (51 loc) · 1.3 KB
/
cache_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
51
52
53
54
55
56
57
58
59
60
61
62
package i18n
import (
"testing"
"golang.org/x/text/language"
. "github.com/smartystreets/goconvey/convey"
)
func TestCache(t *testing.T) {
t.Parallel()
Convey("Given an empty cache", t, func() {
cache := new(Cache)
Convey("When an item is added to the cache", func() {
expected := &Translation{
Lang: language.English,
Key: "SomeKey",
Value: "SomeValue",
}
cache.Add(expected)
Convey("Then it should be accessable", func() {
result := cache.Get(language.English, "SomeKey")
So(result, ShouldNotBeNil)
So(result, ShouldResemble, expected)
})
})
})
Convey("Given a populated cache", t, func() {
cache := new(Cache)
cache.Add(&Translation{
Lang: language.English,
Key: "SomeKey",
Value: "SomeValue",
})
Convey("When an item is deleted from the cache", func() {
cache.Delete(&Translation{
Lang: language.English,
Key: "SomeKey",
Value: "SomeValue",
})
Convey("The item should not exists in the cache", func() {
result := cache.Get(language.English, "SomeKey")
So(result, ShouldBeNil)
})
})
Convey("When the cache is cleared", func() {
cache.Clear()
Convey("The item should not exists in the cache", func() {
result := cache.Get(language.English, "SomeKey")
So(result, ShouldBeNil)
})
})
})
}