oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1package equipotest
2
3import (
4 "go/parser"
5 "go/token"
6 "io/fs"
7 "path/filepath"
8 "strconv"
9 "strings"
10 "testing"
11)
12
13func TestCoreHasNoPlatformDependency(t *testing.T) {
14 const localTeam = "amadan.net/oficina/equipo/internal/equipo/team"
15 required := map[string]bool{
16 "teamcontract/authority_test.go": false,
17 "teamcontract/policy_test.go": false,
18 }
19 root := filepath.Join("..", "equipo")
20 for _, dir := range []string{"team", "teamcontract"} {
21 files := 0
22 err := filepath.WalkDir(filepath.Join(root, dir), func(path string, entry fs.DirEntry, err error) error {
23 if err != nil {
24 return err
25 }
26 if entry.IsDir() || !strings.HasSuffix(path, ".go") {
27 return nil
28 }
29 files++
30 file, err := parser.ParseFile(token.NewFileSet(), path, nil, parser.ImportsOnly)
31 if err != nil {
32 return err
33 }
34 rel, err := filepath.Rel(root, path)
35 if err != nil {
36 return err
37 }
38 rel = filepath.ToSlash(rel)
39 for _, spec := range file.Imports {
40 importPath, err := strconv.Unquote(spec.Path.Value)
41 if err != nil {
42 return err
43 }
44 for _, part := range strings.Split(importPath, "/") {
45 if part == "platform" || part == "suite" {
46 t.Errorf("%s: forbidden import %q", rel, importPath)
47 }
48 }
49 if _, ok := required[rel]; ok && importPath == localTeam {
50 required[rel] = true
51 }
52 }
53 return nil
54 })
55 if err != nil {
56 t.Errorf("read %s imports: %v", dir, err)
57 }
58 if files == 0 {
59 t.Errorf("%s: no Go files found", dir)
60 }
61 }
62 for path, found := range required {
63 if !found {
64 t.Errorf("%s must import %q", path, localTeam)
65 }
66 }
67}
68