package edgesfile import "testing" func TestParseReadsTheWireShape(t *testing.T) { f, err := Parse([]byte(`{"v":1,"box":"annie","eip":"1.1.1.1","region":"eu-west-1",` + `"generation":"2026-08-27T09:00:00Z","hosts":{"a.test":{"role":"home","platform":true},` + `"b.test":{"role":"home","alias":true},` + `"*.c.test":{"role":"wildcard","wildcard":true}}}`)) if err != nil { t.Fatalf("parse: %v", err) } if f.Box != "annie" || f.EIP != "1.1.1.1" || f.Region != "eu-west-1" { t.Fatalf("identity fields = %+v", f) } if !f.Hosts["a.test"].Platform || f.Hosts["a.test"].Alias { t.Fatalf("a.test = %+v, want platform-class route", f.Hosts["a.test"]) } if !f.Hosts["b.test"].Alias || f.Hosts["b.test"].Platform { t.Fatalf("b.test = %+v, want a claim-derived alias", f.Hosts["b.test"]) } // A delegated wildcard parent (#305) decodes with its mark and its own // role. The reader must carry the role through verbatim rather than // normalising it: "wildcard" is the cert half alone, and a reader that // silently read it as RoleHome would dial a box that does not serve the // catch-all. if w := f.Hosts["*.c.test"]; !w.Wildcard || w.Role != "wildcard" { t.Fatalf("*.c.test = %+v, want a cert-only delegated parent", w) } } // V < 1 (no version field at all) is not a file this reader understands; a // HIGHER version is accepted, because the schema grows additively and a newer // box's file still carries box/eip/hosts verbatim. Mirrors the contract // internal/edge/homemap.go and internal/steering already hold. func TestParseRefusesUnversionedAndAcceptsNewer(t *testing.T) { if _, err := Parse([]byte(`{"box":"annie","eip":"1.1.1.1"}`)); err == nil { t.Fatal("an unversioned file must be refused") } if _, err := Parse([]byte(`{"v":9,"box":"annie","eip":"1.1.1.1"}`)); err != nil { t.Fatalf("a newer version must still parse: %v", err) } } func TestKeyIsThePrefixedBoxName(t *testing.T) { if got := Key("annie"); got != "control/edges/annie.json" { t.Fatalf("Key = %q", got) } }