package trunk import ( "os" "path/filepath" "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, say := Read("checks/x/known", t.TempDir()) if !found || string(raw) != "a\nb\n" || say == "" { t.Fatalf("read %q found %v, said %q", raw, found, say) } if _, found, say := Read("checks/x/absent", t.TempDir()); found || say == "" { t.Fatalf("a file the trunk does not hold was found (%v), said %q", found, say) } } func TestWithNoCloneAndNoGitTheComparisonIsSaidNotMade(t *testing.T) { t.Setenv(BesideEnv, "") _, found, say := Read("checks/x/known", t.TempDir()) // not a git checkout if found || say == "" || say[:12] != "NOT COMPARED" { t.Fatalf("found %v, said %q; wanted NOT COMPARED", found, say) } } func TestACloneBesideWithoutTheCatalogueFallsBackToGit(t *testing.T) { t.Setenv(BesideEnv, t.TempDir()) // the siblings are there, the catalogue's own base is not _, found, say := Read("checks/x/known", t.TempDir()) if found || say == "" { t.Fatalf("found %v, said %q", found, say) } }