package seatlist import ( "bytes" "os" "path/filepath" "slices" "testing" "git.novox.be/novox/mesh-sdk/go/internal/beside" ) // ADR 0635 §3, ADR 0608 §2: a bootstrapped definition is a copy of its seat's file in its contracts module, byte for // byte, and a seat with a copy has a row here. The contracts are read beside this repository, as a merge check places // them (mesh-contracts, and mesh-delivery for its `contracts` folder) or, elsewhere, from the copy captured in // testdata/beside. func TestEveryBootstrappedDefinitionEqualsItsContractsFile(t *testing.T) { rows := []struct{ seat, repository, file string }{ {"mesh-broker", "mesh-contracts", "seats/mesh-broker/seat.json"}, {"mesh-config", "mesh-contracts", "seats/mesh-config/seat.json"}, {"node-engine", "mesh-contracts", "seats/node-engine/seat.json"}, {"node-backup", "mesh-contracts", "seats/node-backup/seat.json"}, {"mesh-conditions", "mesh-contracts", "health-and-repair/seats/mesh-conditions/seat.json"}, {"mesh-hand-acts", "mesh-contracts", "health-and-repair/seats/mesh-hand-acts/seat.json"}, {"mesh-watchdogs", "mesh-contracts", "health-and-repair/seats/mesh-watchdogs/seat.json"}, {"operator-channel", "mesh-contracts", "operator-and-conversation/seats/operator-channel/seat.json"}, {"mesh-catalog", "mesh-delivery", "contracts/seats/mesh-catalog/seat.json"}, {"mesh-delivery-checker", "mesh-delivery", "contracts/seats/mesh-delivery-checker/seat.json"}, } var have []string for _, d := range Bootstrapped() { have = append(have, d.Seat) } var want []string for _, r := range rows { want = append(want, r.seat) } slices.Sort(want) if !slices.Equal(have, want) { t.Fatalf("the bootstrapped seats are %v, the rows of this test %v: give each bootstrapped seat a row", have, want) } for _, r := range rows { t.Run(r.seat, func(t *testing.T) { copied, err := bootstrapFiles.ReadFile("bootstrap/" + r.seat + ".json") if err != nil { t.Fatal(err) } contract, err := os.ReadFile(filepath.Join(beside.Dir(t, r.repository), filepath.FromSlash(r.file))) if err != nil { t.Fatal(err) } if !bytes.Equal(copied, contract) { t.Errorf("seatlist/bootstrap/%s.json differs from %s's %s: replace the copy with the contracts' file (ADR 0635 §3)", r.seat, r.repository, r.file) } }) } }