arikawa/gateway/integration_test.go

58 lines
1.1 KiB
Go
Raw Normal View History

2020-01-15 07:34:18 +00:00
// +build integration
package gateway
import (
"log"
"os"
"testing"
)
func TestIntegration(t *testing.T) {
var token = os.Getenv("BOT_TOKEN")
if token == "" {
t.Fatal("Missing $BOT_TOKEN")
}
WSError = func(err error) {
2020-01-16 03:28:21 +00:00
log.Println(err)
2020-01-15 07:34:18 +00:00
}
var gateway *Gateway
// NewGateway should call Start for us.
2020-01-16 04:27:57 +00:00
g, err := NewGateway("Bot " + token)
2020-01-15 07:34:18 +00:00
if err != nil {
t.Fatal("Failed to make a Gateway:", err)
}
gateway = g
ready, ok := (<-gateway.Events).(*ReadyEvent)
if !ok {
t.Fatal("Event received is not of type Ready:", ready)
}
if gateway.SessionID == "" {
t.Fatal("Session ID is empty")
}
log.Println("Bot's username is", ready.User.Username)
// Try and reconnect
if err := gateway.Reconnect(); err != nil {
t.Fatal("Failed to reconnect:", err)
}
2020-01-16 03:28:21 +00:00
/* TODO: this isn't true, as Discord would keep sending Invalid Sessions.
2020-01-15 07:34:18 +00:00
resumed, ok := (<-gateway.Events).(*ResumedEvent)
if !ok {
t.Fatal("Event received is not of type Resumed:", resumed)
}
2020-01-16 03:28:21 +00:00
*/
ready, ok = (<-gateway.Events).(*ReadyEvent)
if !ok {
t.Fatal("Event received is not of type Ready:", ready)
}
2020-01-15 07:34:18 +00:00
}