42 lines
1.4 KiB
Go
42 lines
1.4 KiB
Go
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, skip, err := Read("checks/x/known")
|
|
if err != nil || skip != "" || !found || string(raw) != "a\nb\n" {
|
|
t.Fatalf("read %q found %v skip %q err %v", raw, found, skip, err)
|
|
}
|
|
if _, found, skip, err := Read("checks/x/absent"); err != nil || skip != "" || found {
|
|
t.Fatalf("a file the trunk does not hold: found %v skip %q err %v; wanted its first copy", found, skip, err)
|
|
}
|
|
}
|
|
|
|
func TestWithNothingBesideTheComparisonIsSkippedAndSaidNotMade(t *testing.T) {
|
|
t.Setenv(BesideEnv, "")
|
|
_, found, skip, err := Read("checks/x/known")
|
|
if found || err != nil || len(skip) < 12 || skip[:12] != "NOT COMPARED" {
|
|
t.Fatalf("found %v, skip %q, err %v; wanted NOT COMPARED", found, skip, err)
|
|
}
|
|
}
|
|
|
|
func TestACloneBesideWithoutTheCatalogueFailsLoudly(t *testing.T) {
|
|
t.Setenv(BesideEnv, t.TempDir()) // the siblings are there, the catalogue's own base is not
|
|
if _, _, skip, err := Read("checks/x/known"); err == nil || skip != "" {
|
|
t.Fatalf("skip %q err %v; wanted an error", skip, err)
|
|
}
|
|
}
|