Skip to content

Commit f7e56a5

Browse files
committed
Further tests.
1 parent db818cd commit f7e56a5

File tree

2 files changed

+34
-9
lines changed

2 files changed

+34
-9
lines changed

pipeline/build_golang.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ func (b *BuildPipelineGolang) ExecuteBuild(p *gaia.CreatePipeline) error {
5959
"-d",
6060
"./...",
6161
}
62-
env := os.Environ()
63-
env = append(env, "GOPATH="+goPath)
62+
63+
env := append(os.Environ(), "GOPATH="+goPath)
6464

6565
// Execute and wait until finish or timeout
6666
output, err := executeCmd(path, args, env, p.Pipeline.Repo.LocalDest)

pipeline/build_golang_test.go

+32-7
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ import (
1717
)
1818

1919
var killContext = false
20-
var mockedOutput string
21-
var mockedStatus = 0
20+
var killOnBuild = false
2221

2322
func fakeExecCommandContext(ctx context.Context, name string, args ...string) *exec.Cmd {
2423
if killContext {
@@ -37,16 +36,14 @@ func fakeExecCommandContext(ctx context.Context, name string, args ...string) *e
3736
envArgs = arg
3837
}
3938
os.Setenv("CMD_ARGS", envArgs)
40-
es := strconv.Itoa(mockedStatus)
41-
cmd.Env = []string{"GO_WANT_HELPER_PROCESS=1", "EXIT_STATUS=" + es}
4239
return cmd
4340
}
4441

4542
func TestExecCommandContextHelper(t *testing.T) {
4643
if os.Getenv("GO_WANT_HELPER_PROCESS") != "1" {
4744
return
4845
}
49-
fmt.Fprintln(os.Stdout, mockedOutput)
46+
fmt.Fprintf(os.Stdout, os.Getenv("STDOUT"))
5047
i, _ := strconv.Atoi(os.Getenv("EXIT_STATUS"))
5148
os.Exit(i)
5249
}
@@ -80,7 +77,9 @@ func TestPrepareEnvironmentInvalidPathForMkdir(t *testing.T) {
8077

8178
func TestExecuteBuild(t *testing.T) {
8279
execCommandContext = fakeExecCommandContext
83-
defer func() { execCommandContext = exec.CommandContext }()
80+
defer func() {
81+
execCommandContext = exec.CommandContext
82+
}()
8483
tmp := os.TempDir()
8584
gaia.Cfg = new(gaia.Config)
8685
gaia.Cfg.HomePath = tmp
@@ -100,7 +99,9 @@ func TestExecuteBuild(t *testing.T) {
10099
func TestExecuteBuildContextTimeout(t *testing.T) {
101100
execCommandContext = fakeExecCommandContext
102101
killContext = true
103-
defer func() { execCommandContext = exec.CommandContext }()
102+
defer func() {
103+
execCommandContext = exec.CommandContext
104+
}()
104105
defer func() { killContext = false }()
105106
tmp := os.TempDir()
106107
gaia.Cfg = new(gaia.Config)
@@ -122,6 +123,30 @@ func TestExecuteBuildContextTimeout(t *testing.T) {
122123
}
123124
}
124125

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+
125150
func TestCopyBinary(t *testing.T) {
126151
tmp := os.TempDir()
127152
gaia.Cfg = new(gaia.Config)

0 commit comments

Comments
 (0)