Files
mesh-catalog/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/issue1114_test.go
T

91 lines
4.0 KiB
Go

package main
import (
"strings"
"testing"
)
// novox/hq issue 1114: mesh-controller #379 was opened at the head of the still-open #378. Its announcement read as the
// same delivery announced again, so when #378 closed unmerged the shared record went Stopped and #379 had no delivery.
// The other open pull request at the head is kept on the record; a close of the record's own pull request starts the
// record over for it at once (as issue 1083's take-over does for a later announcement), and an edit of it does so too,
// so a case stuck before the fix frees itself. A merged record is never taken over.
const head1114 = "0149a3d70149a3d70149a3d70149a3d70149a3d7"
func TestClosingThePullRequestOfASharedHeadStartsTheOtherOnesDeliveryOver(t *testing.T) {
w := newWorld(t)
w.op.auto = false
id := IDOf(gCtl, head1114)
w.h.PullUpdated(pr(gCtl, 378, head1114, "feat/chain", "internal/a.go"))
b := pr(gCtl, 379, head1114, "feat/chain-2", "internal/a.go")
b.Body = "Reviewed-by: reviewer@shanks at " + head1114
w.h.PullUpdated(b) // announced while #378 is live: the same delivery heard again
if d := w.delivery(id); d.Number != 378 {
t.Fatalf("setup: the record is #%d, wanted #378 still", d.Number)
}
w.h.PullClosed(pr(gCtl, 378, head1114, "feat/chain"))
d := w.delivery(id)
if d.Number != 379 || d.State.Final() || d.ClosedUnmerged {
t.Fatalf("after #378 closed the record is #%d %s (closed %v); wanted #379, proposed", d.Number, d.State, d.ClosedUnmerged)
}
if d.ReviewedBy == "" {
t.Fatalf("#379's review record was not read: %+v", d)
}
w.h.Checked(verdict(gCtl, 379, head1114, "pass"))
w.settleAll()
if open := w.op.open(); w.state(id) != Ready || len(open) != 1 ||
!strings.Contains(w.op.ask(open[0]).Explanation, "reviewed by reviewer") {
t.Fatalf("#379's delivery is %s with asks %v; wanted ready and one Approve ask with its review record", w.state(id), w.op.open())
}
}
func TestClosingTheOtherPullRequestOfASharedHeadLeavesTheRecordAlone(t *testing.T) {
w := newWorld(t)
id := IDOf(gCtl, head1114)
w.h.PullUpdated(pr(gCtl, 378, head1114, "feat/chain", "internal/a.go"))
w.h.PullUpdated(pr(gCtl, 379, head1114, "feat/chain-2", "internal/a.go"))
w.h.PullClosed(pr(gCtl, 379, head1114, "feat/chain-2"))
w.h.PullClosed(pr(gCtl, 378, head1114, "feat/chain"))
if d := w.delivery(id); d.Number != 378 || !d.ClosedUnmerged || !d.State.Final() {
t.Fatalf("with #379 closed first, #378's close left %d %s; wanted it stopped under #378", d.Number, d.State)
}
}
func TestAnEditOfAPullRequestWhoseSharedHeadsRecordIsStoppedUnderAnotherTakesItOver(t *testing.T) {
w := newWorld(t)
id := IDOf(gCtl, head1114)
w.h.PullUpdated(pr(gCtl, 378, head1114, "feat/chain", "internal/a.go"))
w.h.PullClosed(pr(gCtl, 378, head1114, "feat/chain")) // #379 was never heard: the stuck case
if d := w.delivery(id); !d.State.Final() {
t.Fatalf("setup: %s", d.State)
}
e := pr(gCtl, 379, head1114, "feat/chain-2")
e.Body = "Reviewed-by: reviewer@shanks at " + head1114
w.h.PullEdited(e)
d := w.delivery(id)
if d.Number != 379 || d.State != Proposed || d.ReviewedBy == "" || len(d.Paths) == 0 {
t.Fatalf("after #379's edit the record is #%d %s reviewed %q paths %v; wanted #379 proposed, read, with the paths", d.Number,
d.State, d.ReviewedBy, d.Paths)
}
w.h.PullEdited(e) // an edit heard again changes nothing
if again := w.delivery(id); again.Number != 379 || again.State != Proposed {
t.Fatalf("a second edit moved it: #%d %s", again.Number, again.State)
}
}
func TestAMergedRecordIsNeverTakenOverByTheOtherPullRequestOfItsHead(t *testing.T) {
w := newWorld(t)
id := IDOf(gCtl, head1114)
w.h.PullUpdated(pr(gCtl, 378, head1114, "feat/chain", "internal/a.go"))
w.h.PullUpdated(pr(gCtl, 379, head1114, "feat/chain-2", "internal/a.go"))
w.h.PullMerged(merged(gCtl, 378, head1114, "f378f378f378f378"))
w.h.PullClosed(pr(gCtl, 378, head1114, "feat/chain"))
e := pr(gCtl, 379, head1114, "feat/chain-2")
e.Body = "text"
w.h.PullEdited(e)
if d := w.delivery(id); d.Number != 378 || d.MergedAs == "" {
t.Fatalf("a merged record was taken over: #%d merged as %q", d.Number, d.MergedAs)
}
}