chore: make the tests platform independent

Replace the sh call in plugin stderr capture tests with go native binary
for cross platform test compatibility.

Signed-off-by: Maksym Kondratenko <m.kondratenko.ua@gmail.com>
pull/32207/head
Maksym Kondratenko 4 months ago committed by Maksym Kondratenko
parent f25950f069
commit 8a0d22e59a

@ -85,8 +85,23 @@ func TestSubprocessPluginRuntime(t *testing.T) {
assert.Nil(t, output)
}
func TestHelperProcess(t *testing.T) {
if os.Getenv("GO_WANT_HELPER_PROCESS") != "1" {
return
}
fmt.Fprint(os.Stderr, "plugin error\n")
os.Exit(1)
}
func helperStderrCmd(t *testing.T) *exec.Cmd {
t.Helper()
cmd := exec.Command(os.Args[0], "-test.run=TestHelperProcess", "--")
cmd.Env = append(os.Environ(), "GO_WANT_HELPER_PROCESS=1")
return cmd
}
func TestExecuteCmdCapturesStderr(t *testing.T) {
cmd := exec.Command("sh", "-c", `echo "plugin error" >&2; exit 1`)
cmd := helperStderrCmd(t)
err := executeCmd(cmd, "test-plugin")
require.Error(t, err)
@ -99,7 +114,7 @@ func TestExecuteCmdCapturesStderr(t *testing.T) {
func TestExecuteCmdTeesStderr(t *testing.T) {
var existing bytes.Buffer
cmd := exec.Command("sh", "-c", `echo "plugin error" >&2; exit 1`)
cmd := helperStderrCmd(t)
cmd.Stderr = &existing
err := executeCmd(cmd, "test-plugin")

Loading…
Cancel
Save