1
0
mirror of https://github.com/Jguer/yay.git synced 2026-04-10 08:11:14 +02:00
yay/pkg/settings/exe/runner_test.go
Jo 3b79933638
test: harden coverage and make tests parallel-safe (#2797)
* Test coverage hardening and parallel-safe refactors

Add focused test coverage for under-tested operational paths, edge branches,
and make key table-driven suites parallel-safe. Also fixed flaky installer
test execution under repeated/parallel runs.

* chore: fix goimports ordering for golangci-lint

* Test(download): expand integration coverage for download paths

Add integration scenarios for force/pull repo updates, repo-only and skip semantics,
and direct AUR download/scanner coverage used by getpkgbuild and package preparation.

* Test(exe): relax systemd-run path assertion

Fix flaky TestBuildGitCmd by accepting an absolute systemd-run path while still
asserting the expected binary is used.

* Test(text): avoid race in color tests

Remove parallel execution from TestColorHash so global UseColor writes do not
overlap with color consumers in parallel tests and trigger race detector
failures.

* fix potential race conditions
2026-03-25 00:51:34 +01:00

34 lines
746 B
Go

//go:build !integration
// +build !integration
package exe
import (
"context"
"io"
"os/exec"
"strings"
"testing"
"github.com/stretchr/testify/require"
"github.com/Jguer/yay/v12/pkg/text"
)
func TestOSRunnerCapture(t *testing.T) {
t.Parallel()
runner := NewOSRunner(text.NewLogger(io.Discard, io.Discard, strings.NewReader(""), false, "test"))
cmd := exec.CommandContext(context.Background(), "sh", "-c", "printf 'ok'; printf 'err' >&2")
out, errOut, err := runner.Capture(cmd)
require.NoError(t, err)
require.Equal(t, "ok", out)
require.Empty(t, errOut)
cmdFail := exec.CommandContext(context.Background(), "sh", "-c", "exit 1")
_, stderr, err := runner.Capture(cmdFail)
require.Error(t, err)
require.Empty(t, stderr)
}