mirror of
https://github.com/diamondburned/arikawa.git
synced 2024-11-01 04:24:19 +00:00
2c2daec84b
This should make integration tests pass in CI.
83 lines
1.4 KiB
Go
83 lines
1.4 KiB
Go
//go:build !uintonly
|
|
// +build !uintonly
|
|
|
|
package testenv
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
"strconv"
|
|
"sync"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/diamondburned/arikawa/v3/discord"
|
|
)
|
|
|
|
const PerseveranceTime = 50 * time.Minute
|
|
const DefaultShardCount = 2
|
|
|
|
type Env struct {
|
|
BotToken string
|
|
ChannelID discord.ChannelID
|
|
VoiceChID discord.ChannelID
|
|
ShardCount int
|
|
}
|
|
|
|
var (
|
|
globalEnv Env
|
|
globalErr error
|
|
once sync.Once
|
|
)
|
|
|
|
func Must(t *testing.T) Env {
|
|
if testing.Short() {
|
|
t.Skip("skipping integration test")
|
|
}
|
|
|
|
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 = fmt.Errorf("invalid $CHANNEL_ID: %w", err)
|
|
return
|
|
}
|
|
|
|
vid, err := discord.ParseSnowflake(os.Getenv("VOICE_ID"))
|
|
if err != nil {
|
|
globalErr = fmt.Errorf("invalid $VOICE_ID: %w", err)
|
|
return
|
|
}
|
|
|
|
shardCount := DefaultShardCount
|
|
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,
|
|
}
|
|
}
|