Record whether a node is adopted and which modules were taken on it (hq ADR 0100)
This commit is contained in:
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
// **A read-shaped invocation is never a destructive write.**
|
||||
@@ -97,3 +98,52 @@ func TestAskingAboutAMachineTheMeshHasNeverHeardOfIsRefused(t *testing.T) {
|
||||
t.Fatal("a name the mesh does not know was answered as if it were a machine")
|
||||
}
|
||||
}
|
||||
|
||||
// novox/hq ADR 0100: the operator says a node is adopted — `node add --adopted` for a record, and
|
||||
// the token for a machine joining.
|
||||
func TestANodeAddedAdoptedIsAdopted(t *testing.T) {
|
||||
open := aMesh(t)
|
||||
ctx := t.Context()
|
||||
if err := addNode(ctx, open.inventory, []string{"joiner", "--adopted"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
n, err := open.inventory.NodeByName(ctx, "joiner")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !n.Adopted {
|
||||
t.Fatal("node add --adopted made a converged node")
|
||||
}
|
||||
if err := addNode(ctx, open.inventory, []string{"plain"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if n, _ := open.inventory.NodeByName(ctx, "plain"); n.Adopted {
|
||||
t.Fatal("node add without --adopted made an adopted node")
|
||||
}
|
||||
}
|
||||
|
||||
func TestATokenIssuedAdoptedSaysSoAndReissuingDoesNotConverge(t *testing.T) {
|
||||
open := aMesh(t)
|
||||
ctx := t.Context()
|
||||
issued, err := issueFor(ctx, open.inventory, "", "joiner", true, time.Hour)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !issued.Node.Adopted {
|
||||
t.Fatal("a token issued --adopted is for a node that is not adopted")
|
||||
}
|
||||
again, err := issueFor(ctx, open.inventory, "joiner", "", false, time.Hour)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !again.Node.Adopted {
|
||||
t.Fatal("re-issuing without --adopted converged the node; converging is its own act")
|
||||
}
|
||||
existing, err := issueFor(ctx, open.inventory, "laptop", "", true, time.Hour)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !existing.Node.Adopted {
|
||||
t.Fatal("--adopted on an existing record did not make it adopted")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user