Skip to content

Commit 73696ae

Browse files
committed
test: add test for options env
1 parent 6218976 commit 73696ae

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

options_test.go

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package envbuilder_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/coder/envbuilder"
7+
"github.com/coder/serpent"
8+
"github.com/stretchr/testify/require"
9+
)
10+
11+
type testEnvCase struct {
12+
Env string
13+
EnvValue string
14+
Expected interface{}
15+
Actual func() interface{}
16+
}
17+
18+
func TestEnvOptions(t *testing.T) {
19+
t.Setenv("SETUP_SCRIPT", "setup.sh")
20+
t.Setenv("CACHE_TTL_DAYS", "7")
21+
t.Setenv("IGNORE_PATHS", "/var,/tmp")
22+
t.Setenv("SKIP_REBUILD", "true")
23+
t.Setenv("GIT_CLONE_SINGLE_BRANCH", "")
24+
25+
var o = envbuilder.Options{}
26+
cmd := serpent.Command{
27+
Options: o.CLI(),
28+
Handler: func(inv *serpent.Invocation) error {
29+
return nil
30+
},
31+
}
32+
err := cmd.Invoke().WithOS().Run()
33+
require.NoError(t, err)
34+
35+
require.Equal(t, o.SetupScript, "setup.sh")
36+
require.Equal(t, o.CacheTTLDays, int64(7))
37+
require.Equal(t, o.IgnorePaths, []string{"/var", "/tmp"})
38+
require.True(t, o.SkipRebuild)
39+
require.False(t, o.GitCloneSingleBranch)
40+
}

0 commit comments

Comments
 (0)