-
Notifications
You must be signed in to change notification settings - Fork 339
Expand file tree
/
Copy pathcommand_integration_test.go
More file actions
76 lines (60 loc) · 1.88 KB
/
command_integration_test.go
File metadata and controls
76 lines (60 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package integration
import (
"runtime"
"testing"
"github.com/buildkite/agent/v3/internal/job"
"github.com/buildkite/bintest/v3"
)
func TestMultilineCommandRunUnderBatch(t *testing.T) {
t.Parallel()
if runtime.GOOS != "windows" {
t.Skip("batch test only applies to Windows")
}
tester, err := NewExecutorTester(mainCtx)
if err != nil {
t.Fatalf("NewExecutorTester() error = %v", err)
}
defer tester.Close()
setup := tester.MustMock(t, "Setup.cmd")
build := tester.MustMock(t, "BuildProject.cmd")
setup.Expect().Once()
build.Expect().Once().AndCallFunc(func(c *bintest.Call) {
if got, want := c.GetEnv("LLAMAS"), "COOL"; got != want {
t.Errorf("c.GetEnv(LLAMAS) = %q, want %q", got, want)
c.Exit(1)
} else {
c.Exit(0)
}
})
env := []string{
"BUILDKITE_COMMAND=Setup.cmd\nset LLAMAS=COOL\nBuildProject.cmd",
`BUILDKITE_SHELL=C:\Windows\System32\CMD.exe /S /C`,
`BUILDKITE_HOOKS_SHELL=C:\Program Files\PowerShell\7\pwsh.exe`,
}
tester.RunAndCheck(t, env...)
}
func TestPreExitHooksRunsAfterCommandFails(t *testing.T) {
t.Parallel()
tester, err := NewExecutorTester(mainCtx)
if err != nil {
t.Fatalf("NewExecutorTester() error = %v", err)
}
defer tester.Close()
// Mock out the meta-data calls to the agent after checkout
agent := tester.MockAgent(t)
agent.
Expect("meta-data", "exists", job.CommitMetadataKey).
AndExitWith(0)
preExitFunc := func(c *bintest.Call) {
if got, want := c.GetEnv("BUILDKITE_COMMAND_EXIT_STATUS"), "1"; got != want {
t.Errorf("c.GetEnv(BUILDKITE_COMMAND_EXIT_STATUS) = %q, want %q", got, want)
}
c.Exit(0)
}
tester.ExpectGlobalHook("pre-exit").Once().AndCallFunc(preExitFunc)
tester.ExpectLocalHook("pre-exit").Once().AndCallFunc(preExitFunc)
if err := tester.Run(t, "BUILDKITE_COMMAND=false"); err == nil {
t.Fatalf("tester.Run(t, BUILDKITE_COMMAND=false) = %v, want non-nil error", err)
}
tester.CheckMocks(t)
}