-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathwebook_test.go
54 lines (50 loc) · 1.16 KB
/
webook_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
package webhook
import (
"testing"
"github.com/disgoorg/snowflake/v2"
"github.com/stretchr/testify/assert"
)
func TestParseURL(t *testing.T) {
tt := []struct {
URL string
ID snowflake.ID
Token string
Err bool
}{
{
URL: "https://discord.com/api/webhooks/123456789123456789/foo",
ID: snowflake.ID(123456789123456789),
Token: "foo",
},
{
URL: "https://discord.com/api/webhooks/123456789123456789/foo/",
ID: snowflake.ID(123456789123456789),
Token: "foo",
},
{
URL: "https://canary.discord.com/api/webhooks/123456789123456789/foo",
ID: snowflake.ID(123456789123456789),
Token: "foo",
},
{
URL: "foobarbaz",
Err: true,
},
{
URL: "https://discord.com/api/webhooks/123456789123456789/foo?wait=10",
ID: snowflake.ID(123456789123456789),
Token: "foo",
},
}
for _, tc := range tt {
t.Run(tc.URL, func(t *testing.T) {
c, err := NewWithURL(tc.URL)
if tc.Err {
assert.Error(t, err, "URL parsing should have resulted in an error")
return
}
assert.Equal(t, tc.ID, c.ID(), "URL ID should match")
assert.Equal(t, tc.Token, c.Token(), "URL token should match")
})
}
}