package guards import ( "testing" ) // excelizeImport is the XLSX library's import path. const excelizeImport = "github.com/xuri/excelize/v2" // excelizeHome is the package tree allowed to import it — xlsx itself // and any subpackage of it. Matched as a tree, not by exact directory // equality: equality would make a future xlsx subpackage look like it // was outside home and wrongly forbid it from importing excelize (the // over-strict direction — a false positive, not a leak — but still // wrong). Confining excelize's quirks to this one tree keeps the XLSX // format's weirdness from leaking into the rest of Sheets. const excelizeHome = "internal/sheets/xlsx" // TestExcelizeConfinedToXLSXPackage fails on any excelize import outside // the internal/sheets/xlsx tree. func TestExcelizeConfinedToXLSXPackage(t *testing.T) { root := repoRoot(t) for _, path := range goFiles(t, root) { rel := relPath(t, root, path) if inTree(rel, excelizeHome) { continue } for _, imp := range fileImports(t, path) { if imp == excelizeImport { t.Errorf("%s: imports %q, confined to %s (excelize confinement)", rel, excelizeImport, excelizeHome) } } } }