62 lines
3.2 KiB
Go
62 lines
3.2 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/novox/mesh-controller/internal/link"
|
|
)
|
|
|
|
// A delivery group's gate is the composed check's, and its members' own checks run their repository's check alone
|
|
// (novox/hq ADR 0403 clauses 1 and 7). Pure: no store, no bus.
|
|
|
|
// The heads of a group's members, by repository.
|
|
const (
|
|
headHost = "1111111111111111111111111111111111111111"
|
|
headController = "2222222222222222222222222222222222222222"
|
|
)
|
|
|
|
// A composed member's verdict never says its gate passed: the gate layer, and the verdict that is the gate's, read
|
|
// "composed"; a failure or an error stays what it was.
|
|
func TestAComposedMembersVerdictHasNoPassingGate(t *testing.T) {
|
|
asked := &link.CheckRequest{Owner: "novox", Repo: "mesh-host", Number: 114, Composed: true}
|
|
pass := link.BuildResult{ID: "b", Ref: headHost, Checked: asked, Check: &link.CheckOutcome{Verdict: "pass", Summary: "no module touched",
|
|
Gate: &link.CheckLayer{Verdict: "pass", Summary: "no module touched"}, RepoCheck: &link.CheckLayer{Verdict: "pass", Summary: "ok"}}}
|
|
c := checkedOf(pass)
|
|
if c.Gate == nil || c.Gate.Verdict != "composed" || c.Verdict != "composed" || c.RepoCheck == nil || c.RepoCheck.Verdict != "pass" {
|
|
t.Fatalf("the member's verdict says %+v gate %+v", c, c.Gate)
|
|
}
|
|
asked.Composed = false
|
|
if c := checkedOf(pass); c.Gate.Verdict != "pass" || c.Verdict != "pass" {
|
|
t.Fatalf("a member of no composed group has its own gate: %+v", c.Gate)
|
|
}
|
|
asked.Composed = true
|
|
failing := pass
|
|
failing.Check = &link.CheckOutcome{Verdict: "fail", Summary: "conflict", Gate: &link.CheckLayer{Verdict: "fail", Summary: "conflict"},
|
|
RepoCheck: &link.CheckLayer{Verdict: "fail", Summary: "conflict"}}
|
|
if c := checkedOf(failing); c.Gate.Verdict != "fail" || c.Verdict != "fail" {
|
|
t.Fatalf("a failure was read as composed: %+v", c.Gate)
|
|
}
|
|
broken := link.BuildResult{ID: "b", Ref: headHost, Checked: asked, Failed: "the facts snapshot cannot be read"}
|
|
if c := checkedOf(broken); c.Verdict != "error" || c.Gate.Verdict != "error" {
|
|
t.Fatalf("an error was read as composed: %+v", c)
|
|
}
|
|
}
|
|
|
|
// The composed verdict on the bus carries every member, each with its trunk commit, for the forge's holder to set each
|
|
// member's mesh/merge-gate from it.
|
|
func TestTheComposedVerdictCarriesEveryMember(t *testing.T) {
|
|
asked := &link.CheckRequest{Owner: "novox", Repo: "mesh-host", Number: 114, Group: "feat/x",
|
|
Members: []link.GroupMember{{Owner: "novox", Repo: "mesh-controller", Number: 346, Ref: headController}}}
|
|
c := checkedOf(link.BuildResult{ID: "g", Ref: headHost, Checked: asked, Check: &link.CheckOutcome{Verdict: "pass", Summary: "ok",
|
|
Trunk: "aaaaaaaaaaaa", Members: []link.CheckedMember{{Owner: "novox", Repo: "mesh-controller", Commit: headController[:12], Trunk: "bbbbbbbbbbbb"}}}})
|
|
body, _ := json.Marshal(c)
|
|
for _, want := range []string{`"group":"feat/x"`, `"members":[{"owner":"novox","repo":"mesh-host","number":114,"commit":"` + headHost + `","trunk":"aaaaaaaaaaaa"}`,
|
|
`{"owner":"novox","repo":"mesh-controller","number":346,"commit":"` + headController + `","trunk":"bbbbbbbbbbbb"}`} {
|
|
if !strings.Contains(string(body), want) {
|
|
t.Fatalf("the composed verdict lacks %s:\n%s", want, body)
|
|
}
|
|
}
|
|
}
|