From b59d9bfed778f53e0bee79322473ec3717482dc3 Mon Sep 17 00:00:00 2001 From: "diamondburned (Forefront)" Date: Mon, 16 Mar 2020 18:29:23 -0700 Subject: [PATCH] Arikawa: Updated /x/errors; Gateway: Added TestInvalidToken --- gateway/integration_test.go | 21 +++++++++++++++++++++ go.mod | 2 +- go.sum | 2 ++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/gateway/integration_test.go b/gateway/integration_test.go index 7b0ac11..a4fb6ce 100644 --- a/gateway/integration_test.go +++ b/gateway/integration_test.go @@ -7,8 +7,29 @@ import ( "os" "testing" "time" + + "nhooyr.io/websocket" ) +func TestInvalidToken(t *testing.T) { + g, err := NewGateway("bad token") + if err != nil { + t.Fatal("Failed to make a Gateway:", err) + } + + err = g.Open() + if err == nil { + t.Fatal("Unexpected success while opening with a bad token.") + } + + // 4004 Authentication Failed. + if websocket.CloseStatus(err) == 4004 { + return + } + + t.Fatal("Unexpected error:", err) +} + func TestIntegration(t *testing.T) { var token = os.Getenv("BOT_TOKEN") if token == "" { diff --git a/go.mod b/go.mod index 1ee0574..22bcc87 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.13 require ( github.com/gorilla/schema v1.1.0 - github.com/pkg/errors v0.8.1 + github.com/pkg/errors v0.9.1 github.com/sasha-s/go-csync v0.0.0-20160729053059-3bc6c8bdb3fa golang.org/x/net v0.0.0-20200202094626-16171245cfb2 // indirect golang.org/x/time v0.0.0-20191024005414-555d28b269f0 diff --git a/go.sum b/go.sum index 2e27e8a..08d1195 100644 --- a/go.sum +++ b/go.sum @@ -22,6 +22,8 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/sasha-s/go-csync v0.0.0-20160729053059-3bc6c8bdb3fa h1:xiD6U6h+QMkAwI195dFwdku2N+enlCy9XwFTnEXaCQo=