package api
import (
"strings"
"testing"
"craftdesign.group/quarry/internal/zitcli"
)
// cancelledRuns has no merge with a verdict: every merge of the tip was
// cancelled, and the newest of them is oldPair.
type cancelledRuns struct {
*pairRuns
oldPair string
}
func (cancelledRuns) LatestPairFor(string, string) (string, error) { return "", nil }
func (c cancelledRuns) NewestPairFor(string, string) (string, error) {
return c.oldPair, nil
}
// A landing whose every merge was cancelled reads as that cancelled
// merge, not as a never-run merge with the target as it is now, which
// the sweep never starts and which would stay pending forever.
func TestLandingWithEveryMergeCancelledShowsTheCancelledMerge(t *testing.T) {
dir, ids, ix, pipeSync := premergeStore(t)
// The cancelled merge was against a target tip trunk has moved past.
one := ztip(t, dir, "one")
ci := cancelledRuns{pairRuns: &pairRuns{runs: map[string][]CIRun{}}, oldPair: "pair:" + one + ":" + strings.Repeat("e", 64)}
d := Deps{Version: "v", Checks: mergeChecks{}, CI: ci, Repos: NewRepos(map[string]*Repo{
"test": {Index: ix, Zit: zitcli.New(dir), Sync: pipeSync}})}
l, found, err := ix.LandingByPrefix(ids[0])
if err != nil || !found {
t.Fatalf("no landing: %v", err)
}
subject, pair := d.ciSubject("test", l)
if !pair || subject != ci.oldPair {
t.Fatalf("FAIL: checks are about %q, want the cancelled merge %q", subject, ci.oldPair)
}
}