-
Notifications
You must be signed in to change notification settings - Fork 0
/
group_test.go
95 lines (77 loc) · 2.39 KB
/
group_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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package i18n
import (
"testing"
"golang.org/x/text/language"
. "github.com/smartystreets/goconvey/convey"
)
func TestGroup(t *testing.T) {
t.Parallel()
Convey("Given an i18n group", t, func() {
storage := NewInMemoryStorage()
i18n := New(storage)
group := i18n.Group("SomeKey")
Convey("When a translation is added", func() {
expected := &Translation{
Lang: language.English,
Key: "SomeKey",
Value: "SomeValue",
}
err := group.Add(expected)
So(err, ShouldBeNil)
Convey("Then the translation should be accessable", func() {
result := group.Get(language.English, "SomeKey")
So(result, ShouldNotBeNil)
So(result, ShouldResemble, expected)
})
Convey("Then the translation should be accessable with locle string", func() {
result, err := group.GetWithLangString("en", "SomeKey")
So(err, ShouldBeNil)
So(result, ShouldNotBeNil)
So(result, ShouldResemble, expected)
})
Convey("Then the translation should be accessable with a child language", func() {
result := group.Get(language.BritishEnglish, "SomeKey")
So(err, ShouldBeNil)
So(result, ShouldNotBeNil)
So(result, ShouldResemble, expected)
})
Convey("Then the translation should exist in the storage", func() {
results, err := storage.GetAll()
So(err, ShouldBeNil)
So(results, ShouldHaveLength, 1)
So(results[0], ShouldResemble, expected)
})
Convey("Then the translation should be accessable through the helper method", func() {
result1 := group.T(language.English.String(), "SomeKey")
result2 := group.T(language.English, "SomeKey")
So(result1, ShouldEqual, expected.Value)
So(result2, ShouldEqual, expected.Value)
})
})
})
Convey("Given a popluated group", t, func() {
storage := NewInMemoryStorage()
i18n := New(storage)
group := i18n.Group("SomeKey")
expected := &Translation{
Lang: language.English,
Key: "SomeKey",
Value: "SomeValue",
}
err := group.Add(expected)
So(err, ShouldBeNil)
Convey("When an item is deleted", func() {
err := group.Delete(expected)
So(err, ShouldBeNil)
Convey("Then item should not be accessable", func() {
result := group.Get(language.English, "SomeKey")
So(result, ShouldBeNil)
})
Convey("Then item should not exist in storage", func() {
results, err := storage.GetAll()
So(err, ShouldBeNil)
So(results, ShouldHaveLength, 0)
})
})
})
}