package equipotest import ( "go/parser" "go/token" "io/fs" "path/filepath" "strconv" "strings" "testing" ) func TestCoreHasNoPlatformDependency(t *testing.T) { const localTeam = "amadan.net/oficina/equipo/internal/equipo/team" required := map[string]bool{ "teamcontract/authority_test.go": false, "teamcontract/policy_test.go": false, } root := filepath.Join("..", "equipo") for _, dir := range []string{"team", "teamcontract"} { files := 0 err := filepath.WalkDir(filepath.Join(root, dir), func(path string, entry fs.DirEntry, err error) error { if err != nil { return err } if entry.IsDir() || !strings.HasSuffix(path, ".go") { return nil } files++ file, err := parser.ParseFile(token.NewFileSet(), path, nil, parser.ImportsOnly) if err != nil { return err } rel, err := filepath.Rel(root, path) if err != nil { return err } rel = filepath.ToSlash(rel) for _, spec := range file.Imports { importPath, err := strconv.Unquote(spec.Path.Value) if err != nil { return err } for _, part := range strings.Split(importPath, "/") { if part == "platform" || part == "suite" { t.Errorf("%s: forbidden import %q", rel, importPath) } } if _, ok := required[rel]; ok && importPath == localTeam { required[rel] = true } } return nil }) if err != nil { t.Errorf("read %s imports: %v", dir, err) } if files == 0 { t.Errorf("%s: no Go files found", dir) } } for path, found := range required { if !found { t.Errorf("%s must import %q", path, localTeam) } } }