81 lines
2.2 KiB
Go
81 lines
2.2 KiB
Go
//go:build integration
|
|
|
|
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestStatusNamesAModuleHeldBecauseNothingTookIt(t *testing.T) {
|
|
open := aMesh(t)
|
|
heldOn(t, open, "anchor", "route-proxy", "ca", "certs", "server")
|
|
|
|
asked, err := theThreeQuestions(t.Context(), open)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := asked.untaken["anchor"]["route-proxy"]; got != 3 {
|
|
t.Fatalf("status counted %d resources held for route-proxy, wanted 3", got)
|
|
}
|
|
}
|
|
|
|
func TestAHeldModuleIsFoundFromWhatTheMachineReported(t *testing.T) {
|
|
// End to end through the store, so the condition above is reached by real data and not only by
|
|
// a constructed value: the machine reports, the mesh records, status asks.
|
|
open := aMesh(t)
|
|
heldOn(t, open, "anchor", "route-proxy", "ca", "server")
|
|
|
|
asked, err := theThreeQuestions(t.Context(), open)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(asked.untaken) == 0 {
|
|
t.Fatal("what the machine reported holding did not reach status")
|
|
}
|
|
if asked.well() {
|
|
t.Fatal("a mesh whose machine reported holds reads as well")
|
|
}
|
|
}
|
|
|
|
func TestTheJSONStatusCarriesWhatIsHeldAndForWhichModule(t *testing.T) {
|
|
open := aMesh(t)
|
|
heldOn(t, open, "anchor", "route-proxy", "ca", "certs")
|
|
|
|
asked, err := theThreeQuestions(t.Context(), open)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
body, err := statusAsJSON(asked)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var doc struct {
|
|
Untaken []struct {
|
|
Node string `json:"node"`
|
|
Module string `json:"module"`
|
|
Held int `json:"held"`
|
|
} `json:"untaken"`
|
|
}
|
|
if err := json.Unmarshal(body, &doc); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(doc.Untaken) != 1 {
|
|
t.Fatalf("the document carries %d untaken rows, wanted 1: %s", len(doc.Untaken), body)
|
|
}
|
|
row := doc.Untaken[0]
|
|
if row.Node != "anchor" || row.Module != "route-proxy" || row.Held != 2 {
|
|
t.Fatalf("the row is %+v, wanted anchor/route-proxy/2", row)
|
|
}
|
|
// Absent rather than empty when nothing is held, so a well mesh's document does not carry a
|
|
// field a reader has to interpret.
|
|
clean, err := statusAsJSON(answers{})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if strings.Contains(string(clean), "untaken") {
|
|
t.Fatalf("a mesh holding nothing still names untaken: %s", clean)
|
|
}
|
|
}
|