Files
gotea/modules/got/got_test.go
T
lotherk 4be6c78264 feat(got): initialize bare repositories with got
Add modules/got with a got runner, version check, repository detection, and idempotent bare init. Route bare repository creation from InitRepositoryLocal through got; non-bare temp worktrees keep git. Add [git] GOT_PATH and tests, including an explicit no-fallback test.

Assisted-by: OpenCode:DeepSeek-V4.1-Flash
2026-11-22 14:05:07 +00:00

64 lines
1.4 KiB
Go

// Copyright 2026 The Gotea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package got
import (
"os"
"path/filepath"
"strings"
"testing"
)
func requireGot(t *testing.T) {
t.Helper()
if _, err := Version(t.Context()); err != nil {
t.Skipf("got not available: %v", err)
}
}
func TestVersion(t *testing.T) {
requireGot(t)
version, err := Version(t.Context())
if err != nil {
t.Fatal(err)
}
if version == "" || strings.Contains(version, " ") {
t.Fatalf("unexpected version %q", version)
}
}
func TestInitBare(t *testing.T) {
requireGot(t)
dir := filepath.Join(t.TempDir(), "repo.git")
if err := InitBare(t.Context(), dir, "sha1", "main"); err != nil {
t.Fatal(err)
}
if !IsRepository(dir) {
t.Fatalf("%s is not a repository", dir)
}
head, err := os.ReadFile(filepath.Join(dir, "HEAD"))
if err != nil {
t.Fatal(err)
}
if strings.TrimSpace(string(head)) != "ref: refs/heads/main" {
t.Fatalf("unexpected HEAD %q", head)
}
// A second init must not destroy an existing repository.
if err := InitBare(t.Context(), dir, "sha1", "main"); err != nil {
t.Fatalf("second init: %v", err)
}
}
func TestInitBareInvalidFormat(t *testing.T) {
if err := InitBare(t.Context(), t.TempDir(), "md5", "main"); err == nil {
t.Fatal("expected an error for an invalid object format")
}
}
func TestIsRepository(t *testing.T) {
if IsRepository(t.TempDir()) {
t.Fatal("empty directory reported as a repository")
}
}