Files
mesh-host/internal/bootstrap/phase2_test.go
T
jschoubben 0c01c81c3f E8: run each file's unit tests as subtests of one test
The node-engine held 1,707 top-level unit tests against the budget of 500
a module. Each unit test file with two or more tests now runs them as
subtests of one test named for the file, each named as its function was,
in the same order: every check is kept, and the check counts 383. Files
with a TestMain, a re-run of a test by its name, or the integration tag
are left. Four files of this branch's earlier commits are formatted.

Builds: design 47 H2 §819; H-A-349 DQ-14
2026-11-22 00:30:05 +01:00

54 lines
2.2 KiB
Go

package bootstrap
import (
"strings"
"testing"
)
// The endpoint other machines dial defaults to the host they already dial — the broker's — on
// WireGuard's port. One fact, not two that drift.
func testTheEndpointDerivesFromTheBrokerAddress(t *testing.T) {
if got := derivedEndpoint("192.0.2.10:5671", 51820); got != "192.0.2.10:51820" {
t.Fatalf("derived %q", got)
}
if got := derivedEndpoint("", 51820); got != "" {
t.Fatalf("an endpoint was invented from nothing: %q", got)
}
}
// A manifest with artifacts builds; one without does not — which is what separates postgres (a
// bundle to compile) from nftables (a package and a service).
func testOnlyAManifestWithArtifactsBuilds(t *testing.T) {
if !builds([]byte(`{"build":{"artifacts":[{"name":"x"}]}}`)) {
t.Fatal("a manifest with artifacts was not built")
}
if builds([]byte(`{"resources":[{"id":"p","type":"package","package":"nftables"}]}`)) {
t.Fatal("a manifest with nothing to build was built anyway")
}
}
// Defends novox/hq ADR 0100: the hub's port is the node's, and the endpoint other machines dial
// must name it — an endpoint on another port is an address nothing answers on.
func testTheEndpointAgreesWithTheHubsPort(t *testing.T) {
if got, err := endpointAgrees("192.0.2.10:51820", 51820); err != nil || got != "192.0.2.10:51820" {
t.Errorf("an endpoint on the hub's port: %q %v", got, err)
}
if got, err := endpointAgrees("192.0.2.10", 51821); err != nil || got != "192.0.2.10:51821" {
t.Errorf("a host alone did not take the hub's port: %q %v", got, err)
}
_, err := endpointAgrees("192.0.2.10:51820", 51821)
if err == nil || !strings.Contains(err.Error(), "--hub-port") {
t.Errorf("two ports for one hub were accepted: %v", err)
}
if _, err := endpointAgrees("192.0.2.10:not-a-port", 51820); err == nil {
t.Error("an endpoint whose port is not a number was accepted")
}
}
// TestPhase2 runs this file's tests, each a subtest named as its function was (design 47 H2 §819, the test budget).
func TestPhase2(t *testing.T) {
t.Run("TheEndpointDerivesFromTheBrokerAddress", testTheEndpointDerivesFromTheBrokerAddress)
t.Run("OnlyAManifestWithArtifactsBuilds", testOnlyAManifestWithArtifactsBuilds)
t.Run("TheEndpointAgreesWithTheHubsPort", testTheEndpointAgreesWithTheHubsPort)
}