package main import ( "go/ast" "go/parser" "go/token" "path/filepath" "sort" "strings" "testing" ) // 1389: the controller's own composition is gone. No function of the package is named for it any more, and no function // calls one by that name: a name reappearing is a second copy of what mesh-sdk's go/compose holds (novox/hq ADR 0453). func TestTheControllersOwnCompositionIsGone(t *testing.T) { gone := map[string]bool{"planFor": true, "declarationWith": true, "composedAndValidated": true, "generators": true, "renderingFor": true, "theRestOfTheMesh": true, "whoResolves": true, "grantsFor": true, "namesInTheMesh": true, "onThePrivateNetwork": true, "passSeatsOn": true, "theMeshPassesSeatsOn": true, "assignmentsOf": true, "licencesFor": true, "seatsOn": true, "composeBusUsers": true, "adoptionFor": true, "localNetworksOf": true} files, err := filepath.Glob("*.go") if err != nil { t.Fatal(err) } fset := token.NewFileSet() var found []string for _, f := range files { if strings.HasSuffix(f, "_test.go") { continue } file, err := parser.ParseFile(fset, f, nil, 0) if err != nil { t.Fatal(err) } for _, d := range file.Decls { fn, ok := d.(*ast.FuncDecl) if !ok { continue } if gone[fn.Name.Name] { found = append(found, f+": "+fn.Name.Name+" is declared") } if fn.Body == nil { continue } ast.Inspect(fn.Body, func(n ast.Node) bool { if c, ok := n.(*ast.CallExpr); ok { if id, ok := c.Fun.(*ast.Ident); ok && gone[id.Name] { found = append(found, f+": "+fn.Name.Name+" calls "+id.Name) } } return true }) } } sort.Strings(found) for _, one := range found { t.Errorf("%s: the controller's own composition is back; compose through mesh-sdk (compose_sdk.go)", one) } }