diff options
| author | Paul Buetow <paul@buetow.org> | 2026-04-17 09:04:29 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-04-17 09:04:29 +0300 |
| commit | 58349705d5adafa60b8a1dddd0f5c72bad568d3b (patch) | |
| tree | eefad461de05ad027936c44a3f73925ed1fce652 /internal/git/git_test.go | |
| parent | eb89e32c6675d4ed50f66580346e5ea8f3d7b5b2 (diff) | |
refactor: extract buildGeheimGit helper to keep buildGeheimBackend under 30 lines
Extracts a 3-line buildGeheimGit(cfg) helper from buildGeheimBackend,
mirroring the existing buildKeepassGit pattern and satisfying the project
guideline of keeping functions under 30 lines. Also includes the full
o4 backend-abstraction changeset: Gitter interface, git.NoOp, --backend
flag parsing, keepass backend wiring, and effectiveBackend guard for
migrate-kdbx.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'internal/git/git_test.go')
| -rw-r--r-- | internal/git/git_test.go | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/internal/git/git_test.go b/internal/git/git_test.go index fa1f8f7..462c747 100644 --- a/internal/git/git_test.go +++ b/internal/git/git_test.go @@ -264,3 +264,49 @@ func TestSync_bad_remote(t *testing.T) { t.Fatal("expected error when syncing with a nonexistent remote, got nil") } } + +// TestIsGitRepo_inside verifies that IsGitRepo returns true for a directory +// that is a git repository. +func TestIsGitRepo_inside(t *testing.T) { + dir := initRepo(t) + if !git.IsGitRepo(dir) { + t.Errorf("expected IsGitRepo(%q) = true for a git repo, got false", dir) + } +} + +// TestIsGitRepo_outside verifies that IsGitRepo returns false for a plain +// directory that is not a git repository. +func TestIsGitRepo_outside(t *testing.T) { + dir := t.TempDir() // just a plain temp dir, not git-initialised + if git.IsGitRepo(dir) { + t.Errorf("expected IsGitRepo(%q) = false for a non-git dir, got true", dir) + } +} + +// TestNoOp_satisfies_Gitter verifies that *git.NoOp compiles as a Gitter and +// that all its methods return nil (no-op, no error) so they are safe to call +// unconditionally from CLI dispatch. +func TestNoOp_satisfies_Gitter(t *testing.T) { + var g git.Gitter = git.NewNoOp() + ctx := context.Background() + + table := []struct { + name string + fn func() error + }{ + {"Add", func() error { return g.Add(ctx, "/some/path") }}, + {"Remove", func() error { return g.Remove(ctx, "/some/path") }}, + {"Status", func() error { return g.Status(ctx) }}, + {"Commit", func() error { return g.Commit(ctx) }}, + {"Reset", func() error { return g.Reset(ctx) }}, + {"Sync", func() error { return g.Sync(ctx, []string{"origin"}) }}, + } + + for _, tt := range table { + t.Run(tt.name, func(t *testing.T) { + if err := tt.fn(); err != nil { + t.Errorf("NoOp.%s returned error: %v", tt.name, err) + } + }) + } +} |
