package main import ( "strings" "testing" "github.com/novox/mesh-controller/internal/inventory" ) // Issue 1403: a retry whose every module still waits for the bus asked nothing, and does not say "asked" with an empty list. func TestARetryWhoseModulesAllWaitForTheBusSaysNothingWasAsked(t *testing.T) { p := inventory.Plan{ID: "plan-9", Tier: 1, Tiers: [][]string{{"a"}, {"b", "c"}}} note, said := retryWords(p, []string{"b", "c"}, nil, []string{"b", "c"}) for _, text := range []string{note, said} { if strings.Contains(text, "asked ;") || strings.Contains(text, "asked ") || strings.HasSuffix(strings.Split(text, ";")[0], "asked") { t.Errorf("a retry that asked nothing says %q", text) } if !strings.Contains(text, "b, c not asked yet: the bus did not answer") { t.Errorf("it does not say what waits for the bus: %q", text) } } if !strings.Contains(said, "nothing asked yet") || !strings.Contains(note, "nothing could be asked yet") { t.Errorf("it does not say that nothing was asked: %q / %q", said, note) } } func TestARetryThatAskedSomeAndLeftSomeForTheBusSaysBoth(t *testing.T) { p := inventory.Plan{ID: "plan-9", Tier: 0, Tiers: [][]string{{"a", "b"}}} note, said := retryWords(p, []string{"a", "b"}, []string{"a as build-1"}, []string{"b"}) if !strings.Contains(note, "a asked again") || strings.Contains(note, "a, b asked again") { t.Errorf("the note names b as asked again: %q", note) } if !strings.Contains(said, "asked a as build-1;") || !strings.Contains(said, "b not asked yet: the bus did not answer") { t.Errorf("the answer says %q", said) } } func TestARetryThatAskedEverythingSaysSoAsBefore(t *testing.T) { p := inventory.Plan{ID: "plan-9", Tier: 0, Tiers: [][]string{{"a"}}} note, said := retryWords(p, []string{"a"}, []string{"a as build-1"}, nil) if note != "tier 0 retried by hand: a asked again" || said != "plan-9 retried at tier 0 of 1: asked a as build-1; the plan goes on from there as any plan does" { t.Errorf("a retry that asked everything says %q / %q", note, said) } }