package nats import ( "go/parser" "go/token" "path/filepath" "strconv" "strings" "testing" ) func TestInfrastructureDoesNotImportApplication(t *testing.T) { files, err := filepath.Glob("*.go") if err != nil { t.Fatal(err) } for _, path := range files { if strings.HasSuffix(path, "_test.go") { continue } file, err := parser.ParseFile(token.NewFileSet(), path, nil, parser.ImportsOnly) if err != nil { t.Fatal(err) } for _, imported := range file.Imports { name, err := strconv.Unquote(imported.Path.Value) if err != nil { t.Fatal(err) } if strings.Contains(name, "/internal/app/") { t.Errorf("%s imports application package %q", path, name) } } } }