The seats, holdings, source, build-source, delivery group check, check request, backup plan, adoption (take and converge) and the network graph now read the rest of the mesh through restOfTheMesh and compose.Graph. compose_callers_test.go scans the package and names any function other than the old composition's own that still calls planFor, declarationWith, composedAndValidated, generators, renderingFor, theRestOfTheMesh or whoResolves; issue 1389 deletes those.
64 lines
2.0 KiB
Go
64 lines
2.0 KiB
Go
package main
|
|
|
|
import (
|
|
"go/ast"
|
|
"go/parser"
|
|
"go/token"
|
|
"path/filepath"
|
|
"sort"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// 1388: no caller composes through the controller's own composition any more. The only functions left that call it are the
|
|
// composition's own, which issue 1389 deletes with it; this fails the moment any other function reaches for it again.
|
|
func TestNoCallerComposesThroughTheControllersOwnComposition(t *testing.T) {
|
|
legacy := map[string]bool{"planFor": true, "declarationWith": true, "composedAndValidated": true, "generators": true,
|
|
"renderingFor": true, "theRestOfTheMesh": true, "whoResolves": true}
|
|
// The composition's own pairs, until 1389: "file: caller calls callee".
|
|
allowed := map[string]bool{
|
|
"facts.go: composedAndValidated calls declarationWith": true,
|
|
"facts.go: composedAndValidated calls planFor": true,
|
|
"network.go: generators calls whoResolves": true,
|
|
"network.go: whoResolves calls planFor": true,
|
|
"plan.go: declarationWith calls renderingFor": true,
|
|
"plan.go: grantsFor calls planFor": true,
|
|
"plan.go: planFor calls theRestOfTheMesh": 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 || 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 && legacy[id.Name] {
|
|
found = append(found, f+": "+fn.Name.Name+" calls "+id.Name)
|
|
}
|
|
}
|
|
return true
|
|
})
|
|
}
|
|
}
|
|
sort.Strings(found)
|
|
for _, pair := range found {
|
|
if !allowed[pair] {
|
|
t.Errorf("%s: it composes through the controller's own composition, not mesh-sdk's", pair)
|
|
}
|
|
}
|
|
}
|