59 lines
2.3 KiB
Go
59 lines
2.3 KiB
Go
package main
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/novox/mesh-controller/internal/inventory"
|
|
)
|
|
|
|
// 1922/AC1: a tier naming a module the catalogue no longer holds asks it without failing the plan: the module ends
|
|
// as deleted (not built, not sent) and the tier's other modules go on.
|
|
func TestAModuleTheCatalogueNoLongerHoldsEndsDeletedAndTheTierGoesOn(t *testing.T) {
|
|
p, byName := aWalkOfOne("sudo")
|
|
p.Tiers = [][]string{{"gone", "sudo"}}
|
|
for _, m := range p.Tiers[0] {
|
|
askModule(t.Context(), p, m, byName)
|
|
}
|
|
if g := p.Modules["gone"]; g == nil || g.State != planDeleted || g.Build != "" || g.SentAt != nil {
|
|
t.Fatalf("the removed module is not deleted: %+v", g)
|
|
}
|
|
if p.State == inventory.PlanFailed {
|
|
t.Fatalf("the plan failed: %q", p.Note)
|
|
}
|
|
if s := p.Modules["sudo"]; s == nil || s.State != "asked" {
|
|
t.Fatalf("the other module of the tier did not go on: %+v", s)
|
|
}
|
|
}
|
|
|
|
// 1922/AC2: a plan that failed on such a module before the fix is retried: the removed module ends deleted and the
|
|
// plan is building again, to go on to its next tier.
|
|
func TestARetryOfAPlanFailedOnARemovedModuleResumes(t *testing.T) {
|
|
p := inventory.Plan{ID: "plan-1", State: inventory.PlanFailed, Note: "gone is no longer in the catalogue",
|
|
Tiers: [][]string{{"gone"}, {"next"}},
|
|
Modules: map[string]*inventory.PlanModule{
|
|
"gone": {State: "failed", Why: "no longer in the catalogue"},
|
|
}}
|
|
failed := toRetry(&p, nil, nil)
|
|
if len(failed) != 1 || failed[0] != "gone" {
|
|
t.Fatalf("the failed set is %v", failed)
|
|
}
|
|
for _, m := range failed {
|
|
askModule(t.Context(), &p, m, map[string]inventory.Entry{})
|
|
}
|
|
resumed(&p, "retried")
|
|
if p.State != inventory.PlanBuilding || p.Modules["gone"].State != planDeleted {
|
|
t.Fatalf("the retry did not resume: %s %+v", p.State, p.Modules["gone"])
|
|
}
|
|
}
|
|
|
|
// 1922/AC3: an ended plan's note names the verb that releases the modules waiting for a gate, not `push --behind`.
|
|
func TestAnEndedPlansHintNamesTheReleaseOfTheBacklog(t *testing.T) {
|
|
p := inventory.Plan{State: inventory.PlanFailed, Note: "failed",
|
|
Modules: map[string]*inventory.PlanModule{"agent": {State: "built"}}}
|
|
sayUnsent(&p, func(string) bool { return true })
|
|
if strings.Contains(p.Note, "push --behind") || !strings.Contains(p.Note, "upgrade release-backlog") {
|
|
t.Fatalf("the note reads %q", p.Note)
|
|
}
|
|
}
|