github.com/stevenmatthewt/agent@v3.5.4+incompatible/bootstrap/integration/command_integration_test.go (about) 1 package integration 2 3 import ( 4 "testing" 5 6 "github.com/buildkite/bintest" 7 ) 8 9 func TestPreExitHooksRunsAfterCommandFails(t *testing.T) { 10 tester, err := NewBootstrapTester() 11 if err != nil { 12 t.Fatal(err) 13 } 14 defer tester.Close() 15 16 // Mock out the meta-data calls to the agent after checkout 17 agent := tester.MustMock(t, "buildkite-agent") 18 agent. 19 Expect("meta-data", "exists", "buildkite:git:commit"). 20 AndExitWith(0) 21 22 preExitFunc := func(c *bintest.Call) { 23 cmdExitStatus := c.GetEnv(`BUILDKITE_COMMAND_EXIT_STATUS`) 24 if cmdExitStatus != "1" { 25 t.Errorf("Expected an exit status of 1, got %v", cmdExitStatus) 26 } 27 c.Exit(0) 28 } 29 30 tester.ExpectGlobalHook("pre-exit").Once().AndCallFunc(preExitFunc) 31 tester.ExpectLocalHook("pre-exit").Once().AndCallFunc(preExitFunc) 32 33 if err = tester.Run(t, "BUILDKITE_COMMAND=false"); err == nil { 34 t.Fatal("Expected the bootstrap to fail") 35 } 36 37 tester.CheckMocks(t) 38 }