Remove brittle and duplicate test assertions

This commit is contained in:
2026-12-02 21:10:04 +00:00
parent 17f930b8d5
commit d3b4f25f71
5 changed files with 42 additions and 42 deletions

View File

@@ -2,7 +2,7 @@ package artifactmodel
import (
"encoding/json"
"strings"
"reflect"
"testing"
)
@@ -29,16 +29,27 @@ func TestArtifactMetadataJSON(t *testing.T) {
if err != nil {
t.Fatalf("Marshal() complete metadata error = %v", err)
}
wantComplete := `{"contract":{"media_type":"application/json","schema_id":"notarius.dnd.npc_registry","schema_version":"v1","module_key":"dnd/npc-registry"},"external_provenance":{"system":"notarius","run_id":"run-123","pipeline_id":"dnd-session","artifact_id":"npc-registry"}}`
if string(complete) != wantComplete {
t.Fatalf("complete metadata JSON = %s, want %s", complete, wantComplete)
var got map[string]any
if err := json.Unmarshal(complete, &got); err != nil {
t.Fatal(err)
}
want := map[string]any{
"contract": map[string]any{"media_type": "application/json", "schema_id": "notarius.dnd.npc_registry", "schema_version": "v1", "module_key": "dnd/npc-registry"},
"external_provenance": map[string]any{"system": "notarius", "run_id": "run-123", "pipeline_id": "dnd-session", "artifact_id": "npc-registry"},
}
if !reflect.DeepEqual(got, want) {
t.Fatalf("complete metadata = %#v, want %#v", got, want)
}
omitted, err := json.Marshal(envelope{})
if err != nil {
t.Fatalf("Marshal() omitted metadata error = %v", err)
}
if string(omitted) != `{}` {
got = nil
if err := json.Unmarshal(omitted, &got); err != nil {
t.Fatal(err)
}
if len(got) != 0 {
t.Fatalf("omitted metadata JSON = %s, want {}", omitted)
}
@@ -50,7 +61,12 @@ func TestArtifactMetadataJSON(t *testing.T) {
if err != nil {
t.Fatalf("Marshal() contract without module key error = %v", err)
}
if strings.Contains(string(withoutModule), "module_key") {
t.Fatalf("contract JSON unexpectedly contains omitted module_key: %s", withoutModule)
got = nil
if err := json.Unmarshal(withoutModule, &got); err != nil {
t.Fatal(err)
}
want = map[string]any{"contract": map[string]any{"media_type": "application/json", "schema_id": "notarius.dnd.npc_registry", "schema_version": "v1"}}
if !reflect.DeepEqual(got, want) {
t.Fatalf("metadata without module = %#v, want %#v", got, want)
}
}