diff --git a/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/catalogrevision_subject_test.go b/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/catalogrevision_subject_test.go new file mode 100644 index 00000000..f36ae4ee --- /dev/null +++ b/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/catalogrevision_subject_test.go @@ -0,0 +1,25 @@ +package main + +import ( + "testing" + + meshcatalog "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog" +) + +func TestACatalogRevisionIsSaidOnTheSeatsSubjectWithItsBranch(t *testing.T) { + for _, c := range []struct { + name string + e meshcatalog.CatalogRevisionEvent + want string + refused bool + }{ + {"trunk", meshcatalog.CatalogRevisionEvent{Kind: "trunk", Branch: "main", Revision: 3}, "mesh.seat.mesh-catalog.event.catalog-revision.main", false}, + {"candidate", meshcatalog.CatalogRevisionEvent{Kind: "candidate", Branch: "fix/x=2ey", Revision: 1}, "mesh.seat.mesh-catalog.event.catalog-revision.fix/x=2ey", false}, + {"no branch", meshcatalog.CatalogRevisionEvent{Kind: "trunk", Revision: 3}, "", true}, + } { + got, err := catalogRevisionSubject(c.e) + if (err != nil) != c.refused || got != c.want { + t.Errorf("%s: subject %q (%v), want %q refused=%v", c.name, got, err, c.want, c.refused) + } + } +} diff --git a/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/integration_test.go b/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/integration_test.go index a3b2c506..29e8e44a 100644 --- a/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/integration_test.go +++ b/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/integration_test.go @@ -1064,7 +1064,7 @@ func TestIndexerWritesModulesAtAMerge(t *testing.T) { // 1239/AC9; I1, I3: the m if err != nil { t.Fatal(err) } - if msg, err := events.GetLastMsgForSubject(ctx, "mesh.seat.mesh-catalog.event."+meshcatalog.EventCatalogRevision); err != nil || + if msg, err := events.GetLastMsgForSubject(ctx, meshcatalog.SubjectCatalogRevisionAll); err != nil || !strings.Contains(string(msg.Data), fmt.Sprintf(`"revision":%d`, newest)) { t.Errorf("catalog-revision said: %v (%v): want revision %d", msg, err, newest) } diff --git a/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/objects.go b/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/objects.go index 459c2584..8e33e217 100644 --- a/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/objects.go +++ b/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/objects.go @@ -125,6 +125,16 @@ func (b *busObjects) Fill(ctx context.Context) (int64, int64, error) { return int64(st.Size()), info.CachedInfo().Config.MaxBytes, nil } +// catalogRevisionSubject is where an event says: the seat's catalog-revision. (the seat definition's subject), the +// branch the event's own field names. An event with no branch is refused: the indexer names the branch of every revision it +// keeps, and a bare subject is one the bus refuses. +func catalogRevisionSubject(e meshcatalog.CatalogRevisionEvent) (string, error) { + if e.Branch == "" { + return "", fmt.Errorf("the catalog-revision of %s revision %d names no branch, so it has no subject", e.Kind, e.Revision) + } + return meshcatalog.SubjectCatalogRevision(e.Branch), nil +} + // sayCatalogRevision publishes the seat mesh-catalog's event catalog-revision under the duplicate id of its kind and // number, so a revision said twice is heard once (design 47, Two graphs). func sayCatalogRevision(conn *nats.Conn, cred process.Account) func(context.Context, meshcatalog.CatalogRevisionEvent) error { @@ -133,7 +143,11 @@ func sayCatalogRevision(conn *nats.Conn, cred process.Account) func(context.Cont if err != nil { return err } - msg := nats.NewMsg(seatEventSubject(meshcatalog.EventCatalogRevision)) + subject, err := catalogRevisionSubject(e) + if err != nil { + return err + } + msg := nats.NewMsg(subject) id := fmt.Sprintf("%s-%s-%d%s", meshcatalog.EventCatalogRevision, e.Kind, e.Revision, e.Heads) msg.Header.Set("x-event-id", id) msg.Header.Set("x-source", cred.Module)