47 lines
1.8 KiB
Go
47 lines
1.8 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")
|
|
}
|
|
}
|