//go:build integration package main import ( "encoding/json" "strings" "testing" "git.novox.be/novox/mesh-sdk/go/catalogue" ) // Registration publishes the newest trunk's list of predefined keys. It judges no manifest against it (ADR 0578 ยง3): the // indexer's judge does, with the list it keeps, and a fallback to a key not on it, or of another type, is refused there // (mesh-delivery-indexer judge's tests). func TestRegistrationPublishesTheNewestTrunkList(t *testing.T) { withoutAPublishedList(t) open := aMesh(t) ctx := t.Context() // A manifest naming font-size registers, and its build's list is published. if _, _, err := takeIn(ctx, open.inventory, asTheOperator(t, open.inventory, catalogueBuild("b-1", notifierFallingBackTo("font-size", "number"), theFirstKeys, 10))); err != nil { t.Fatalf("a module naming font-size was not registered: %v", err) } kept, has, err := open.inventory.PredefinedKept(ctx) if err != nil || !has || kept.Generation != 10 || kept.Build != "b-1" { t.Fatalf("the list was not published: %+v %v %v", kept, has, err) } if got := catalogue.PublishedPredefined(); len(got) != 2 { t.Fatalf("the controller judges against %v, not the list published", got) } // A newer build's list, which drops agent-managed-settings, replaces the published one. smaller := `{"font-size": {"type": "number", "description": "points", "minimum": 6, "maximum": 72}}` if _, _, err := takeIn(ctx, open.inventory, catalogueBuild("b-4", notifierFallingBackTo("font-size", "number"), smaller, 12)); err != nil { t.Fatal(err) } // The older build's outcome heard later registers nothing new about the list: the newer stands. if _, _, err := takeIn(ctx, open.inventory, catalogueBuild("b-5", notifierFallingBackTo("font-size", "number"), theFirstKeys, 11)); err != nil { t.Fatal(err) } kept, _, _ = open.inventory.PredefinedKept(ctx) if kept.Build != "b-4" || len(kept.Keys) != 1 || len(catalogue.PublishedPredefined()) != 1 { t.Fatalf("an older build's list heard later replaced the newer one: %+v", kept) } // A build of another repository publishes nothing. other := catalogueBuild("b-6", notifierFallingBackTo("font-size", "number"), theFirstKeys, 99) other.Repository, other.Source.Repository = "http://forge.internal:20000/novox/notifier.git", "novox/notifier" other.Manifest = json.RawMessage(strings.Replace(notifierFallingBackTo("font-size", "number"), `"notifier"`, `"chimes"`, 1)) if _, _, err := takeIn(ctx, open.inventory, asTheOperator(t, open.inventory, other)); err != nil { t.Fatalf("a module of another repository naming a published key: %v", err) } if kept, _, _ = open.inventory.PredefinedKept(ctx); kept.Build != "b-4" { t.Fatalf("a build of another repository published its list: %+v", kept) } }