Skip to content
quarry Artifact [c759b370f2]
Login

Artifact [c759b370f2]

Artifact c759b370f281130e81aa3e12bcd4c455691403cbb3f0fb08003cec0bebfa1939:


package api

import (
	"testing"

	"craftdesign.group/quarry/internal/index"
)

// A rung with no green run of the target's required checks waits, and
// the stack lands only the rungs below the lowest that waits.
func TestAStackLandsOnlyBelowItsLowestWaitingRung(t *testing.T) {
	st := func() *index.Strata {
		return &index.Strata{Top: "c", Preflight: "lands", LandTo: "c", LandCount: 3, Segments: []index.StackSegment{
			{ID: "a", Target: "trunk", State: "open", Position: 1},
			{ID: "b", Target: "ba", State: "open", Position: 2},
			{ID: "c", Target: "bb", State: "open", Position: 3},
		}}
	}
	all := []index.LandingSummary{{ID: "a", Target: "trunk"}, {ID: "b", Target: "ba"}, {ID: "c", Target: "bb"}}
	d := Deps{Checks: checksStub{required: []string{"quarry"}}, Repos: NewRepos(map[string]*Repo{})}

	s := st()
	d.strataChecks("test", all, s)
	if s.WaitsAt != 1 || s.LandCount != 0 || s.LandTo != "" || len(s.Segments[0].Waiting) != 1 {
		t.Errorf("FAIL: a base with no green run read %+v", s)
	}

	// Nothing required: the probe's answer stands.
	s = st()
	Deps{Checks: checksStub{}}.strataChecks("test", all, s)
	if s.WaitsAt != 0 || s.LandCount != 3 || s.LandTo != "c" {
		t.Errorf("FAIL: with nothing required the stack read %+v", s)
	}

	// Not probed: lands whole until a rung waits.
	s = st()
	s.Preflight, s.LandTo, s.LandCount = "", "", 0
	Deps{}.strataChecks("test", all, s)
	if s.LandCount != 3 || s.LandTo != "c" {
		t.Errorf("FAIL: an unprobed stack read %+v", s)
	}

	// A probe that stops at rung 2 is not overruled by checks above it.
	s = st()
	s.Preflight, s.StopsAt, s.LandTo, s.LandCount = "stops", 2, "a", 1
	s.Segments[0].State = "accepted"
	d.strataChecks("test", all, s)
	if s.LandCount != 1 || s.WaitsAt != 0 {
		t.Errorf("FAIL: checks above the stopping rung moved the walk: %+v", s)
	}
}