package catalogue import ( "reflect" "strings" "testing" ) // The delivery seat answers "what did the mesh's checks say of this pull request?" as a verb of its own, // `checks` (novox/hq ADR 0239): read by repository and a pull request's number or a commit. func TestTheDeliverySeatPromisesChecks(t *testing.T) { seat, ok := SeatNamed(DeliverySeat) if !ok { t.Fatal("the delivery seat is not in the set") } var checks *Verb for i := range seat.Serves { if seat.Serves[i].Name == "checks" { checks = &seat.Serves[i] } } if checks == nil { t.Fatalf("the delivery seat promises %v and not checks", VerbNames(seat.Serves)) } props, _ := checks.Input["properties"].(map[string]any) for _, arg := range []string{"repository", "number", "commit"} { if _, has := props[arg]; !has { t.Errorf("checks takes no %q", arg) } } if req, _ := checks.Input["required"].([]string); !reflect.DeepEqual(req, []string{"repository"}) { t.Errorf("checks requires %v, wanted only the repository", req) } // Added after the seat's holder shipped, it is optional: the holder serving the ten verbs before it still // holds the seat, and one serving all eleven does too — so the controller and the catalogue can move in // either order, and no check of the catalogue fails on a module nobody touched between the two. if !checks.Optional { t.Fatal("checks is a condition of holding before its holder serves it") } var before []string for _, v := range VerbNames(seat.Serves) { if v != "checks" { before = append(before, v) } } m := Manifest{Module: "mesh-delivery", Claims: []Claim{{Name: DeliverySeat, Scope: ScopeMesh, Serves: before}}} if err := CanHold(m, seat); err != nil { t.Fatalf("a holder without checks yet: %v", err) } m.Claims[0].Serves = VerbNames(seat.Serves) if err := CanHold(m, seat); err != nil { t.Fatalf("a holder serving every verb: %v", err) } // Every other verb is still a condition of holding. m.Claims[0].Serves = append([]string{"checks"}, before[1:]...) if err := CanHold(m, seat); err == nil || !strings.Contains(err.Error(), before[0]) { t.Fatalf("a holder without %s: %v", before[0], err) } }