carlos / platform Public

Clone
git clone https://amadan.net/carlos/platform

Plain git — no account needed to clone.

Download

Download this file

1package provision
2
3import (
4 "bytes"
5 "os"
6 "os/exec"
7 "strings"
8 "testing"
9)
10
11// TestRootBinaryLinksNoConsoleOrMail pins the basis of
12// census-ruling-console-invite-delivery R1 (platform-1e;
13// docs/superpowers/notes/census-proposal-console-invite-delivery.md): the
14// root carlos binary (the package at the repo root) links neither
15// internal/console nor internal/mail, so the console's units in that overlay
16// never run as root. go list -deps names the package's non-test imports,
17// direct and indirect, for each GOOS the release builds.
18func TestRootBinaryLinksNoConsoleOrMail(t *testing.T) {
19 goBin, err := exec.LookPath("go")
20 if err != nil {
21 t.Skip("go not on PATH")
22 }
23 root := censusRoot(t)
24 banned := []string{
25 "github.com/carlosframework/platform/internal/console",
26 "github.com/carlosframework/platform/internal/mail",
27 }
28 for _, goos := range []string{"linux", "darwin", "windows"} {
29 cmd := exec.Command(goBin, "list", "-deps", "-f", "{{.ImportPath}}", ".")
30 cmd.Dir = root
31 cmd.Env = append(os.Environ(), "GOOS="+goos, "CGO_ENABLED=0")
32 var stderr bytes.Buffer
33 cmd.Stderr = &stderr
34 out, err := cmd.Output()
35 if err != nil {
36 t.Fatalf("go list -deps . (GOOS=%s): %v: %s", goos, err, stderr.String())
37 }
38 deps := map[string]bool{}
39 for _, line := range strings.Split(string(out), "\n") {
40 deps[strings.TrimSpace(line)] = true
41 }
42 if !deps["github.com/carlosframework/platform"] {
43 t.Fatalf("go list -deps . (GOOS=%s) did not list the root package itself", goos)
44 }
45 for _, pkg := range banned {
46 if deps[pkg] {
47 t.Errorf("GOOS=%s: the root carlos binary links %s; census-ruling-console-invite-delivery R1 assumed it does not", goos, pkg)
48 }
49 for dep := range deps {
50 if strings.HasPrefix(dep, pkg+"/") {
51 t.Errorf("GOOS=%s: the root carlos binary links %s, under %s", goos, dep, pkg)
52 }
53 }
54 }
55 }
56}
57