| 1 | package checks |
| 2 | |
| 3 | import ( |
| 4 | "amadan.net/oficina/equipo/internal/runner/provider" |
| 5 | "context" |
| 6 | "errors" |
| 7 | "slices" |
| 8 | "strings" |
| 9 | "testing" |
| 10 | ) |
| 11 | |
| 12 | func TestSharedBaselineFixtureIsolation(t *testing.T) { |
| 13 | first := newFixture(t) |
| 14 | original := slices.Clone(first.d.Baseline.Names) |
| 15 | first.d.Baseline.Names[0].Name = "changed" |
| 16 | put(t, first.base, "extra_test.go", "package fixture\nimport \"testing\"\nfunc TestExtra(t *testing.T){}\n") |
| 17 | second := newFixture(t) |
| 18 | if !slices.Equal(second.d.Baseline.Names, original) { |
| 19 | t.Fatal("fixtures share mutable baseline names") |
| 20 | } |
| 21 | fresh, err := second.e.CaptureBaseline(context.Background(), second.d) |
| 22 | must(t, err) |
| 23 | if fresh.Hash != second.d.Baseline.Hash || !slices.Equal(fresh.Names, original) { |
| 24 | t.Fatal("shared baseline differs from fresh isolated capture") |
| 25 | } |
| 26 | first.d.Baseline.Names = slices.Clone(original) |
| 27 | changed, err := first.e.CaptureBaseline(context.Background(), first.d) |
| 28 | must(t, err) |
| 29 | if changed.Hash == fresh.Hash || !slices.Contains(changed.Names, TestIdentity{Package: "fixture", Name: "TestExtra"}) { |
| 30 | t.Fatal("changed fixture bypassed baseline capture") |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | func TestCheckFailureDiagnostic(t *testing.T) { |
| 35 | f := newFixture(t) |
| 36 | _, _, _, err := f.e.run(context.Background(), Command{Argv: []string{"/bin/sh", "-c", "echo namespace-cause >&2; exit 7"}, Dir: ".", Parser: "go-test-json", TimeoutSeconds: 10}, f.base, "") |
| 37 | if !errors.Is(err, provider.ErrContract) || !strings.Contains(err.Error(), "namespace-cause") || !strings.Contains(err.Error(), "exit 7") { |
| 38 | t.Fatalf("missing check diagnostic: %v", err) |
| 39 | } |
| 40 | } |
| 41 | |