34 lines
943 B
Go
34 lines
943 B
Go
package buildstep
|
|
|
|
import (
|
|
"go/parser"
|
|
"go/token"
|
|
"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)
|
|
}
|
|
}
|
|
}
|
|
}
|