Skip to content

Commit

Permalink
test: Add test to verify castsponsorskip envs work
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed Aug 28, 2023
1 parent cbf5ce6 commit b19f79f
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions cmd/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"math/rand"
"os"
"strconv"
"testing"
"time"

Expand Down Expand Up @@ -114,3 +115,43 @@ func TestEnvs(t *testing.T) {
assert.Equal(t, "AIzaSyDaGmWKa4JsXZ-HjGw7ISLn_3namBGewQe", config.Default.YouTubeAPIKey)
assert.Equal(t, true, config.Default.MuteAds)
}

func TestSBCEnvs(t *testing.T) {
defer func() {
viper.Reset()
config.Default = &config.Config{}
}()

discoverInterval := randDuration()
playingInterval := randDuration()

defer func() {
_ = os.Unsetenv("SBCSCANINTERVAL")
_ = os.Unsetenv("SBCPOLLINTERVAL")
_ = os.Unsetenv("SBCCATEGORIES")
_ = os.Unsetenv("SBCYOUTUBEAPIKEY")
}()
_ = os.Setenv("SBCSCANINTERVAL", strconv.Itoa(int(discoverInterval.Seconds())))
_ = os.Setenv("SBCPOLLINTERVAL", strconv.Itoa(int(playingInterval.Seconds())))
_ = os.Setenv("SBCCATEGORIES", "a b c")
_ = os.Setenv("SBCYOUTUBEAPIKEY", "AIzaSyDaGmWKa4JsXZ-HjGw7ISLn_3namBGewQe")

var cmd *cobra.Command
if !assert.NotPanics(t, func() {
cmd = NewCommand("", "")
}) {
return
}
cmd.RunE = func(cmd *cobra.Command, args []string) error {
return nil
}

if err := cmd.Execute(); !assert.NoError(t, err) {
return
}

assert.Equal(t, discoverInterval, config.Default.DiscoverInterval)
assert.Equal(t, playingInterval, config.Default.PlayingInterval)
assert.Equal(t, []string{"a", "b", "c"}, config.Default.Categories)
assert.Equal(t, "AIzaSyDaGmWKa4JsXZ-HjGw7ISLn_3namBGewQe", config.Default.YouTubeAPIKey)
}

0 comments on commit b19f79f

Please sign in to comment.