Skip to content

Commit b19f79f

Browse files
committed
test: Add test to verify castsponsorskip envs work
1 parent cbf5ce6 commit b19f79f

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

cmd/cmd_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cmd
33
import (
44
"math/rand"
55
"os"
6+
"strconv"
67
"testing"
78
"time"
89

@@ -114,3 +115,43 @@ func TestEnvs(t *testing.T) {
114115
assert.Equal(t, "AIzaSyDaGmWKa4JsXZ-HjGw7ISLn_3namBGewQe", config.Default.YouTubeAPIKey)
115116
assert.Equal(t, true, config.Default.MuteAds)
116117
}
118+
119+
func TestSBCEnvs(t *testing.T) {
120+
defer func() {
121+
viper.Reset()
122+
config.Default = &config.Config{}
123+
}()
124+
125+
discoverInterval := randDuration()
126+
playingInterval := randDuration()
127+
128+
defer func() {
129+
_ = os.Unsetenv("SBCSCANINTERVAL")
130+
_ = os.Unsetenv("SBCPOLLINTERVAL")
131+
_ = os.Unsetenv("SBCCATEGORIES")
132+
_ = os.Unsetenv("SBCYOUTUBEAPIKEY")
133+
}()
134+
_ = os.Setenv("SBCSCANINTERVAL", strconv.Itoa(int(discoverInterval.Seconds())))
135+
_ = os.Setenv("SBCPOLLINTERVAL", strconv.Itoa(int(playingInterval.Seconds())))
136+
_ = os.Setenv("SBCCATEGORIES", "a b c")
137+
_ = os.Setenv("SBCYOUTUBEAPIKEY", "AIzaSyDaGmWKa4JsXZ-HjGw7ISLn_3namBGewQe")
138+
139+
var cmd *cobra.Command
140+
if !assert.NotPanics(t, func() {
141+
cmd = NewCommand("", "")
142+
}) {
143+
return
144+
}
145+
cmd.RunE = func(cmd *cobra.Command, args []string) error {
146+
return nil
147+
}
148+
149+
if err := cmd.Execute(); !assert.NoError(t, err) {
150+
return
151+
}
152+
153+
assert.Equal(t, discoverInterval, config.Default.DiscoverInterval)
154+
assert.Equal(t, playingInterval, config.Default.PlayingInterval)
155+
assert.Equal(t, []string{"a", "b", "c"}, config.Default.Categories)
156+
assert.Equal(t, "AIzaSyDaGmWKa4JsXZ-HjGw7ISLn_3namBGewQe", config.Default.YouTubeAPIKey)
157+
}

0 commit comments

Comments
 (0)