Files
Gogs/internal/testutil/exec_test.go
ᴊᴏᴇ ᴄʜᴇɴ 59e9fa191b chore: remove all MIT license file headers (#8083)
Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
2026-01-08 19:32:15 -05:00

52 lines
881 B
Go

package testutil
import (
"errors"
"fmt"
"os"
"testing"
"github.com/stretchr/testify/assert"
)
func TestExecHelper(_ *testing.T) {
if !WantHelperProcess() {
return
}
if os.Getenv("PASS") != "1" {
fmt.Fprintln(os.Stdout, "tests failed")
os.Exit(1)
}
fmt.Fprintln(os.Stdout, "tests succeed")
}
func TestExec(t *testing.T) {
tests := []struct {
helper string
env string
expOut string
expErr error
}{
{
helper: "NoTestsToRun",
expErr: errors.New("no tests to run"),
}, {
helper: "TestExecHelper",
expErr: errors.New("exit status 1 - tests failed\n"),
}, {
helper: "TestExecHelper",
env: "PASS=1",
expOut: "tests succeed",
},
}
for _, test := range tests {
t.Run("", func(t *testing.T) {
out, err := Exec(test.helper, test.env)
assert.Equal(t, test.expErr, err)
assert.Equal(t, test.expOut, out)
})
}
}