package failurekit import ( "os" "path/filepath" "testing" ) // 1901/AC7 and 1890/AC8: a build module with a test step and no kit is refused, one that runs the kit passes, one with no // test step is exempt from the failure cases but not from the left-running case, a module that runs only the failure // cases is refused, and a module that claims no node-build-* seat is not judged. func TestABuildModuleWithATestStepMustRunTheKit(t *testing.T) { root := t.TempDir() const imp = "package main\n\nimport \"git.novox.be/novox/mesh-sdk/go/buildstep/conformance\"\n\n" const sweep = "func TestSweep(t *testing.T) { conformance.LeftRunning(t, nil) }\n" kit := imp + "func TestKit(t *testing.T) { conformance.Run(t, conformance.GoTest, nil) }\n" + sweep for path, body := range map[string]string{ "modules/a/module.json": `{"claims":[{"name":"node-build-a"}],"tools":["build_a_fetch","build_a_test"]}`, "modules/a/cmd/a/check_test.go": "package main\n", "modules/b/module.json": `{"claims":[{"name":"node-build-b"}],"tools":[{"name":"build_b_test"}]}`, "modules/b/cmd/b/kit_test.go": kit, "modules/c/module.json": `{"claims":[{"name":"node-build-c"}],"tools":["build_c_build"]}`, "modules/c/cmd/c/kit_test.go": imp + sweep, "modules/f/module.json": `{"claims":[{"name":"node-build-f"}],"tools":["build_f_build"]}`, "modules/g/module.json": `{"claims":[{"name":"node-build-g"}],"tools":["build_g_test"]}`, "modules/g/cmd/g/kit_test.go": imp + "func TestKit(t *testing.T) { conformance.Run(t, conformance.GoTest, nil) }\n", "modules/d/module.json": `{"claims":[{"name":"other"}],"tools":["d_test"]}`, "modules/e/module.json": `{"claims":[{"name":"node-build-e"}],"tools":["build_e_test"]}`, "modules/e/cmd/e/kit.go": kit, // not a test file } { p := filepath.Join(root, path) if err := os.MkdirAll(filepath.Dir(p), 0o755); err != nil { t.Fatal(err) } if err := os.WriteFile(p, []byte(body), 0o644); err != nil { t.Fatal(err) } } got, err := Judge(root) if err != nil { t.Fatal(err) } want := map[string]string{"a": "refused", "b": "passes", "c": "exempt", "e": "refused", "f": "refused", "g": "refused"} if len(got) != len(want) { t.Fatalf("judged %+v, want a, b, c, e, f and g", got) } for _, j := range got { is := "passes" if j.Refused != "" { is = "refused" } else if j.Exempt != "" { is = "exempt" } if is != want[j.Module] { t.Errorf("%s %s (%+v), want it %s", j.Module, is, j, want[j.Module]) } } } // Every build module of this catalogue with a test step runs the kit. func TestTheCataloguesBuildModulesRunTheKit(t *testing.T) { got, err := Judge(filepath.Join("..", "..")) if err != nil { t.Fatal(err) } if len(got) == 0 { t.Fatal("no module claims a node-build-* seat: the check reads the wrong tree") } for _, j := range got { switch { case j.Refused != "": t.Errorf("%s: %s", j.Module, j.Refused) case j.Exempt != "": t.Logf("%s is exempt: %s", j.Module, j.Exempt) } } }