package architecture import ( "go/ast" "go/parser" "go/token" "io/fs" "path/filepath" "strings" "testing" ) func TestLocalCustomerModelHasNoPlatformTenancy(t *testing.T) { // Local customer models and storage must stay free of provider tenancy. forbidden := map[string]bool{"organization": true, "organizationref": true, "orgref": true, "orgdb": true, "role": true, "roles": true, "roledescription": true, "rolemanager": true, "policy": true, "policies": true, "policydescription": true, "policydb": true, "permissionbound": true, "signup_provisioning": true} err := filepath.WalkDir("../..", func(path string, entry fs.DirEntry, err error) error { if err != nil { return err } if entry.IsDir() || filepath.Ext(path) != ".go" || strings.HasSuffix(path, "_test.go") { return nil } parsed, err := parser.ParseFile(token.NewFileSet(), path, nil, 0) if err != nil { return err } ast.Inspect(parsed, func(node ast.Node) bool { var names []*ast.Ident switch n := node.(type) { case *ast.TypeSpec: names = []*ast.Ident{n.Name} case *ast.Field: names = n.Names } for _, name := range names { if forbidden[strings.ToLower(name.Name)] { t.Errorf("%s reintroduces local platform tenancy: %s", path, name.Name) } } return true }) return nil }) if err != nil { t.Fatal(err) } }