package provision import ( "bytes" "os" "os/exec" "strings" "testing" ) // TestRootBinaryLinksNoConsoleOrMail pins the basis of // census-ruling-console-invite-delivery R1 (platform-1e; // docs/superpowers/notes/census-proposal-console-invite-delivery.md): the // root carlos binary (the package at the repo root) links neither // internal/console nor internal/mail, so the console's units in that overlay // never run as root. go list -deps names the package's non-test imports, // direct and indirect, for each GOOS the release builds. func TestRootBinaryLinksNoConsoleOrMail(t *testing.T) { goBin, err := exec.LookPath("go") if err != nil { t.Skip("go not on PATH") } root := censusRoot(t) banned := []string{ "github.com/carlosframework/platform/internal/console", "github.com/carlosframework/platform/internal/mail", } for _, goos := range []string{"linux", "darwin", "windows"} { cmd := exec.Command(goBin, "list", "-deps", "-f", "{{.ImportPath}}", ".") cmd.Dir = root cmd.Env = append(os.Environ(), "GOOS="+goos, "CGO_ENABLED=0") var stderr bytes.Buffer cmd.Stderr = &stderr out, err := cmd.Output() if err != nil { t.Fatalf("go list -deps . (GOOS=%s): %v: %s", goos, err, stderr.String()) } deps := map[string]bool{} for _, line := range strings.Split(string(out), "\n") { deps[strings.TrimSpace(line)] = true } if !deps["github.com/carlosframework/platform"] { t.Fatalf("go list -deps . (GOOS=%s) did not list the root package itself", goos) } for _, pkg := range banned { if deps[pkg] { t.Errorf("GOOS=%s: the root carlos binary links %s; census-ruling-console-invite-delivery R1 assumed it does not", goos, pkg) } for dep := range deps { if strings.HasPrefix(dep, pkg+"/") { t.Errorf("GOOS=%s: the root carlos binary links %s, under %s", goos, dep, pkg) } } } } }