-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathtoken_test.go
40 lines (33 loc) · 868 Bytes
/
token_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
package tempest
import (
"strings"
"testing"
)
func TestUserToken(t *testing.T) {
const exampleBotToken = "MTE3ODAzNjYxNjU1NjcyODM2MA.GWWLzQ.xI3VzmU5Pj1we5IjRLeKQVjBiHCYJmAdTlfWEo"
const exampleBotUserID Snowflake = 1178036616556728360
t.Run("success", func(t *testing.T) {
ID, err := extractUserIDFromToken(exampleBotToken)
if err != nil {
t.Error(err)
}
if ID != exampleBotUserID {
t.Error("extracted ID is invalid")
}
})
t.Run("failure/creation", func(t *testing.T) {
_, err := StringToSnowflake(strings.ReplaceAll(exampleBotToken, ".", ""))
if err == nil {
t.Error(err)
}
})
t.Run("failure/extraction", func(t *testing.T) {
ID, err := extractUserIDFromToken(strings.ReplaceAll(exampleBotToken, "z", "x"))
if err != nil {
t.Error(err)
}
if ID == exampleBotUserID {
t.Error("extracted ID is invalid")
}
})
}