package buildstep import ( "go/parser" "go/token" "os/exec" "path/filepath" "strconv" "strings" "testing" ) // The layouts, keys and codecs of this package are read by modules that never touch the bus (a composer's tool, the // builder's published package): it imports neither the bus library nor mesh-sdk's runtime (the root package), whose // part that runs is package buildrun's. func TestThePackageIsFreeOfTheBus(t *testing.T) { files, _ := filepath.Glob("*.go") fset := token.NewFileSet() for _, f := range files { if strings.HasSuffix(f, "_test.go") { continue } parsed, err := parser.ParseFile(fset, f, nil, parser.ImportsOnly) if err != nil { t.Fatal(err) } for _, imp := range parsed.Imports { path, _ := strconv.Unquote(imp.Path.Value) if strings.HasPrefix(path, "github.com/nats-io/") || path == "git.novox.be/novox/mesh-sdk/go" { t.Errorf("%s imports %s, which reaches the bus", f, path) } } } // Nor through a package it imports: a mesh-sdk package that came to import the bus library (buscalls' seat chunks) took // the builder's published package onto the bus through this one (join 11). out, err := exec.Command("go", "list", "-deps", ".").Output() if err != nil { t.Fatalf("go list: %v", err) } for _, p := range strings.Fields(string(out)) { if strings.HasPrefix(p, "github.com/nats-io/") { t.Errorf("buildstep depends on %s", p) } } }