package architecture import ( "go/parser" "go/token" "io/fs" "path/filepath" "strconv" "strings" "testing" ) // Keep the reusable domain independent of transport and session ownership. func TestSecondFactorDomainBoundary(t *testing.T) { err := filepath.WalkDir("../twofactor", func(path string, d fs.DirEntry, err error) error { if err != nil { return err } if d.IsDir() { if d.Name() == "http" { return filepath.SkipDir } return nil } if !strings.HasSuffix(path, ".go") || strings.HasSuffix(path, "_test.go") { return nil } file, err := parser.ParseFile(token.NewFileSet(), path, nil, parser.ImportsOnly) if err != nil { return err } for _, im := range file.Imports { name, err := strconv.Unquote(im.Path.Value) if err != nil { return err } for _, blocked := range []string{"/product/auth/", "/product/sessions/", "/jwtauth", "/jwt/"} { if strings.Contains(name, blocked) { t.Errorf("2FA domain imports operation/transport dependency %s in %s", name, path) } } } return nil }) if err != nil { t.Fatal(err) } }