Skip to content
1 change: 1 addition & 0 deletions .testcoverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ exclude:
paths:
- main\.go$ # Program entry point
- cmd/genreadme/
- internal/backend/backendtest/ # shared test helpers, exercised only from other packages' tests
12 changes: 2 additions & 10 deletions backends/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,8 @@ func (*Backend) Run(
args []string,
interactive bool,
) (backend.RunResult, error) {
if len(args) == 0 {
return backend.RunResult{}, backend.ErrNoArgs
}

res, err := backend.RunCommand(ctx, "git", path, args, interactive)
if err != nil {
return backend.RunResult{}, fmt.Errorf("git %s: %w", args[0], err)
}

return res, nil
//nolint:wrapcheck // RunTool already wraps with the binary name and subcommand
return backend.RunTool(ctx, "git", path, args, interactive)
}

// runGit is a helper for internal status queries.
Expand Down
43 changes: 4 additions & 39 deletions backends/git/git_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package git

import (
"context"
"os"
"path/filepath"
"slices"
"testing"

"github.com/hugoh/hrd/internal/backend"
"github.com/hugoh/hrd/internal/backend/backendtest"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -223,32 +223,7 @@ func TestBackend_SubcommandArgs(t *testing.T) {
}

func TestBackend_Detect(t *testing.T) {
t.Run("with git dir", func(t *testing.T) {
dir := t.TempDir()
err := os.MkdirAll(filepath.Join(dir, ".git"), 0o750)
require.NoError(t, err)

b := &Backend{}
ok, err := b.Detect(dir)
require.NoError(t, err)
assert.True(t, ok)
})

t.Run("without git dir", func(t *testing.T) {
dir := t.TempDir()

b := &Backend{}
ok, err := b.Detect(dir)
require.NoError(t, err)
assert.False(t, ok)
})

t.Run("error on invalid path", func(t *testing.T) {
b := &Backend{}
ok, err := b.Detect("\x00invalid")
assert.False(t, ok)
assert.Error(t, err)
})
backendtest.AssertDetect(t, func() backend.Backend { return &Backend{} }, ".git")
}

func TestBackend_Run_Interactive(t *testing.T) {
Expand All @@ -275,13 +250,7 @@ func TestBackend_Subcommands(t *testing.T) {
}

func TestBackend_Subcommands_Error(t *testing.T) {
b := &Backend{}

ctx, cancel := context.WithCancel(t.Context())
cancel()

_, err := b.Subcommands(ctx)
assert.Error(t, err)
backendtest.AssertSubcommandsErrorsOnCanceledContext(t, &Backend{})
}

func TestParseGitCmdList(t *testing.T) {
Expand Down Expand Up @@ -395,11 +364,7 @@ func TestBackend_Run(t *testing.T) {
}

func TestBackend_Run_NoArgs(t *testing.T) {
dir := t.TempDir()

b := &Backend{}
_, err := b.Run(t.Context(), dir, nil, false)
assert.ErrorIs(t, err, backend.ErrNoArgs)
backendtest.AssertRunNoArgs(t, &Backend{})
}

func TestBackend_Run_NonZeroExit(t *testing.T) {
Expand Down
Loading
Loading