package main import ( "encoding/json" "strings" "testing" "git.novox.be/novox/mesh-delivery/contracts/go/clients/meshcatalogclient" "git.novox.be/novox/mesh-delivery/contracts/go/seats/meshcatalog" ) // Design 47 G ยง589, A-87: the tools bundle reads each watched branch's newest catalog graph entry of the module from the catalog // half itself: the verb registrations for the branches, the verb revision for each branch's view. func TestNewestIsReadFromTheCatalogHalfOfEachWatchedBranch(t *testing.T) { fp := map[string]string{"main": "src2:" + strings.Repeat("1", 64), "feature": "src2:" + strings.Repeat("2", 64)} ask := func(key string, body any) (json.RawMessage, error) { switch key { case meshcatalogclient.RegistrationsVerb: return json.Marshal(meshcatalog.RegistrationsAnswer{Registrations: []meshcatalog.Registration{{Module: "m", Branches: []string{"main", "feature"}}}}) case meshcatalogclient.RevisionVerb: in := body.(meshcatalog.RevisionInput) return json.Marshal(meshcatalog.RevisionAnswer{Revision: &meshcatalog.CatalogRevision{Revision: 3, Kind: meshcatalogclient.KindTrunk}, Entries: []meshcatalog.CatalogEntry{{Module: "m", Fp: fp[in.Branch]}, {Module: "z", Fp: "src2:" + strings.Repeat("9", 64)}}}) } t.Fatalf("asked %s", key) return nil, nil } got, err := newestVia(ask)("m") if err != nil || len(got) != 2 || got["main"] != fp["main"] || got["feature"] != fp["feature"] { t.Fatalf("newest = %v, %v, want each branch's entry fingerprint whole", got, err) } }