package link import ( "strings" "testing" ) // The count that did not add up was the only symptom sixteen held resources had, and reading it meant // opening the node's state file by hand (novox/hq 04-ISSUES/125). The line that says what an apply did // says what it did not, too. func TestTheApplyLineSaysWhatItHeldAndForWhichModule(t *testing.T) { got := heldNote([]Held{ {ID: "ca", Module: "route-proxy", Kind: "directory"}, {ID: "certs", Module: "route-proxy", Kind: "directory"}, {ID: "server", Module: "route-proxy", Kind: "container"}, {ID: "mail", Module: "mailu", Kind: "container"}, }) if !strings.Contains(got, "4 held") { t.Fatalf("the count of what was held is not in the line: %q", got) } // The module is the thing an operator can act on: `take` takes a module. if !strings.Contains(got, "route-proxy: 3") || !strings.Contains(got, "mailu: 1") { t.Fatalf("the line does not break the holds down by module: %q", got) } // Ordered, so two machines holding the same things read the same and a diff of two reports is // about what changed. if strings.Index(got, "mailu") > strings.Index(got, "route-proxy") { t.Fatalf("modules are not in a stated order: %q", got) } // It says why, because "held" alone reads as a failure and this is correct behaviour. if !strings.Contains(got, "taken") { t.Fatalf("the line does not say a hold ends when the module is taken: %q", got) } } func TestAnApplyThatHeldNothingSaysNothingExtra(t *testing.T) { // A converged machine holds nothing, which is most applies. Reporting "0 held" on every one of // them is how a line stops being read. if got := heldNote(nil); got != "" { t.Fatalf("an apply with no holds added %q to its line", got) } if got := heldNote([]Held{}); got != "" { t.Fatalf("an apply with no holds added %q to its line", got) } }