package config import ( "os" "path/filepath" "testing" ) // TestTheDocumentedAgentExampleLoads parses the file shipped in deploy/examples. // // It exists because the example was wrong for the entire life of the project // and nothing noticed. The fabric struct carried no koanf tags, so the `name:` // key the example documents bound to nothing, and an agent configured exactly // as instructed refused to start with "fabrics[0]: name is required" — naming // the key the operator had just written. // // Every fabric until then had been configured in a Go test, where the tags do // not matter. A published example that has never been parsed is a guess. func TestTheDocumentedAgentExampleLoads(t *testing.T) { path := filepath.Join("..", "..", "deploy", "examples", "agent.yaml") if _, err := os.Stat(path); err != nil { t.Skipf("no example to check: %v", err) } cfg, err := LoadAgent(path) if err != nil { t.Fatalf("the documented example does not load: %v", err) } if len(cfg.Fabrics) == 0 { t.Fatal("the example documents a fabric and none was parsed") } f := cfg.Fabrics[0] if f.Fabric == "" { t.Error("the fabric name did not bind") } if len(f.HCAs) == 0 { t.Error("the fabric's adapters did not bind") } if f.RateGbps == 0 { t.Error("the fabric's rate did not bind") } // node_id is left to the hostname, so the example need not say it; where // the control plane is, nothing can find out. if cfg.Server == "" { t.Errorf("server=%q", cfg.Server) } } func TestTheDocumentedServerExampleLoads(t *testing.T) { path := filepath.Join("..", "..", "deploy", "examples", "server.yaml") if _, err := os.Stat(path); err != nil { t.Skipf("no example to check: %v", err) } cfg, err := Load(path) if err != nil { t.Fatalf("the documented example does not load: %v", err) } if err := cfg.Validate(); err != nil { t.Fatalf("the documented example does not validate: %v", err) } if cfg.Listen == "" || len(cfg.Models) == 0 { t.Errorf("listen=%q models=%d", cfg.Listen, len(cfg.Models)) } }