github.com/bazelbuild/bazel-watcher@v0.25.2/internal/e2e/lifecycle_hooks/lifecycle_hooks_test.go (about) 1 package lifecycle_hooks 2 3 import ( 4 "testing" 5 6 "github.com/bazelbuild/bazel-watcher/internal/e2e" 7 "github.com/bazelbuild/rules_go/go/tools/bazel_testing" 8 ) 9 10 const mainFiles = ` 11 -- BUILD.bazel -- 12 sh_binary( 13 name = "test", 14 srcs = ["test.sh"], 15 ) 16 sh_binary( 17 name = "failure", 18 srcs = ["failure.sh"], 19 ) 20 -- test.sh -- 21 printf "action" 22 ` 23 24 func TestMain(m *testing.M) { 25 bazel_testing.TestMain(m, bazel_testing.Args{ 26 Main: mainFiles, 27 }) 28 } 29 30 func TestLifecycleHooks(t *testing.T) { 31 ibazel := e2e.SetUp(t) 32 defer ibazel.Kill() 33 34 ibazel.RunWithAdditionalArgs("//:test", []string{ 35 "-run_command_before=echo hi-before", 36 "-run_command_after=echo hi-after", 37 "-run_command_after_success=echo hi-after-success", 38 "-run_command_after_error=echo hi-after-error", 39 }) 40 ibazel.ExpectOutput("hi-before") 41 ibazel.ExpectOutput("hi-after") 42 ibazel.ExpectOutput("hi-after-success") 43 } 44 45 func TestLifecycleHooksFailure(t *testing.T) { 46 ibazel := e2e.SetUp(t) 47 defer ibazel.Kill() 48 49 ibazel.RunUnverifiedWithAdditionalArgs("//:failure", []string{ 50 "-run_command_before=echo hi-before", 51 "-run_command_after=echo hi-after", 52 "-run_command_after_success=echo hi-after-success", 53 "-run_command_after_error=echo hi-after-error", 54 }) 55 ibazel.ExpectOutput("hi-before") 56 ibazel.ExpectOutput("hi-after") 57 ibazel.ExpectOutput("hi-after-error") 58 }