Download this file
| 1 | package guards |
| 2 | |
| 3 | import ( |
| 4 | "strings" |
| 5 | "testing" |
| 6 | ) |
| 7 | |
| 8 | // sealtestImport is the plaintext-gate test helper package. Its own doc |
| 9 | // comment already says this — "this package must never be imported from |
| 10 | // non-test code: doing so would drag the testing package into the |
| 11 | // production binary" — but until now that rested on the comment alone. |
| 12 | const sealtestImport = "amadan.net/oficina/sheets/internal/sheets/sealtest" |
| 13 | |
| 14 | // TestSealtestOnlyImportedByTests fails on any non-_test.go file that |
| 15 | // imports sealtest. |
| 16 | func TestSealtestOnlyImportedByTests(t *testing.T) { |
| 17 | root := repoRoot(t) |
| 18 | for _, path := range goFiles(t, root) { |
| 19 | if strings.HasSuffix(path, "_test.go") { |
| 20 | continue |
| 21 | } |
| 22 | rel := relPath(t, root, path) |
| 23 | for _, imp := range fileImports(t, path) { |
| 24 | if imp == sealtestImport { |
| 25 | t.Errorf("%s: imports %q from non-test code (sealtest containment: sealtest imports testing, so it must stay test-only)", rel, sealtestImport) |
| 26 | } |
| 27 | } |
| 28 | } |
| 29 | } |
| 30 | |