2020-12-01 01:49:18 +00:00
|
|
|
// +build !uintonly
|
|
|
|
|
|
|
|
package testenv
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"sync"
|
|
|
|
"testing"
|
2021-01-01 07:48:29 +00:00
|
|
|
"time"
|
2020-12-01 01:49:18 +00:00
|
|
|
|
|
|
|
"github.com/diamondburned/arikawa/v2/discord"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
2021-01-01 07:48:29 +00:00
|
|
|
const PerseveranceTime = 50 * time.Minute
|
|
|
|
|
2020-12-01 01:49:18 +00:00
|
|
|
type Env struct {
|
|
|
|
BotToken string
|
|
|
|
ChannelID discord.ChannelID
|
|
|
|
VoiceChID discord.ChannelID
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
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
|
|
|
}
|
|
|
|
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() {
|
|
|
|
var token = os.Getenv("BOT_TOKEN")
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
var cid = os.Getenv("CHANNEL_ID")
|
|
|
|
if cid == "" {
|
2020-12-12 01:58:52 +00:00
|
|
|
globalErr = errors.New("missing $CHANNEL_ID")
|
2020-12-01 01:49:18 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
id, err := discord.ParseSnowflake(cid)
|
|
|
|
if err != nil {
|
2020-12-12 01:58:52 +00:00
|
|
|
globalErr = errors.Wrap(err, "invalid $CHANNEL_ID")
|
2020-12-01 01:49:18 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var sid = os.Getenv("VOICE_ID")
|
|
|
|
if sid == "" {
|
2020-12-12 01:58:52 +00:00
|
|
|
globalErr = errors.New("missing $VOICE_ID")
|
2020-12-01 01:49:18 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
vid, err := discord.ParseSnowflake(sid)
|
|
|
|
if err != nil {
|
2020-12-12 01:58:52 +00:00
|
|
|
globalErr = errors.Wrap(err, "invalid $VOICE_ID")
|
2020-12-01 01:49:18 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-12-12 01:58:52 +00:00
|
|
|
globalEnv = Env{
|
2020-12-01 01:49:18 +00:00
|
|
|
BotToken: token,
|
|
|
|
ChannelID: discord.ChannelID(id),
|
|
|
|
VoiceChID: discord.ChannelID(vid),
|
|
|
|
}
|
|
|
|
}
|