2023-06-08 01:02:48 +00:00
|
|
|
//go:build !uintonly
|
2020-12-01 01:49:18 +00:00
|
|
|
// +build !uintonly
|
|
|
|
|
|
|
|
package testenv
|
|
|
|
|
|
|
|
import (
|
2023-09-19 15:25:48 +00:00
|
|
|
"errors"
|
2023-09-19 15:23:25 +00:00
|
|
|
"fmt"
|
2020-12-01 01:49:18 +00:00
|
|
|
"os"
|
2021-06-10 23:48:32 +00:00
|
|
|
"strconv"
|
2020-12-01 01:49:18 +00:00
|
|
|
"sync"
|
|
|
|
"testing"
|
2021-01-01 07:48:29 +00:00
|
|
|
"time"
|
2020-12-01 01:49:18 +00:00
|
|
|
|
2021-06-02 02:53:19 +00:00
|
|
|
"github.com/diamondburned/arikawa/v3/discord"
|
2020-12-01 01:49:18 +00:00
|
|
|
)
|
|
|
|
|
2021-01-01 07:48:29 +00:00
|
|
|
const PerseveranceTime = 50 * time.Minute
|
2023-11-04 09:21:49 +00:00
|
|
|
const DefaultShardCount = 2
|
2021-01-01 07:48:29 +00:00
|
|
|
|
2020-12-01 01:49:18 +00:00
|
|
|
type Env struct {
|
2021-06-10 23:48:32 +00:00
|
|
|
BotToken string
|
|
|
|
ChannelID discord.ChannelID
|
|
|
|
VoiceChID discord.ChannelID
|
2023-11-04 09:21:49 +00:00
|
|
|
ShardCount int
|
2020-12-01 01:49:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
2020-12-12 01:58:52 +00:00
|
|
|
globalEnv Env
|
|
|
|
globalErr error
|
|
|
|
once sync.Once
|
2020-12-01 01:49:18 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func Must(t *testing.T) Env {
|
2023-06-08 01:02:48 +00:00
|
|
|
if testing.Short() {
|
|
|
|
t.Skip("skipping integration test")
|
|
|
|
}
|
|
|
|
|
2020-12-01 01:49:18 +00:00
|
|
|
e, err := GetEnv()
|
|
|
|
if err != nil {
|
2021-01-01 07:48:29 +00:00
|
|
|
t.Skip("integration test variables missing")
|
2020-12-01 01:49:18 +00:00
|
|
|
}
|
2023-06-08 01:02:48 +00:00
|
|
|
|
2020-12-01 01:49:18 +00:00
|
|
|
return e
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetEnv() (Env, error) {
|
|
|
|
once.Do(getEnv)
|
2020-12-12 01:58:52 +00:00
|
|
|
return globalEnv, globalErr
|
2020-12-01 01:49:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func getEnv() {
|
2021-06-10 23:48:32 +00:00
|
|
|
token := os.Getenv("BOT_TOKEN")
|
2020-12-01 01:49:18 +00:00
|
|
|
if token == "" {
|
2020-12-12 01:58:52 +00:00
|
|
|
globalErr = errors.New("missing $BOT_TOKEN")
|
2020-12-01 01:49:18 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-06-10 23:48:32 +00:00
|
|
|
id, err := discord.ParseSnowflake(os.Getenv("CHANNEL_ID"))
|
2020-12-01 01:49:18 +00:00
|
|
|
if err != nil {
|
2023-09-19 15:23:25 +00:00
|
|
|
globalErr = fmt.Errorf("invalid $CHANNEL_ID: %w", err)
|
2020-12-01 01:49:18 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-06-10 23:48:32 +00:00
|
|
|
vid, err := discord.ParseSnowflake(os.Getenv("VOICE_ID"))
|
2020-12-01 01:49:18 +00:00
|
|
|
if err != nil {
|
2023-09-19 15:23:25 +00:00
|
|
|
globalErr = fmt.Errorf("invalid $VOICE_ID: %w", err)
|
2020-12-01 01:49:18 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-11-04 09:21:49 +00:00
|
|
|
shardCount := DefaultShardCount
|
2021-06-10 23:48:32 +00:00
|
|
|
if c, err := strconv.Atoi(os.Getenv("SHARD_COUNT")); err == nil {
|
|
|
|
shardCount = c
|
|
|
|
}
|
|
|
|
|
2020-12-12 01:58:52 +00:00
|
|
|
globalEnv = Env{
|
2021-06-10 23:48:32 +00:00
|
|
|
BotToken: token,
|
|
|
|
ChannelID: discord.ChannelID(id),
|
|
|
|
VoiceChID: discord.ChannelID(vid),
|
|
|
|
ShardCount: shardCount,
|
2020-12-01 01:49:18 +00:00
|
|
|
}
|
|
|
|
}
|