From b8a27d3d99bbf1eaf711ce816e1d4148fc135197 Mon Sep 17 00:00:00 2001 From: Jamie Tanna Date: Mon, 4 May 2026 14:15:29 +0100 Subject: [PATCH] test: don't allow `interface{}` types As noted in PRF-1956, we had some types that are defined as aliases of `interface{}`, which reduce the type safety for our users. To avoid this happening again, we can introduce a test to validate these do not return again. Co-authored-by: Claude Sonnet 4.6 --- generated_test.go | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 generated_test.go diff --git a/generated_test.go b/generated_test.go new file mode 100644 index 0000000..c722a3f --- /dev/null +++ b/generated_test.go @@ -0,0 +1,37 @@ +package rootly + +import ( + "go/ast" + "go/parser" + "go/token" + "testing" +) + +func TestNoInterfaceTypeAliases(t *testing.T) { + fset := token.NewFileSet() + f, err := parser.ParseFile(fset, "schema.gen.go", nil, 0) + if err != nil { + t.Fatalf("failed to parse schema.gen.go: %v", err) + } + + for _, decl := range f.Decls { + genDecl, ok := decl.(*ast.GenDecl) + if !ok || genDecl.Tok != token.TYPE { + continue + } + for _, spec := range genDecl.Specs { + typeSpec, ok := spec.(*ast.TypeSpec) + if !ok || !typeSpec.Assign.IsValid() { + continue + } + + t.Run(typeSpec.Name.Name+" should not be an interface{}", func(t *testing.T) { + iface, ok := typeSpec.Type.(*ast.InterfaceType) + + if ok && iface.Methods.NumFields() == 0 { + t.Fail() + } + }) + } + } +}