package release import "testing" // Ruling R-PLANNED-RECOVERY (Astra round 2 finding 1): the pre-exec // revalidation admits the planner's selection of a build in place of exactly // the held target, and nothing wider. func TestHeldExecStaleAdmitsOnlyThePlannersTransition(t *testing.T) { heldT := HeldWakeDecision{Target: "T", Held: true} st := &BuildState{LastExecuted: "T"} cases := []struct { name string d HeldWakeDecision st *BuildState build string inPlaceOf string admitted bool }{ {"the target itself", heldT, st, "T", "", true}, {"the good build, no selection", heldT, st, "A", "", false}, {"the good build, chosen in place of T", heldT, st, "A", "T", true}, {"the good build, chosen in place of another build", heldT, st, "A", "B", false}, {"last_executed restarts", HeldWakeDecision{Target: "R", Held: true}, &BuildState{LastExecuted: "A"}, "A", "", true}, {"a pending request's T, the fallback in place of it", HeldWakeDecision{Target: "T", Held: true}, &BuildState{LastExecuted: "A0"}, "A", "T", true}, {"not held", HeldWakeDecision{}, st, "A", "", true}, } for _, c := range cases { err := HeldExecStale(c.d, c.st, c.build, c.inPlaceOf) if (err == nil) != c.admitted { t.Errorf("%s: HeldExecStale = %v; admitted want %v", c.name, err, c.admitted) } } }