feat(discord_test#init): check for oauth2 token

This commit is contained in:
nitroflap 2022-02-16 16:38:21 +03:00
parent 7044ee62cb
commit 3d0ad546d1
No known key found for this signature in database
GPG key ID: 810F53DB0E0F81A8

View file

@ -15,11 +15,11 @@ var (
dg *Session // Stores a global discordgo user session
dgBot *Session // Stores a global discordgo bot session
envToken = os.Getenv("DGU_TOKEN") // Token to use when authenticating the user account
envBotToken = os.Getenv("DGB_TOKEN") // Token to use when authenticating the bot account
envGuild = os.Getenv("DG_GUILD") // Guild ID to use for tests
envChannel = os.Getenv("DG_CHANNEL") // Channel ID to use for tests
envAdmin = os.Getenv("DG_ADMIN") // User ID of admin user to use for tests
envOAuth2Token = os.Getenv("DG_OAUTH2_TOKEN") // Token to use when authenticating using OAuth2 token
envBotToken = os.Getenv("DGB_TOKEN") // Token to use when authenticating the bot account
envGuild = os.Getenv("DG_GUILD") // Guild ID to use for tests
envChannel = os.Getenv("DG_CHANNEL") // Channel ID to use for tests
envAdmin = os.Getenv("DG_ADMIN") // User ID of admin user to use for tests
)
func init() {
@ -30,10 +30,10 @@ func init() {
}
}
if d, err := New(envToken); err == nil {
dg = d
} else {
fmt.Println("dg is nil, error", err)
if envOAuth2Token != "" {
if d, err := New(envOAuth2Token); err == nil {
dg = d
}
}
}
@ -43,11 +43,11 @@ func init() {
// TestNewToken tests the New() function with a Token.
func TestNewToken(t *testing.T) {
if envToken == "" {
if envOAuth2Token == "" {
t.Skip("Skipping New(token), DGU_TOKEN not set")
}
d, err := New(envToken)
d, err := New(envOAuth2Token)
if err != nil {
t.Fatalf("New(envToken) returned error: %+v", err)
}
@ -62,11 +62,11 @@ func TestNewToken(t *testing.T) {
}
func TestOpenClose(t *testing.T) {
if envToken == "" {
if envOAuth2Token == "" {
t.Skip("Skipping TestClose, DGU_TOKEN not set")
}
d, err := New(envToken)
d, err := New(envOAuth2Token)
if err != nil {
t.Fatalf("TestClose, New(envToken) returned error: %+v", err)
}