75 lines
2.7 KiB
Go
75 lines
2.7 KiB
Go
package lint
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// What this repository no longer holds (R4g, design 47 acceptance test 24): the checker runs the build module's own steps
|
|
// and the repository's tests, so no script of the repository stands in for them. A file named here came back.
|
|
|
|
// root is this repository's root, from the package's directory.
|
|
const root = "../.."
|
|
|
|
func TestTheRepositoryHoldsNoMergeCheckScript(t *testing.T) {
|
|
for _, name := range []string{"merge-check.sh", "check-nested-modules.sh", "RELEASE-57.md", "testdata/store-tests"} {
|
|
if _, err := os.Stat(filepath.Join(root, name)); err == nil {
|
|
t.Errorf("%s is in the repository: the checker (ADR 0501 §5) runs its steps, and no script of the repository "+
|
|
"stands in for it", name)
|
|
}
|
|
}
|
|
}
|
|
|
|
// sources are the controller's own Go files that are not tests: what the controller does, not what a test stands in for.
|
|
func sources(t *testing.T) map[string]string {
|
|
t.Helper()
|
|
out := map[string]string{}
|
|
err := filepath.WalkDir(root, func(path string, d os.DirEntry, err error) error {
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if d.IsDir() && (d.Name() == ".git" || d.Name() == "testdata" || d.Name() == "vendor") {
|
|
return filepath.SkipDir
|
|
}
|
|
if d.IsDir() || !strings.HasSuffix(path, ".go") || strings.HasSuffix(path, "_test.go") {
|
|
return nil
|
|
}
|
|
raw, err := os.ReadFile(path)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
out[path] = string(raw)
|
|
return nil
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return out
|
|
}
|
|
|
|
// The controller's tree holds no reference to a container runtime for a build (R4g, issue 1851): no socket of one, and no
|
|
// program run to build, pull or export an image. Builds are the build modules' (ADR 0501).
|
|
func TestTheControllerHoldsNoContainerRuntimeForABuild(t *testing.T) {
|
|
for path, src := range sources(t) {
|
|
for _, word := range []string{"docker.sock", `exec.Command("docker"`, `"docker", "pull"`, `"docker", "run"`, "buildah", "podman"} {
|
|
if strings.Contains(src, word) {
|
|
t.Errorf("%s names %s: a build runs on a build module, never through the controller", path, word)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// No file of the controller names the forge's statuses of the retired merge check (issue 1299, issue 1318): a pull request
|
|
// into any repository asks the controller nothing, and the checker's `mesh/check` is the only status it need name.
|
|
func TestNoFileOfTheControllerNamesTheRetiredMergeStatuses(t *testing.T) {
|
|
for path, src := range sources(t) {
|
|
for _, word := range []string{"mesh/merge-gate", "mesh/repo-check", "StatusContextGate", "StatusContextRepoCheck"} {
|
|
if strings.Contains(src, word) {
|
|
t.Errorf("%s names %s, which the controller no longer asks, says or judges", path, word)
|
|
}
|
|
}
|
|
}
|
|
}
|