Skip to content

Commit b76a4c0

Browse files
committed
Split tests by type and improve boolean tests
1 parent b091ca7 commit b76a4c0

File tree

1 file changed

+50
-10
lines changed

1 file changed

+50
-10
lines changed

options_test.go

+50-10
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,67 @@ import (
88
"github.com/stretchr/testify/require"
99
)
1010

11-
// TestEnvOptionParsing tests that given environment variables of different types are handled as expected.
12-
func TestEnvOptionParsing(t *testing.T) {
11+
// TestStrEnvOptions tests that string env variables can be handled as expected.
12+
func TestStrEnvOptions(t *testing.T) {
1313
t.Setenv("SETUP_SCRIPT", "setup.sh")
14+
t.Setenv("INIT_COMMAND", "sleep infinity")
15+
16+
var o envbuilder.Options
17+
err := runCLI(&o)
18+
require.NoError(t, err)
19+
20+
require.Equal(t, o.SetupScript, "setup.sh")
21+
require.Equal(t, o.InitCommand, "sleep infinity")
22+
}
23+
24+
// TestIntEnvOptions tests that numeric env variables can be handled as expected.
25+
func TestIntEnvOptions(t *testing.T) {
26+
t.Setenv("CACHE_TTL_DAYS", "7")
27+
28+
var o envbuilder.Options
29+
err := runCLI(&o)
30+
require.NoError(t, err)
31+
32+
require.Equal(t, o.CacheTTLDays, 7)
33+
}
34+
35+
// TestMultipleStrEnvOptions tests that numeric env variables can be handled as expected.
36+
func TestMultipleStrEnvOptions(t *testing.T) {
1437
t.Setenv("CACHE_TTL_DAYS", "7")
15-
t.Setenv("IGNORE_PATHS", "/var,/tmp")
38+
39+
var o envbuilder.Options
40+
err := runCLI(&o)
41+
require.NoError(t, err)
42+
43+
require.Equal(t, o.CacheTTLDays, 7)
44+
}
45+
46+
// TestBoolEnvOptions tests that boolean env variables can be handled as expected.
47+
func TestBoolEnvOptions(t *testing.T) {
1648
t.Setenv("SKIP_REBUILD", "true")
1749
t.Setenv("GIT_CLONE_SINGLE_BRANCH", "")
50+
t.Setenv("EXIT_ON_BUILD_FAILURE", "false")
51+
t.Setenv("FORCE_SAFE", "TRUE")
52+
t.Setenv("INSECURE", "FALSE")
1853

1954
var o envbuilder.Options
55+
err := runCLI(&o)
56+
require.NoError(t, err)
57+
58+
require.True(t, o.SkipRebuild)
59+
require.False(t, o.GitCloneSingleBranch)
60+
require.False(t, o.ExitOnBuildFailure)
61+
require.True(t, o.ForceSafe)
62+
require.False(t, o.Insecure)
63+
}
64+
65+
func runCLI(o *envbuilder.Options) error {
2066
cmd := serpent.Command{
2167
Options: o.CLI(),
2268
Handler: func(inv *serpent.Invocation) error {
2369
return nil
2470
},
2571
}
2672
err := cmd.Invoke().WithOS().Run()
27-
require.NoError(t, err)
28-
29-
require.Equal(t, o.SetupScript, "setup.sh")
30-
require.Equal(t, o.CacheTTLDays, int64(7))
31-
require.Equal(t, o.IgnorePaths, []string{"/var", "/tmp"})
32-
require.True(t, o.SkipRebuild)
33-
require.False(t, o.GitCloneSingleBranch)
73+
return err
3474
}

0 commit comments

Comments
 (0)