package main import ( "go/ast" "go/parser" "go/token" "testing" ) // Keep the executable's production composition wired through server.Dependencies, // rather than relying only on unit tests that inject a fake ranker. func TestProductionCompositionSuppliesLayaRankerToServerDependencies(t *testing.T) { file, err := parser.ParseFile(token.NewFileSet(), "main.go", nil, 0) if err != nil { t.Fatal(err) } found := false ast.Inspect(file, func(node ast.Node) bool { literal, ok := node.(*ast.CompositeLit) if !ok { return true } selector, ok := literal.Type.(*ast.SelectorExpr) if !ok || selector.Sel.Name != "Dependencies" { return true } for _, element := range literal.Elts { kv, ok := element.(*ast.KeyValueExpr) if ok { if key, ok := kv.Key.(*ast.Ident); ok && key.Name == "LayaRanker" { found = true } } } return true }) if !found { t.Fatal("cmd/server main does not pass a LayaRanker through server.Dependencies") } }