Improve structural test diagnostics

This commit is contained in:
2026-09-05 18:08:49 +00:00
parent 85663f5bc9
commit 204caf9d24
10 changed files with 64 additions and 36 deletions

View File

@@ -2,11 +2,13 @@ package stage
import (
"path/filepath"
"reflect"
"slices"
"strings"
"testing"
"time"
"github.com/google/go-cmp/cmp"
"gitea.maximumdirect.net/eric/narratio/internal/artifactmodel"
"gitea.maximumdirect.net/eric/narratio/internal/artifactpolicy"
"gitea.maximumdirect.net/eric/narratio/internal/config"
@@ -151,7 +153,7 @@ func TestPlanAnalyzeWorkSelectionAndDependencyClosure(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(plan.ExplicitTargets, tt.wantTargets) {
if !slices.Equal(plan.ExplicitTargets, tt.wantTargets) {
t.Fatalf("targets = %#v, want %#v", plan.ExplicitTargets, tt.wantTargets)
}
assertAnalyzePlanKeys(t, "execution", plan.ExecutionOrder, tt.wantExecution)
@@ -163,7 +165,7 @@ func TestPlanAnalyzeWorkSelectionAndDependencyClosure(t *testing.T) {
forced = append(forced, item.Key)
}
}
if !(len(forced) == 0 && len(tt.wantForced) == 0) && !reflect.DeepEqual(forced, tt.wantForced) {
if !(len(forced) == 0 && len(tt.wantForced) == 0) && !slices.Equal(forced, tt.wantForced) {
t.Fatalf("forced = %#v, want %#v", forced, tt.wantForced)
}
})
@@ -263,8 +265,16 @@ func TestPlanAnalyzeWorkStartingRecordsPreserveOnlyValidConfiguredAuthority(t *t
}
assertAnalyzePlanKeys(t, "invalidated", plan.Invalidated, []string{"invalid_unselected"})
assertAnalyzePlanKeys(t, "removed", plan.Removed, []string{"removed"})
if !reflect.DeepEqual(before["unrelated"], *stored["unrelated"]) || !reflect.DeepEqual(before["invalid_unselected"], *stored["invalid_unselected"]) {
t.Fatal("planning mutated stored records")
gotUnchanged := map[string]manifest.AnalyzeArtifactRecord{
"unrelated": *stored["unrelated"],
"invalid_unselected": *stored["invalid_unselected"],
}
wantUnchanged := map[string]manifest.AnalyzeArtifactRecord{
"unrelated": before["unrelated"],
"invalid_unselected": before["invalid_unselected"],
}
if diff := cmp.Diff(wantUnchanged, gotUnchanged); diff != "" {
t.Fatalf("planning mutated stored records (-before +after):\n%s", diff)
}
}
@@ -306,7 +316,7 @@ func TestPlanAnalyzeWorkOrderIsDeterministicAcrossMapInsertion(t *testing.T) {
t.Fatal(err)
}
got := analyzePlanKeys(plan.ExecutionOrder)
if !reflect.DeepEqual(got, want) {
if !slices.Equal(got, want) {
t.Fatalf("attempt %d order = %#v, want %#v", attempt, got, want)
}
}
@@ -350,7 +360,7 @@ func assertAnalyzePlanKeys(t *testing.T, label string, items []analyzePlanItem,
if len(got) == 0 && len(want) == 0 {
return
}
if !reflect.DeepEqual(got, want) {
if !slices.Equal(got, want) {
t.Fatalf("%s = %#v, want %#v", label, got, want)
}
}

View File

@@ -2,9 +2,10 @@ package stage
import (
"path/filepath"
"reflect"
"testing"
"github.com/google/go-cmp/cmp"
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
"gitea.maximumdirect.net/eric/narratio/internal/config"
"gitea.maximumdirect.net/eric/narratio/internal/manifest"
@@ -164,8 +165,11 @@ func TestReconcileAnalyzeArtifactsIsReadOnly(t *testing.T) {
if _, err := reconcileAnalyzeArtifacts(env.Config.Pipeline.Scriptorium, newAnalyzeIdentityExecution(t, env, m)); err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(before, m.Stages["analyze"].AnalyzeArtifacts) || !m.UpdatedAt.Equal(beforeUpdatedAt) {
t.Fatal("reconciliation mutated manifest state")
if diff := cmp.Diff(before, m.Stages["analyze"].AnalyzeArtifacts); diff != "" {
t.Fatalf("reconciliation mutated artifact state (-before +after):\n%s", diff)
}
if !m.UpdatedAt.Equal(beforeUpdatedAt) {
t.Fatalf("reconciliation changed manifest update time: before=%s after=%s", beforeUpdatedAt, m.UpdatedAt)
}
}

View File

@@ -1,11 +1,12 @@
package stage
import (
"reflect"
"strings"
"testing"
"time"
"github.com/google/go-cmp/cmp"
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
)
@@ -56,8 +57,8 @@ func TestBuildPublishOutputPlanModelsEveryOutcome(t *testing.T) {
t.Fatalf("outcomes[%d] = %#v, want source %q status %q", index, plan.Outcomes[index], wantSources[index], wantStatuses[index])
}
}
if !reflect.DeepEqual(plan.Outcomes[1].Declaration, carried) {
t.Fatalf("carried declaration = %#v, want exact %#v", plan.Outcomes[1].Declaration, carried)
if diff := cmp.Diff(carried, plan.Outcomes[1].Declaration); diff != "" {
t.Fatalf("carried declaration differs (-want +got):\n%s", diff)
}
if plan.Outcomes[1].Destination != "artifacts/beta-old.md" || plan.Outcomes[1].OriginRun != "20260512T010203Z-11223344" {
t.Fatalf("carried outcome = %#v", plan.Outcomes[1])