@@ -17,8 +17,7 @@ import (
17
17
)
18
18
19
19
var killContext = false
20
- var mockedOutput string
21
- var mockedStatus = 0
20
+ var killOnBuild = false
22
21
23
22
func fakeExecCommandContext (ctx context.Context , name string , args ... string ) * exec.Cmd {
24
23
if killContext {
@@ -37,16 +36,14 @@ func fakeExecCommandContext(ctx context.Context, name string, args ...string) *e
37
36
envArgs = arg
38
37
}
39
38
os .Setenv ("CMD_ARGS" , envArgs )
40
- es := strconv .Itoa (mockedStatus )
41
- cmd .Env = []string {"GO_WANT_HELPER_PROCESS=1" , "EXIT_STATUS=" + es }
42
39
return cmd
43
40
}
44
41
45
42
func TestExecCommandContextHelper (t * testing.T ) {
46
43
if os .Getenv ("GO_WANT_HELPER_PROCESS" ) != "1" {
47
44
return
48
45
}
49
- fmt .Fprintln (os .Stdout , mockedOutput )
46
+ fmt .Fprintf (os .Stdout , os . Getenv ( "STDOUT" ) )
50
47
i , _ := strconv .Atoi (os .Getenv ("EXIT_STATUS" ))
51
48
os .Exit (i )
52
49
}
@@ -80,7 +77,9 @@ func TestPrepareEnvironmentInvalidPathForMkdir(t *testing.T) {
80
77
81
78
func TestExecuteBuild (t * testing.T ) {
82
79
execCommandContext = fakeExecCommandContext
83
- defer func () { execCommandContext = exec .CommandContext }()
80
+ defer func () {
81
+ execCommandContext = exec .CommandContext
82
+ }()
84
83
tmp := os .TempDir ()
85
84
gaia .Cfg = new (gaia.Config )
86
85
gaia .Cfg .HomePath = tmp
@@ -100,7 +99,9 @@ func TestExecuteBuild(t *testing.T) {
100
99
func TestExecuteBuildContextTimeout (t * testing.T ) {
101
100
execCommandContext = fakeExecCommandContext
102
101
killContext = true
103
- defer func () { execCommandContext = exec .CommandContext }()
102
+ defer func () {
103
+ execCommandContext = exec .CommandContext
104
+ }()
104
105
defer func () { killContext = false }()
105
106
tmp := os .TempDir ()
106
107
gaia .Cfg = new (gaia.Config )
@@ -122,6 +123,30 @@ func TestExecuteBuildContextTimeout(t *testing.T) {
122
123
}
123
124
}
124
125
126
+ func TestExecuteBuildBinaryNotFoundError (t * testing.T ) {
127
+ tmp := os .TempDir ()
128
+ gaia .Cfg = new (gaia.Config )
129
+ gaia .Cfg .HomePath = tmp
130
+ // Initialize shared logger
131
+ gaia .Cfg .Logger = hclog .New (& hclog.LoggerOptions {
132
+ Level : hclog .Trace ,
133
+ Output : hclog .DefaultOutput ,
134
+ Name : "Gaia" ,
135
+ })
136
+ currentPath := os .Getenv ("PATH" )
137
+ defer func () { os .Setenv ("PATH" , currentPath ) }()
138
+ os .Setenv ("PATH" , "" )
139
+ b := new (BuildPipelineGolang )
140
+ p := new (gaia.CreatePipeline )
141
+ err := b .ExecuteBuild (p )
142
+ if err == nil {
143
+ t .Fatal ("no error found while expecting error." )
144
+ }
145
+ if err .Error () != "exec: \" go\" : executable file not found in $PATH" {
146
+ t .Fatal ("the error wasn't what we expected. instead it was: " , err )
147
+ }
148
+ }
149
+
125
150
func TestCopyBinary (t * testing.T ) {
126
151
tmp := os .TempDir ()
127
152
gaia .Cfg = new (gaia.Config )
0 commit comments