@@ -8,27 +8,67 @@ import (
8
8
"github.com/stretchr/testify/require"
9
9
)
10
10
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 ) {
13
13
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 ) {
14
37
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 ) {
16
48
t .Setenv ("SKIP_REBUILD" , "true" )
17
49
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" )
18
53
19
54
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 {
20
66
cmd := serpent.Command {
21
67
Options : o .CLI (),
22
68
Handler : func (inv * serpent.Invocation ) error {
23
69
return nil
24
70
},
25
71
}
26
72
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
34
74
}
0 commit comments