forked from andersfylling/disgord
-
Notifications
You must be signed in to change notification settings - Fork 0
/
channel_test.go
92 lines (81 loc) · 2.19 KB
/
channel_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
// +build !integration
package disgord
import (
"io/ioutil"
"testing"
"github.com/andersfylling/disgord/internal/util"
)
func TestChannel_DeepCopy(t *testing.T) {
test := NewChannel()
icon1 := "sdljfdsjf"
test.Icon = icon1
test.PermissionOverwrites = append(test.PermissionOverwrites, PermissionOverwrite{
Type: "first",
})
test.PermissionOverwrites = append(test.PermissionOverwrites, PermissionOverwrite{
Type: "second",
})
copy := test.DeepCopy().(*Channel)
icon2 := "sfkjdsf"
test.Icon = icon2
if copy.Icon != icon1 {
t.Error("deep copy failed")
}
test.PermissionOverwrites = append(test.PermissionOverwrites, PermissionOverwrite{
Type: "third",
})
if len(copy.PermissionOverwrites) != 2 {
t.Error("deep copy failed")
}
}
func checkForChannelUnmarshalErr(t *testing.T, data []byte) {
v := Channel{}
if err := unmarshal(data, &v); err != nil {
t.Error(err)
}
}
func TestChannel_UnmarshalJSON(t *testing.T) {
t.Run("create", func(t *testing.T) {
data, err := ioutil.ReadFile("testdata/channel/channel_create.json")
check(err, t)
checkForChannelUnmarshalErr(t, data)
})
t.Run("update", func(t *testing.T) {
files := []string{
"testdata/channel/update_name.json",
"testdata/channel/update_nsfw1.json",
"testdata/channel/update_nsfw2.json",
"testdata/channel/update_ratelimit.json",
"testdata/channel/update_ratelimit_removed.json",
"testdata/channel/update_topic.json",
"testdata/channel/update_topic_removed.json",
}
for _, file := range files {
data, err := ioutil.ReadFile(file)
check(err, t)
checkForChannelUnmarshalErr(t, data)
}
})
t.Run("delete", func(t *testing.T) {
data, err := ioutil.ReadFile("testdata/channel/delete.json")
check(err, t)
checkForChannelUnmarshalErr(t, data)
})
}
func TestChannel_saveToDiscord(t *testing.T) {
}
func TestChannel_JSONIconNull(t *testing.T) {
// check if null's in json are parsed as an empty string
data := []byte(`{"id":"324234235","type":1,"icon":null}`)
var c *struct {
ID Snowflake `json:"id"`
Type int `json:"type"`
Icon string `json:"icon"`
}
if err := util.Unmarshal(data, &c); err != nil {
t.Fatal(err)
}
if c.Icon != "" {
t.Error(c.Icon, "was not empty")
}
}