overlay: placing a node with nothing said no longer unplaces it
The sibling of node public-domain, and the worse one: a placement is three facts declared together, so an invocation that said none of them took all three away — the endpoint every other machine dials, the site, and the hub. A mesh whose hub was placed that way has no paths left, at the moment somebody was trying to look at it. --nothing keeps the real case (a machine that roams and opens every path itself) sayable, by name. Claude-Session: https://claude.ai/code/session_01LrgweAeERJYBg88c5cKDzF
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/novox/mesh-control/internal/inventory"
|
||||
)
|
||||
|
||||
// placementOf is what the mesh holds about where one node is.
|
||||
func placementOf(t *testing.T, ctx context.Context, inv *inventory.Inventory, name string) inventory.Overlay {
|
||||
t.Helper()
|
||||
placed, err := inv.Overlays(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, one := range placed {
|
||||
if one.Name == name {
|
||||
return one
|
||||
}
|
||||
}
|
||||
t.Fatalf("%s is not placed at all", name)
|
||||
return inventory.Overlay{}
|
||||
}
|
||||
|
||||
// The sibling of `node public-domain`, and the worse one: a placement is three facts declared
|
||||
// together, so an invocation that said none of them took all three away — the endpoint every other
|
||||
// machine dials, the site, and the hub. A mesh whose hub was placed that way has no paths left.
|
||||
func TestPlacingANodeWithNothingSaidDoesNotUnplaceIt(t *testing.T) {
|
||||
open := aMesh(t)
|
||||
ctx := t.Context()
|
||||
if err := overlayPlace(ctx, open.inventory,
|
||||
[]string{"anchor", "--endpoint", "198.51.100.10:51820", "--site", "hosting", "--hub"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err := overlayPlace(ctx, open.inventory, []string{"anchor"})
|
||||
if err == nil {
|
||||
t.Fatal("saying nothing unplaced the node instead of being refused")
|
||||
}
|
||||
if !strings.Contains(err.Error(), "--nothing") {
|
||||
t.Errorf("the refusal does not say how to mean it: %v", err)
|
||||
}
|
||||
|
||||
held := placementOf(t, ctx, open.inventory, "anchor")
|
||||
if held.Endpoint != "198.51.100.10:51820" || held.Site != "hosting" || !held.Hub {
|
||||
t.Fatalf("the placement was taken away by an invocation that was refused: %+v", held)
|
||||
}
|
||||
}
|
||||
|
||||
// Placing a machine with nothing set is a real thing to want — one that roams and opens every path
|
||||
// itself is exactly that — so it keeps a way to be said, by name.
|
||||
func TestPlacingANodeWithNothingIsAskedForByName(t *testing.T) {
|
||||
open := aMesh(t)
|
||||
ctx := t.Context()
|
||||
if err := overlayPlace(ctx, open.inventory,
|
||||
[]string{"anchor", "--endpoint", "198.51.100.10:51820", "--site", "hosting"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := overlayPlace(ctx, open.inventory, []string{"anchor", "--nothing"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
held := placementOf(t, ctx, open.inventory, "anchor")
|
||||
if held.Endpoint != "" || held.Site != "" || held.Hub {
|
||||
t.Fatalf("--nothing did not place it with nothing: %+v", held)
|
||||
}
|
||||
}
|
||||
|
||||
// Both at once cannot be meant, so neither silently wins.
|
||||
func TestAPlacementAndNothingTogetherIsRefused(t *testing.T) {
|
||||
open := aMesh(t)
|
||||
ctx := t.Context()
|
||||
if err := overlayPlace(ctx, open.inventory,
|
||||
[]string{"anchor", "--site", "hosting", "--nothing"}); err == nil {
|
||||
t.Fatal("a placement and --nothing together was accepted")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user