package main import ( "bytes" "encoding/json" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog" "github.com/novox/mesh-host/internal/buckets/bucketstest" "go/build" "os" "os/exec" "path/filepath" "reflect" "runtime" "sort" "strings" "testing" "git.novox.be/novox/mesh-sdk/go/catalogue" "git.novox.be/novox/mesh-sdk/go/seatlist/seatlisttest" "github.com/novox/mesh-host/internal/beside" "github.com/novox/mesh-host/internal/compose" "github.com/novox/mesh-host/internal/composer" ) // captured is every manifest of the catalogue captured in testdata/beside (internal/beside), raw, by module name. func captured(t *testing.T) map[string]composer.Manifest { t.Helper() read, err := readCatalogue(filepath.Dir(beside.Catalogue(t))) if err != nil { t.Fatal(err) } if len(read) < 100 { t.Fatalf("the captured catalogue holds %d manifests, fewer than the catalogue's", len(read)) } return read } // meshOf is a mesh of three machines over the captured catalogue, each assigned real modules, the input the assigner // composes with (nodes and their assignments, holdings from the claims): anchor runs the bus and the store, laptop a // desktop's modules, ace a module whose requirement is provided elsewhere. func meshOf() compose.Input { return compose.Input{Nodes: []compose.Node{ {Name: "anchor", Assigned: []string{"nats", "postgres"}}, {Name: "laptop", Assigned: []string{"sudo", "zsh"}}, {Name: "ace", Assigned: []string{"mesh-reads", "nats"}}, }} } func request(t *testing.T, depth string) composer.Request { t.Helper() r := composer.Request{V: composer.Version, Depth: depth, HoldingsFromClaims: true, Machines: []string{"anchor", "laptop", "ace"}, Seats: seats(t), Cases: []composer.Case{{Name: "trunk", Manifests: captured(t)}}} return withInput(t, r, meshOf()) } // seats is the seat list a request carries, as the checker hands the one its reader holds (ADR 0635 §1, ADR 0636 §4). func seats(t *testing.T) []json.RawMessage { t.Helper() var out []json.RawMessage for _, d := range seatlisttest.Definitions() { raw, err := json.Marshal(d) if err != nil { t.Fatal(err) } out = append(out, raw) } return out } // withInput is r with in as its input, as a caller puts it on the wire: the request's shape carries the input as JSON. func withInput(t *testing.T, r composer.Request, in compose.Input) composer.Request { t.Helper() raw, err := json.Marshal(in) if err != nil { t.Fatal(err) } if err := json.Unmarshal(raw, &r.Input); err != nil { t.Fatal(err) } return r } func runJSON(t *testing.T, args []string, in []byte) (int, composer.Verdict, string) { t.Helper() var out, errOut bytes.Buffer code := run(args, bytes.NewReader(in), &out, &errOut) var v composer.Verdict if code == 0 { if err := json.Unmarshal(out.Bytes(), &v); err != nil { t.Fatalf("the verdict is not JSON: %v\n%s", err, out.String()) } } return code, v, errOut.String() } func encode(t *testing.T, r composer.Request) []byte { t.Helper() raw, err := json.Marshal(r) if err != nil { t.Fatal(err) } return raw } // 1621/AC1: the command reads the plain input and the manifests on standard input, validates every manifest, composes // the machines named and writes one verdict: per machine composes or the reason, per manifest accepted or the field // refused. func TestTheCommandWritesOneVerdictPerManifestAndMachine(t *testing.T) { r := request(t, composer.DepthResolve) r.Cases[0].Manifests["later"] = composer.Manifest{Raw: json.RawMessage(`{"module":"later","version":"1","shares":["x"]}`)} r.Cases[0].Manifests["refused"] = composer.Manifest{Raw: json.RawMessage(`{"module":"refused","version":"1"}`)} r.Cases[0].Verdicts = bucketstest.Raw(map[string]meshcatalog.VerdictsByDigestValue{"refused": {V: 1, Module: "refused", Judge: "src2:j", State: meshcatalogclient.VerdictRefused, Problems: []string{"it is wrong"}}}) code, v, stderr := runJSON(t, nil, encode(t, r)) if code != 0 { t.Fatalf("exit %d: %s", code, stderr) } if len(v.Cases) != 1 || v.Cases[0].Name != "trunk" || v.SDK == "" { t.Fatalf("verdict = %+v", v) } c := v.Cases[0] // ADR 0578 §5, §6: the composer judges nothing; it sets an unknown field aside and names it, and holds a manifest // its verdict refuses, named in the indexer's words. if got := c.Manifests["later"]; !got.Accepted || !strings.Contains(got.SetAside, `"shares"`) { t.Errorf("the manifest with an unknown field reads %+v, want accepted naming the field set aside", got) } if got := c.Manifests["refused"]; got.Accepted || !strings.Contains(got.Refused, "refused the manifest of refused: it is wrong") { t.Errorf("the refused manifest reads %+v, want refused in the verdict's words", got) } if got := c.Manifests["nats"]; !got.Accepted { t.Errorf("nats reads %+v, want accepted", got) } if len(c.Machines) != 3 { t.Fatalf("machines = %v, want the three named", c.Machines) } for name, m := range c.Machines { if !m.Composes && m.Reason == "" { t.Errorf("%s does not compose and says no reason", name) } } // Issue 1966, the group try of 2026-11-06 10:07: the composer judges against the seat list its request carries, the // node-engine's from the bus (ADR 0635 §1). The uplink's holder steps back from the resolver file for the resolver's // holder by the seat's definition; without the list nothing is judged (ADR 0636 §1), never "both declare the path". resolverMachine := func(withSeats bool) composer.Machine { r := composer.Request{V: composer.Version, Depth: composer.DepthCompose, HoldingsFromClaims: true, Machines: []string{"laptop"}, Cases: []composer.Case{{Name: "trunk", Manifests: captured(t)}}} if withSeats { r.Seats = seats(t) } r = withInput(t, r, compose.Input{Nodes: []compose.Node{{Name: "laptop", Assigned: []string{"networkmanager", "systemd-resolved", "pacman", "systemd", "dnsmasq"}, Capabilities: map[string]bool{"file-references": true, "privileged": true, "service-manager": true, "package-manager": true, "uplink-networkmanager": true}}}}) code, v, stderr := runJSON(t, nil, encode(t, r)) if code != 0 || len(v.Cases) != 1 { t.Fatalf("exit %d: %s", code, stderr) } return v.Cases[0].Machines["laptop"] } if m := resolverMachine(true); strings.Contains(m.Reason+strings.Join(m.Problems, " "), "both declare") || m.NotJudged != "" { t.Errorf("with the seat list, the uplink's and the resolver's holders on one machine: %+v, want the uplink's stepping back", m) } if m := resolverMachine(false); m.Composes || m.NotJudged != NoSeatList || m.Reason != "" || m.Blamed == nil { t.Errorf("without a seat list: %+v, want not judged, saying why, blaming none", m) } // Design 47 G §721, §733 (the node-engine's composer): a machine's verdict names the modules it blames, each with its // problem, and always writes blamed (A-469h). On a node composed as its node-engine composes it (ComposedHow), blamed is // the modules the change refuses that the node held neither in its read nor composing without the change (A-469j). file := func(module, path, content string) string { return `{"module": "` + module + `", "version": "1", "resources": [{"id": "f", "type": "file", "path": "` + path + `", "mode": "0600", "content": "` + content + `"}]}` } plain := func(module string) string { return `{"module": "` + module + `", "version": "1"}` } secret := `N=${secret:repository}\\n` search := map[string]string{"m1": plain("m1"), "m2": file("m2", "/var/lib/m2/env", secret), "m3": plain("m3")} for _, row := range []struct { name string manifests map[string]string assigned []string how *compose.ComposedHow tries int // the request's blame_tries blamed []blame // each module blamed, its problem holding the words given }{ // G-24 H-AC1: a fixture module whose manifest is refused on the machine is blamed by name. {"a module the change refuses is blamed by name", map[string]string{"app": file("app", "/var/lib/app/env", `N=${secret:repository}\\n`)}, []string{"app"}, &compose.ComposedHow{Node: "a", Builds: map[string]string{}}, 20, []blame{{Module: "app", Problem: "repository"}}}, // Held composing without the change (HeldBefore): left out of blamed. {"a module held before the change is not blamed", map[string]string{"app": file("app", "/var/lib/app/env", `N=${secret:repository}\\n`)}, []string{"app"}, &compose.ComposedHow{Node: "a", Builds: map[string]string{}, HeldBefore: map[string]string{"app": "held"}}, 0, []blame{}}, // G-24 H-AC2 (A-468l): two modules owning one path are both blamed, with that path. {"two modules owning one path are both blamed", map[string]string{"one": file("one", "/etc/shared.conf", "x"), "two": file("two", "/etc/shared.conf", "y")}, []string{"one", "two"}, &compose.ComposedHow{Node: "a", Builds: map[string]string{}}, 0, []blame{{Module: "one", Problem: `one and two both declare the path "/etc/shared.conf"`}, {Module: "two", Problem: `one and two both declare the path "/etc/shared.conf"`}}}, // The same, on a node whose input says not how it composes: nothing is held, both owners are blamed from the refusal. {"two path owners, composed without how the node composes", map[string]string{"one": file("one", "/etc/shared.conf", "x"), "two": file("two", "/etc/shared.conf", "y")}, []string{"one", "two"}, nil, 20, []blame{{Module: "one", Problem: `one and two both declare the path "/etc/shared.conf"`}, {Module: "two", Problem: `one and two both declare the path "/etc/shared.conf"`}}}, // G-24 H-AC5: a machine that fails with no module held is searched over the changed modules placed on it (here every // one, the input naming no manifest its builds were made of, A-469k), in assignment order; the search ends at the // first whose hold ends the problem, so m3 is never tried. {"the search ends at the first module whose hold ends the problem", search, []string{"m1", "m2", "m3"}, &compose.ComposedHow{Node: "a"}, 20, []blame{{Module: "m2", Problem: "repository"}}}, // A module whose case manifest is the one its build was made of is not changed (A-469k), so never held: m2's // problem is then no changed module's, and none is blamed. {"a module its build was made of is not tried", search, []string{"m1", "m2", "m3"}, &compose.ComposedHow{Node: "a", Manifests: map[string]string{"m2": digest(t, search["m2"])}}, 20, []blame{}}, // A-470v: a hold that changes the problem but leaves the machine not composing keeps that module held and blamed, // and the search goes on against the retry's problem: both modules the change refuses are blamed. {"every module the change refuses is blamed", map[string]string{"m1": file("m1", "/var/lib/m1/env", secret), "m2": file("m2", "/var/lib/m2/env", secret), "m3": plain("m3")}, []string{"m1", "m2", "m3"}, &compose.ComposedHow{Node: "a"}, 20, []blame{{Module: "m1", Problem: "repository"}, {Module: "m2", Problem: "repository"}}}, // G-24 H-AC4: past the request's blame_tries the modules not yet tried are named so. {"past blame_tries the untried are named", search, []string{"m1", "m2", "m3"}, &compose.ComposedHow{Node: "a"}, 1, []blame{{Module: "m2", Problem: composer.NotTried}, {Module: "m3", Problem: composer.NotTried}}}, // A-468i: a request with no blame_tries gets no search; the machine fails on the node's own account (H-AC3). {"a request with no blame_tries is not searched", search, []string{"m1", "m2", "m3"}, &compose.ComposedHow{Node: "a"}, 0, []blame{}}, // A-469j: one search, the composer's, inside the node-engine's composition (ComposeSent): an input that says not how // its node composes is composed without one, so its failure is the node's own. {"a node that says not how it composes is not searched", search, []string{"m1", "m2", "m3"}, nil, 20, []blame{}}, } { t.Run(row.name, func(t *testing.T) { r := composer.Request{V: composer.Version, Depth: composer.DepthCompose, Machines: []string{"a"}, Seats: seats(t), BlameTries: row.tries, Cases: []composer.Case{{Name: "change", Manifests: map[string]composer.Manifest{}}}} for name, raw := range row.manifests { r.Cases[0].Manifests[name] = composer.Manifest{Raw: json.RawMessage(raw)} } r = withInput(t, r, compose.Input{Nodes: []compose.Node{{Name: "a", Assigned: row.assigned}}, ComposedHow: row.how}) var out, errOut bytes.Buffer if code := run(nil, bytes.NewReader(encode(t, r)), &out, &errOut); code != 0 { t.Fatalf("exit %d: %s", code, errOut.String()) } if !strings.Contains(out.String(), `"blamed":`) { t.Errorf("the verdict writes no blamed: %s", out.String()) } var v composer.Verdict if err := json.Unmarshal(out.Bytes(), &v); err != nil { t.Fatal(err) } m := v.Cases[0].Machines["a"] if held := row.how != nil && row.how.HeldBefore != nil; m.Composes != held { t.Errorf("composes = %v, want %v: %+v", m.Composes, held, m) } if len(m.Blamed) != len(row.blamed) { t.Fatalf("blamed %+v, want %+v (%+v)", m.Blamed, row.blamed, m) } for i, b := range row.blamed { if m.Blamed[i].Module != b.Module || !strings.Contains(m.Blamed[i].Problem, b.Problem) { t.Errorf("blamed %+v, want %+v", m.Blamed, row.blamed) } } }) } } // digest is the content digest of a manifest (compose.ContentDigest). func digest(t *testing.T, raw string) string { t.Helper() d, err := compose.ContentDigest([]byte(raw)) if err != nil { t.Fatal(err) } return d } // blame is one module a machine's verdict blames (composer.Machine.Blamed). type blame = struct { Module string `json:"module"` Problem string `json:"problem"` } // 1621/AC3: over the captured catalogue and a mesh of three machines, the command's verdict equals, machine for // machine and manifest for manifest, what the linked reader, resolution and composition answer, at both depths. func TestTheCommandAnswersWhatTheLinkedCompositionAnswers(t *testing.T) { for _, depth := range []string{composer.DepthResolve, composer.DepthCompose} { r := request(t, depth) code, v, stderr := runJSON(t, nil, encode(t, r)) if code != 0 { t.Fatalf("%s: exit %d: %s", depth, code, stderr) } in := meshOf() in.Catalogue = map[string]catalogue.Manifest{} for name, m := range r.Cases[0].Manifests { // A request without a list of predefined keys reads a fallback as the indexer does (Request.Predefined). parsed, err := catalogue.Decode(m.Raw) got := v.Cases[0].Manifests[name] if (err == nil) != got.Accepted || (err != nil && err.Error() != got.Refused) { t.Errorf("%s: the manifest of %s: linked %v, command %+v", depth, name, err, got) } if err == nil { in.Catalogue[name] = parsed } } in.Holdings = composer.HoldingsOf(in.Catalogue, in.Nodes) composed := 0 for _, node := range r.Machines { got := v.Cases[0].Machines[node] var want composer.Machine if depth == composer.DepthResolve { if _, err := compose.Resolve(in, node); err != nil { want = composer.Machine{Reason: err.Error()} } else { want = composer.Machine{Composes: true} } } else { d, problems, err := compose.Compose(in, node) switch { case err != nil: want = composer.Machine{Reason: err.Error()} default: want = composer.Machine{Composes: len(problems) == 0, Problems: problems, Refusals: d.Refusals()} if len(problems) > 0 { want.Reason = "the node-engine's validator refuses the declaration" } } } // G-24 H-AC3 (§721): a machine that does not compose and blames no module (ace: its own sealing key) fails on the // node's own account, blamed written empty. want.Blamed = []blame{} if !reflect.DeepEqual(got, want) { t.Errorf("%s: %s: command %+v, linked %+v", depth, node, got, want) } if got.Composes { composed++ } else { t.Logf("%s: %s does not compose: %s %v", depth, node, got.Reason, got.Problems) } } t.Logf("%s: %d of %d machines compose", depth, composed, len(r.Machines)) } } // 1621 note 6: a person composes a catalogue checkout (repository@ref checked out or archived: the command fetches // nothing) for a node and reads its declaration: each path with its kind, owner and mode. func TestACatalogueCheckoutIsComposedForANode(t *testing.T) { dir := t.TempDir() if err := os.MkdirAll(filepath.Join(dir, "modules", "demo"), 0o755); err != nil { t.Fatal(err) } manifest := `{"module": "demo", "version": "1", "resources": [{"id": "state", "type": "directory", ` + `"path": "/var/lib/demo", "mode": "0750", "owner": "root"}]}` if err := os.WriteFile(filepath.Join(dir, "modules", "demo", "module.json"), []byte(manifest), 0o644); err != nil { t.Fatal(err) } in := encode(t, withInput(t, composer.Request{V: composer.Version, Seats: seats(t)}, compose.Input{Nodes: []compose.Node{{Name: "laptop", Assigned: []string{"demo"}}}})) code, v, stderr := runJSON(t, []string{"-catalogue", dir, "-node", "laptop", "-declarations"}, in) if code != 0 { t.Fatalf("exit %d: %s", code, stderr) } m := v.Cases[0].Machines["laptop"] want := []composer.Path{{Path: "/var/lib/demo", Kind: "directory", Owner: "root", Mode: "0750", Module: ""}} if !m.Composes || len(m.Declared) != 1 || m.Declared[0].Path != want[0].Path || m.Declared[0].Mode != "0750" || m.Declared[0].Owner != "root" || m.Declared[0].Kind != "directory" { t.Fatalf("laptop = %+v, want it composed declaring %+v", m, want) } } // A run step hands the command no standard input: the request is read from the file -request names, or from the one // MESH_RUN_INPUT names, and a file that is not there is a request it cannot read. func TestTheRequestIsReadFromAFile(t *testing.T) { file := filepath.Join(t.TempDir(), "request.json") r := composer.Request{V: composer.Version, Cases: []composer.Case{{Name: "only", Manifests: map[string]composer.Manifest{ "demo": {Raw: json.RawMessage(`{"module":"demo","version":"1"}`)}}}}} if err := os.WriteFile(file, encode(t, r), 0o600); err != nil { t.Fatal(err) } code, v, stderr := runJSON(t, []string{"-request", file}, nil) if code != 0 || len(v.Cases) != 1 || !v.Cases[0].Manifests["demo"].Accepted { t.Fatalf("exit %d (%s), verdict %+v", code, stderr, v) } if code, _, stderr := runJSON(t, []string{"-request", file + ".gone"}, nil); code != 1 || !strings.Contains(stderr, "cannot be read") { t.Errorf("a request file that is not there: exit %d, %q", code, stderr) } // A pipeline step names its input file in MESH_RUN_INPUT: the command reads the request there and the verdict is the // last line of standard output (design 47 G A-167). r.Depth = composer.DepthCompose if err := os.WriteFile(file, encode(t, r), 0o600); err != nil { t.Fatal(err) } t.Setenv("MESH_RUN_INPUT", file) var out, errOut bytes.Buffer if code := run(nil, bytes.NewReader(nil), &out, &errOut); code != 0 { t.Fatalf("exit %d: %s", code, errOut.String()) } lines := strings.Split(strings.TrimRight(out.String(), "\n"), "\n") v = composer.Verdict{} if err := json.Unmarshal([]byte(lines[len(lines)-1]), &v); err != nil || len(v.Cases) != 1 || !v.Cases[0].Manifests["demo"].Accepted { t.Fatalf("last line is no verdict: %v\n%s", err, out.String()) } t.Setenv("MESH_RUN_INPUT", file+".gone") if code := run(nil, bytes.NewReader(nil), &out, &errOut); code != 1 || !strings.Contains(errOut.String(), "cannot be read") { t.Errorf("a missing input file: exit %d, %q", code, errOut.String()) } } // The exit codes: 1 for a request that cannot be read or run, 2 for wrong flags, each said on standard error. func TestTheExitCodesSayWhatFailed(t *testing.T) { unfilled := encode(t, composer.Request{V: composer.Version, Cases: []composer.Case{{Name: "c", Manifests: map[string]composer.Manifest{"x": {Digest: "abc"}}}}}) for _, c := range []struct { name string args []string in string code int says string }{ {"not JSON", nil, "{", 1, "not JSON"}, {"another version", nil, `{"v":2}`, 1, "version 2"}, {"a digest left unfilled", nil, string(unfilled), 1, "digest"}, {"an unknown depth", nil, `{"v":1,"depth":"deep"}`, 1, "depth"}, {"nothing to read", nil, "", 1, "no request"}, {"a wrong flag", []string{"-nope"}, "", 2, "nope"}, {"an argument", []string{"extra"}, "", 2, "unexpected"}, } { var out, errOut bytes.Buffer if got := run(c.args, strings.NewReader(c.in), &out, &errOut); got != c.code || !strings.Contains(errOut.String(), c.says) { t.Errorf("%s: exit %d saying %q, want %d saying %q", c.name, got, errOut.String(), c.code, c.says) } } } // ownPackages is every package of this repository the command imports, directly or not, with the packages each // imports: what this repository adds to the composition; mesh-sdk's packages are judged in mesh-sdk. func ownPackages(t *testing.T) map[string][]string { t.Helper() _, file, _, _ := runtime.Caller(0) root := filepath.Join(filepath.Dir(file), "..", "..") const module = "github.com/novox/mesh-host" out := map[string][]string{} var walk func(path string) walk = func(path string) { if _, done := out[path]; done { return } rel := strings.TrimPrefix(strings.TrimPrefix(path, module), "/") pkg, err := build.Default.ImportDir(filepath.Join(root, rel), 0) if err != nil { t.Fatalf("%s: %v", path, err) } out[path] = pkg.Imports for _, imp := range pkg.Imports { if strings.HasPrefix(imp, module+"/") { walk(imp) } } } walk(composer.Package) return out } // 1621/AC2 and AC4: the command imports, through every package of this repository it reaches, only the standard // library, mesh-sdk, the contracts modules' pure packages (seats' types, clients' codecs), the delivery SDK's composer (the command's own request and verdict types) and catalog key codec (a catalog entry's key, design 47 G A-144), the builder's builds package (a build's value and its keys), the private network's overlay package (mesh-wireguard's own pure package: names, graph and // generator, no bus) and this repository's own packages, and none that reaches a bus, a store, a network service or // another process. func TestTheCommandImportsNoBusStoreNetworkOrProcess(t *testing.T) { forbidden := []string{"net/http", "net/rpc", "net/smtp", "os/exec", "database/sql", "plugin", "syscall"} own := ownPackages(t) if len(own) < 4 { t.Fatalf("the command reaches %d packages of this repository; the walk found too few to judge", len(own)) } for path, imports := range own { for _, imp := range imports { std := !strings.Contains(strings.SplitN(imp, "/", 2)[0], ".") if !std && !strings.HasPrefix(imp, "git.novox.be/novox/mesh-networking/modules/mesh-wireguard/go/overlay") && !strings.HasPrefix(imp, "git.novox.be/novox/mesh-sdk/go") && !strings.HasPrefix(imp, "git.novox.be/novox/mesh-contracts/") && !strings.HasPrefix(imp, "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/") && !strings.HasPrefix(imp, "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/composer") && imp != "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/catalogkey" && !strings.HasPrefix(imp, "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds") && !strings.HasPrefix(imp, "github.com/novox/mesh-host/") { t.Errorf("%s imports %s, which is neither the standard library, mesh-sdk nor this repository", path, imp) } for _, f := range forbidden { if imp == f { t.Errorf("%s imports %s", path, imp) } } } } } // 1621/AC2: run with an empty network namespace, the command still writes its verdict: it needs no network. The test // runs its own binary again under `unshare --net` as an unprivileged user's namespace; where the kernel or the sandbox // allows no new namespace (a build module's run step is already one with no network), it says so and skips. func TestTheCommandRunsWithNoNetwork(t *testing.T) { if os.Getenv("MESH_COMPOSE_HELPER") == "1" { os.Exit(run(nil, os.Stdin, os.Stdout, os.Stderr)) } unshare, err := exec.LookPath("unshare") if err != nil { t.Skip("no unshare on this machine, so no empty network namespace can be made here") } if out, err := exec.Command(unshare, "--net", "--map-root-user", "true").CombinedOutput(); err != nil { t.Skipf("this machine makes no unprivileged network namespace (%v: %s); a run step's own has no network", err, out) } r := request(t, composer.DepthResolve) cmd := exec.Command(unshare, "--net", "--map-root-user", os.Args[0], "-test.run=^TestTheCommandRunsWithNoNetwork$") cmd.Env = []string{"MESH_COMPOSE_HELPER=1"} cmd.Stdin = bytes.NewReader(encode(t, r)) var out, errOut bytes.Buffer cmd.Stdout, cmd.Stderr = &out, &errOut if err := cmd.Run(); err != nil { t.Fatalf("the command in an empty network namespace: %v: %s", err, errOut.String()) } var v composer.Verdict if err := json.Unmarshal(out.Bytes(), &v); err != nil || len(v.Cases) != 1 || len(v.Cases[0].Machines) != 3 { t.Fatalf("no verdict from the command with no network: %v\n%s", err, out.String()) } names := make([]string, 0, len(v.Cases[0].Machines)) for n := range v.Cases[0].Machines { names = append(names, n) } sort.Strings(names) t.Logf("composed with no network: %v", names) }