-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconfig_test.go
76 lines (64 loc) · 1.43 KB
/
config_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
package main
import (
"encoding/json"
"testing"
"github.com/diamondburned/arikawa/v3/discord"
"github.com/stretchr/testify/assert"
)
func TestSnowflakeLookup_MarshalJSON(t *testing.T) {
lookup := snowflakeLookup{
discord.Snowflake(1337): struct{}{},
discord.Snowflake(42): struct{}{},
discord.Snowflake(777): struct{}{},
}
d, err := json.Marshal(lookup)
assert.NoError(t, err)
assert.EqualValues(t, `["42","777","1337"]`, string(d))
}
func TestSnowflakeLookup_UnmarshalJSON(t *testing.T) {
lookup := make(snowflakeLookup)
input := []byte(`["1337","42","777"]`)
err := json.Unmarshal(input, &lookup)
assert.NoError(t, err)
expected := snowflakeLookup{
discord.Snowflake(1337): struct{}{},
discord.Snowflake(42): struct{}{},
discord.Snowflake(777): struct{}{},
}
assert.Equal(t, expected, lookup)
}
func TestConfigFromBytes(t *testing.T) {
input := []byte(`
{
"prefix": "dr.",
"permissions": {
"docs": [
"1337"
],
"config": {
"42": [
"777"
]
}
}
}
`)
config, err := configFromBytes(input)
assert.NoError(t, err)
expected := configuration{
Prefix: "dr.",
Permissions: commandPermissions{
Docs: map[discord.Snowflake]struct{}{
1337: {},
},
Config: map[discord.GuildID]snowflakeLookup{
42: map[discord.Snowflake]struct{}{
777: {},
},
},
},
Aliases: map[string]string{},
Blacklist: map[discord.Snowflake]struct{}{},
}
assert.Equal(t, expected, config)
}