mirror of
https://github.com/anchore/syft.git
synced 2026-08-19 16:48:27 +02:00
with a cold fixture cache the integration suite builds and saves 18 docker images across 36 sequential tests, which walks past `go test`'s default 10m timeout and takes the fixture cache rebuild down with it. that suite now runs `go test` directly with `-timeout=30m` (gotest.Tasks() has no timeout option), plus `-count=1` since the built fixtures are the side effect we're actually after and a test cache hit would skip producing them. also adds `RACE` as one switch for the race detector across every suite: - `RACE=false make test` drops `-race` from unit + integration and skips the race smoke, worth doing on a cache rebuild where the wall clock is all docker builds anyway - `RACE=true` forces it on locally - unset behaves as before: on in CI, off locally and on windows Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/anchore/go-make/config"
|
|
"github.com/anchore/go-make/tasks/gotest"
|
|
)
|
|
|
|
func TestRaceEnabled(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
env string // "" means RACE is unset
|
|
ci bool
|
|
want bool
|
|
}{
|
|
{name: "default in CI", ci: true, want: true},
|
|
{name: "default locally", ci: false, want: false},
|
|
{name: "explicitly off in CI", env: "false", ci: true, want: false},
|
|
{name: "explicitly on locally", env: "true", ci: false, want: true},
|
|
{name: "unparseable falls back to default", env: "yes-please", ci: true, want: true},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if tt.env != "" {
|
|
t.Setenv("RACE", tt.env)
|
|
}
|
|
orig := config.CI
|
|
config.CI = tt.ci
|
|
t.Cleanup(func() { config.CI = orig })
|
|
|
|
if got := raceEnabled(); got != tt.want {
|
|
t.Errorf("raceEnabled() = %v, want %v", got, tt.want)
|
|
}
|
|
|
|
// the gotest suites get the same answer through the functional option
|
|
var cfg gotest.Config
|
|
race()(&cfg)
|
|
if cfg.Race != tt.want {
|
|
t.Errorf("race() set Race = %v, want %v", cfg.Race, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|