| 1 | package release |
| 2 | |
| 3 | import "testing" |
| 4 | |
| 5 | // Ruling R-PLANNED-RECOVERY (Astra round 2 finding 1): the pre-exec |
| 6 | // revalidation admits the planner's selection of a build in place of exactly |
| 7 | // the held target, and nothing wider. |
| 8 | func TestHeldExecStaleAdmitsOnlyThePlannersTransition(t *testing.T) { |
| 9 | heldT := HeldWakeDecision{Target: "T", Held: true} |
| 10 | st := &BuildState{LastExecuted: "T"} |
| 11 | cases := []struct { |
| 12 | name string |
| 13 | d HeldWakeDecision |
| 14 | st *BuildState |
| 15 | build string |
| 16 | inPlaceOf string |
| 17 | admitted bool |
| 18 | }{ |
| 19 | {"the target itself", heldT, st, "T", "", true}, |
| 20 | {"the good build, no selection", heldT, st, "A", "", false}, |
| 21 | {"the good build, chosen in place of T", heldT, st, "A", "T", true}, |
| 22 | {"the good build, chosen in place of another build", heldT, st, "A", "B", false}, |
| 23 | {"last_executed restarts", HeldWakeDecision{Target: "R", Held: true}, &BuildState{LastExecuted: "A"}, "A", "", true}, |
| 24 | {"a pending request's T, the fallback in place of it", HeldWakeDecision{Target: "T", Held: true}, &BuildState{LastExecuted: "A0"}, "A", "T", true}, |
| 25 | {"not held", HeldWakeDecision{}, st, "A", "", true}, |
| 26 | } |
| 27 | for _, c := range cases { |
| 28 | err := HeldExecStale(c.d, c.st, c.build, c.inPlaceOf) |
| 29 | if (err == nil) != c.admitted { |
| 30 | t.Errorf("%s: HeldExecStale = %v; admitted want %v", c.name, err, c.admitted) |
| 31 | } |
| 32 | } |
| 33 | } |
| 34 | |