From d530a9e9f9bd85ea18a688d879d0558cd56fb8bd Mon Sep 17 00:00:00 2001 From: Ophestra Umiker Date: Sun, 29 Sep 2024 14:40:01 +0900 Subject: helper: stub helper for tests Signed-off-by: Ophestra Umiker --- helper/export_test.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 helper/export_test.go (limited to 'helper/export_test.go') diff --git a/helper/export_test.go b/helper/export_test.go new file mode 100644 index 00000000..6bf18ce3 --- /dev/null +++ b/helper/export_test.go @@ -0,0 +1,18 @@ +package helper + +import ( + "os" + "os/exec" + "testing" +) + +// replace execCommand to have the resulting *exec.Cmd launch TestHelperChildStub +func ReplaceExecCommand(t *testing.T) { + t.Cleanup(func() { + execCommand = exec.Command + }) + + execCommand = func(name string, arg ...string) *exec.Cmd { + return exec.Command(os.Args[0], append([]string{"-test.run=TestHelperChildStub", "--", name}, arg...)...) + } +} -- cgit v1.3.1