package skillsrepo import ( "os" "os/exec" "path/filepath" "testing" ) func gitInit(t *testing.T, dir string) { t.Helper() if _, err := exec.LookPath("git"); err != nil { t.Skip("git not available") } run := func(args ...string) { full := append([]string{"-c", "user.email=t@t", "-c", "user.name=t", "-C", dir}, args...) if out, err := exec.Command("git", full...).CombinedOutput(); err != nil { t.Fatalf("git %v: %v\n%s", args, err, out) } } run("init", "-q") if err := os.WriteFile(filepath.Join(dir, "a.txt"), []byte("x"), 0o644); err != nil { t.Fatal(err) } run("add", ".") run("commit", "-q", "-m", "init") } func TestCheckHealthyRepo(t *testing.T) { dir := t.TempDir() gitInit(t, dir) h := Check(dir) if !h.IsRepo { t.Fatal("should be a repo") } if h.Head == "" { t.Fatalf("HEAD should be readable: %+v", h) } if !h.FsckOK { t.Fatalf("fsck should pass: %+v", h) } if h.FreeBytes == 0 { t.Fatal("free bytes should be reported") } } func TestCheckNotARepo(t *testing.T) { h := Check(t.TempDir()) if h.IsRepo { t.Fatal("should not be a repo") } if h.Healthy() { t.Fatal("non-repo must not be healthy") } if len(h.Problems) == 0 { t.Fatal("expected a problem note") } }