Enable race testing in validation
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -93,6 +94,35 @@ func TestPublishPushesOnlyTheCapturedAnnotatedTag(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckUsesSelectedRaceSuiteBeforeAdditionalChecks(t *testing.T) {
|
||||
requireRacePrerequisites(t)
|
||||
repo := newPublishFixture(t)
|
||||
raceMarker := filepath.Join(t.TempDir(), "race-enabled")
|
||||
t.Setenv("RELEASEKIT_RACE_MARKER", raceMarker)
|
||||
checks := 0
|
||||
_, err := releasekit.Check(context.Background(), releasekit.ReleaseRequest{
|
||||
RepositoryDir: repo.work,
|
||||
Product: "Sample App",
|
||||
Version: "v1.2.3",
|
||||
Validation: releasekit.ValidationSpec{
|
||||
Go: releasekit.GoValidationSpec{Race: true},
|
||||
},
|
||||
AdditionalChecks: func(context.Context, releasekit.Candidate) error {
|
||||
checks++
|
||||
return nil
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("Check() error = %v", err)
|
||||
}
|
||||
if checks != 1 {
|
||||
t.Fatalf("additional checks ran %d times, want once", checks)
|
||||
}
|
||||
if _, err := os.Stat(raceMarker); err != nil {
|
||||
t.Fatalf("race-enabled fixture did not run: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPublishFailedStandardSuiteSkipsAdditionalChecksAndTagCreation(t *testing.T) {
|
||||
repo := newPublishFixture(t)
|
||||
t.Setenv("RELEASEKIT_FAIL_FIXTURE_SUITE", "1")
|
||||
@@ -133,6 +163,27 @@ func TestPublishFailedStandardSuiteSkipsAdditionalChecksAndTagCreation(t *testin
|
||||
}
|
||||
}
|
||||
|
||||
func requireRacePrerequisites(t *testing.T) {
|
||||
t.Helper()
|
||||
supported := runtime.GOOS == "darwin" && (runtime.GOARCH == "amd64" || runtime.GOARCH == "arm64") ||
|
||||
(runtime.GOOS == "freebsd" || runtime.GOOS == "linux") && (runtime.GOARCH == "amd64" || runtime.GOARCH == "arm64" || runtime.GOARCH == "ppc64le") ||
|
||||
runtime.GOOS == "windows" && runtime.GOARCH == "amd64"
|
||||
if !supported {
|
||||
t.Skipf("Go race detector is not supported on %s/%s", runtime.GOOS, runtime.GOARCH)
|
||||
}
|
||||
cgo, err := exec.Command("go", "env", "CGO_ENABLED").Output()
|
||||
if err != nil || strings.TrimSpace(string(cgo)) != "1" {
|
||||
t.Skip("Go race detector requires CGO_ENABLED=1")
|
||||
}
|
||||
cc, err := exec.Command("go", "env", "CC").Output()
|
||||
if err != nil || len(strings.Fields(string(cc))) == 0 {
|
||||
t.Skip("Go race detector requires a C compiler")
|
||||
}
|
||||
if _, err := exec.LookPath(strings.Fields(string(cc))[0]); err != nil {
|
||||
t.Skip("Go race detector C compiler is unavailable")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckReturnsPublicValidationError(t *testing.T) {
|
||||
repo := newPublishFixture(t)
|
||||
t.Setenv("RELEASEKIT_FAIL_FIXTURE_SUITE", "1")
|
||||
@@ -627,6 +678,25 @@ func TestFixture(t *testing.T) {
|
||||
t.Fatal("fixture standard suite failure")
|
||||
}
|
||||
}
|
||||
`)
|
||||
writeFile(t, work, "race_fixture_test.go", `//go:build race
|
||||
|
||||
package fixture
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestRaceBuildSelection(t *testing.T) {
|
||||
marker := os.Getenv("RELEASEKIT_RACE_MARKER")
|
||||
if marker == "" {
|
||||
return
|
||||
}
|
||||
if err := os.WriteFile(marker, []byte("race enabled"), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
`)
|
||||
writeFile(t, work, "docs/releases/v1.2.3.md", releaseNote)
|
||||
writeFile(t, work, "source.txt", "candidate")
|
||||
|
||||
Reference in New Issue
Block a user