42 lines
1.0 KiB
Go
42 lines
1.0 KiB
Go
package architecture
|
|
|
|
import (
|
|
"go/parser"
|
|
"go/token"
|
|
"io/fs"
|
|
"path/filepath"
|
|
"strconv"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestGenericRuntimeDoesNotInstallConcreteContracts(t *testing.T) {
|
|
for _, dir := range []string{"../app/runtime", "../app/http"} {
|
|
err := filepath.WalkDir(dir, func(path string, entry fs.DirEntry, err error) error {
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if entry.IsDir() || !strings.HasSuffix(path, ".go") || strings.HasSuffix(path, "_test.go") {
|
|
return nil
|
|
}
|
|
file, err := parser.ParseFile(token.NewFileSet(), path, nil, parser.ImportsOnly)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
for _, im := range file.Imports {
|
|
name, err := strconv.Unquote(im.Path.Value)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if strings.Contains(name, "/http/v") || strings.Contains(name, "/app/api/v") || strings.HasSuffix(name, "/app/profile") {
|
|
t.Errorf("generic runtime imports a concrete API contract: %s in %s", name, path)
|
|
}
|
|
}
|
|
return nil
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
}
|