package trunk import ( "os" "path/filepath" "strings" "testing" ) func TestTheCloneBesideTheCheckIsTheTrunk(t *testing.T) { beside := t.TempDir() dir := filepath.Join(beside, Repository, "checks", "x") if err := os.MkdirAll(dir, 0o755); err != nil { t.Fatal(err) } if err := os.WriteFile(filepath.Join(dir, "known"), []byte("a\nb\n"), 0o644); err != nil { t.Fatal(err) } t.Setenv(BesideEnv, beside) raw, found, err := Read("checks/x/known") if err != nil || !found || string(raw) != "a\nb\n" { t.Fatalf("read %q found %v err %v", raw, found, err) } if _, found, err := Read("checks/x/absent"); err != nil || found { t.Fatalf("a file the trunk does not hold: found %v err %v; wanted its first copy", found, err) } } func TestWithNothingBesideTheComparisonFailsAndSaysNotMade(t *testing.T) { t.Setenv(BesideEnv, "") _, found, err := Read("checks/x/known") if found || err == nil || !strings.Contains(err.Error(), "NOT COMPARED") { t.Fatalf("found %v, err %v; wanted a failure saying NOT COMPARED", found, err) } } func TestACloneBesideWithoutTheCatalogueFailsAndSaysNotMade(t *testing.T) { t.Setenv(BesideEnv, t.TempDir()) // the siblings are there, the catalogue's own base is not _, found, err := Read("checks/x/known") if found || err == nil || !strings.Contains(err.Error(), "NOT COMPARED") || !strings.Contains(err.Error(), "not beside") { t.Fatalf("found %v, err %v; wanted a failure naming the missing copy", found, err) } }