-
Notifications
You must be signed in to change notification settings - Fork 1
/
mock_test.go
59 lines (50 loc) · 1.34 KB
/
mock_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
package discordgoi18n
import (
"testing"
"github.com/bwmarrin/discordgo"
"github.com/stretchr/testify/assert"
)
func TestMock(t *testing.T) {
// Must not panic
mock := newMock()
mock.SetDefault(discordgo.ChineseCN)
assert.NoError(t, mock.LoadBundle(discordgo.SpanishES, ""))
assert.Empty(t, mock.Get(discordgo.Croatian, "", nil))
assert.Empty(t, mock.GetDefault("", nil))
assert.Nil(t, mock.GetLocalizations("", nil))
var called bool
mock.SetDefaultFunc = func(_ discordgo.Locale) {
called = true
}
mock.LoadBundleFunc = func(_ discordgo.Locale, _ string) error {
called = true
return nil
}
mock.GetFunc = func(_ discordgo.Locale, _ string, _ Vars) string {
called = true
return ""
}
mock.GetDefaultFunc = func(_ string, _ Vars) string {
called = true
return ""
}
mock.GetLocalizationsFunc = func(_ string, _ Vars) *map[discordgo.Locale]string {
called = true
return nil
}
called = false
mock.SetDefault(discordgo.ChineseCN)
assert.True(t, called)
called = false
assert.NoError(t, mock.LoadBundle(discordgo.SpanishES, ""))
assert.True(t, called)
called = false
assert.Empty(t, mock.Get(discordgo.Croatian, "", nil))
assert.True(t, called)
called = false
assert.Empty(t, mock.GetDefault("", nil))
assert.True(t, called)
called = false
assert.Empty(t, mock.GetLocalizations("", nil))
assert.True(t, called)
}