package main import ( "os" "testing" "git.novox.be/novox/mesh-sdk/go/catalogue" ) type resource map[string]any func resourceOf(t *testing.T, m catalogue.Manifest, id string) resource { t.Helper() for _, r := range m.Resources { if r["id"] == id { return r } } t.Fatalf("no resource %s", id) return nil } // TestToolsAreTheManifests holds the served tools and the manifest's list to one another, and the // bundle to the shape the builder compiles and the runtime loads. func TestToolsAreTheManifests(t *testing.T) { manifestJSON, err := os.ReadFile("../../module.json") if err != nil { t.Fatal(err) } // manifest strictness is the catalog check's (H-A-498): the SDK's reader sets an unknown field aside. m, err := catalogue.Decode(manifestJSON) if err != nil { t.Fatalf("module.json: %v", err) } names := map[string]bool{} for _, tool := range tools(machine(nil, 1000)) { if names[tool.Name] { t.Errorf("%s is served twice", tool.Name) } names[tool.Name] = true } for _, want := range m.Tools { if !names[want] { t.Errorf("the manifest lists %s and the bundle does not serve it", want) } delete(names, want) } if len(names) != 0 { t.Errorf("served and not listed: %v", names) } var tools *catalogue.Artifact for _, a := range m.Build.Artifacts { if a.Name == "tools" { tools = &a } } if tools == nil || tools.Kind != "bundle" || tools.Language != "go" || tools.System != "arch" || tools.From != "cmd/"+binaryName || tools.Binary != binaryName { t.Fatalf("the tools artifact: %v", tools) } if len(tools.Loads) != 1 || tools.Loads[0] != binaryName { t.Fatalf("loads: %v", tools.Loads) } }