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 weeks ago
parent 849730659e
commit cb8aa471be
No known key found for this signature in database
GPG Key ID: 819E17D2E58F89D8

@ -87,8 +87,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)
@ -101,7 +116,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