mirror of
https://github.com/diamondburned/arikawa.git
synced 2024-12-12 08:25:10 +00:00
4158db8715
This commit makes it so that all API wrapper methods under state will ignore errors returned from the cabinet setters. This is because an intermittent error from the state shouldn't shadow the actual result from the Discord API.
75 lines
1.2 KiB
Go
75 lines
1.2 KiB
Go
// +build !uintonly
|
|
|
|
package testenv
|
|
|
|
import (
|
|
"os"
|
|
"strconv"
|
|
"sync"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/diamondburned/arikawa/v3/discord"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
const PerseveranceTime = 50 * time.Minute
|
|
|
|
type Env struct {
|
|
BotToken string
|
|
ChannelID discord.ChannelID
|
|
VoiceChID discord.ChannelID
|
|
ShardCount int // default 3
|
|
}
|
|
|
|
var (
|
|
globalEnv Env
|
|
globalErr error
|
|
once sync.Once
|
|
)
|
|
|
|
func Must(t *testing.T) Env {
|
|
e, err := GetEnv()
|
|
if err != nil {
|
|
t.Skip("integration test variables missing")
|
|
}
|
|
return e
|
|
}
|
|
|
|
func GetEnv() (Env, error) {
|
|
once.Do(getEnv)
|
|
return globalEnv, globalErr
|
|
}
|
|
|
|
func getEnv() {
|
|
token := os.Getenv("BOT_TOKEN")
|
|
if token == "" {
|
|
globalErr = errors.New("missing $BOT_TOKEN")
|
|
return
|
|
}
|
|
|
|
id, err := discord.ParseSnowflake(os.Getenv("CHANNEL_ID"))
|
|
if err != nil {
|
|
globalErr = errors.Wrap(err, "invalid $CHANNEL_ID")
|
|
return
|
|
}
|
|
|
|
vid, err := discord.ParseSnowflake(os.Getenv("VOICE_ID"))
|
|
if err != nil {
|
|
globalErr = errors.Wrap(err, "invalid $VOICE_ID")
|
|
return
|
|
}
|
|
|
|
shardCount := 2
|
|
if c, err := strconv.Atoi(os.Getenv("SHARD_COUNT")); err == nil {
|
|
shardCount = c
|
|
}
|
|
|
|
globalEnv = Env{
|
|
BotToken: token,
|
|
ChannelID: discord.ChannelID(id),
|
|
VoiceChID: discord.ChannelID(vid),
|
|
ShardCount: shardCount,
|
|
}
|
|
}
|