forked from andersfylling/disgord
-
Notifications
You must be signed in to change notification settings - Fork 0
/
channel_test.go
54 lines (46 loc) · 1.14 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
//go:build !integration
// +build !integration
package disgord
import (
"testing"
"github.com/andersfylling/disgord/json"
)
func TestChannel_DeepCopy(t *testing.T) {
test := &Channel{}
icon1 := "sdljfdsjf"
test.Icon = icon1
test.PermissionOverwrites = append(test.PermissionOverwrites, PermissionOverwrite{
Type: 0,
})
test.PermissionOverwrites = append(test.PermissionOverwrites, PermissionOverwrite{
Type: 1,
})
cp := DeepCopy(test).(*Channel)
icon2 := "sfkjdsf"
test.Icon = icon2
if cp.Icon != icon1 {
t.Error("deep copy failed")
}
test.PermissionOverwrites = append(test.PermissionOverwrites, PermissionOverwrite{
Type: 2,
})
if len(cp.PermissionOverwrites) != 2 {
t.Error("deep copy failed")
}
}
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 := json.Unmarshal(data, &c); err != nil {
t.Fatal(err)
}
executeInternalUpdater(c)
if c.Icon != "" {
t.Error(c.Icon, "was not empty")
}
}