Skip to content
quarry Artifact [072abd8029]
Login

Artifact [072abd8029]

Artifact 072abd80297a408337321e22c38830421178228ea762e65309c4e51db3b36dfa:


package web

import (
	"strings"
	"testing"
	"time"
)

// Right after Update from trunk the new tip has no runs yet: they are
// dispatched once the poller folds the merge. Re-run is not offered in
// that gap; once it has passed, a required check with no run offers
// Re-run again, as the only way to start one.
func TestReRunIsHiddenWhileAnUpdatesRunsAreDispatched(t *testing.T) {
	render := func(at time.Time) string {
		var buf strings.Builder
		err := noHooks.template(landingPage).ExecuteTemplate(&buf, "landing-body", pageData{
			Repo: "quarry", CanTrigger: true,
			Landing: &landingDetail{
				landingRow: landingRow{ID: "aa11bb22cc33", Branch: "b", Target: "trunk", State: "open"},
				Required:   []string{"quarry"},
				Events:     []landingEvent{{State: "updated", User: "dmestas", Date: at.UTC().Format("2006-01-02T15:04:05.000")}},
			},
		})
		if err != nil {
			t.Fatal(err)
		}
		return buf.String()
	}
	if got := render(time.Now()); strings.Contains(got, "/ci/trigger") {
		t.Error("FAIL: Re-run offered while the update's runs are being dispatched")
	}
	if got := render(time.Now().Add(-10 * time.Minute)); !strings.Contains(got, "/ci/trigger") {
		t.Error("FAIL: Re-run not offered for a required check that never ran")
	}
}