Skip to content

Commit bb6cbb1

Browse files
appleboyclaude
andcommitted
fix(test): resolve lint errors in HandleRemote test
- Check os.Chdir error return in defer to satisfy errcheck - Use exec.CommandContext instead of exec.Command to satisfy noctx - Add nolint:gosec for test-only git commands with static args Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 51088c2 commit bb6cbb1

1 file changed

Lines changed: 10 additions & 11 deletions

File tree

plugin_test.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,21 @@ func TestPlugin_HandleRemote_ExistingRemote(t *testing.T) {
5656
if err != nil {
5757
t.Fatal(err)
5858
}
59-
defer os.Chdir(origDir)
59+
defer func() {
60+
_ = os.Chdir(origDir)
61+
}()
6062

6163
if err := os.Chdir(tmpDir); err != nil {
6264
t.Fatal(err)
6365
}
6466

6567
// Initialize a git repo and add a remote
66-
cmds := [][]string{
67-
{"git", "init"},
68-
{"git", "remote", "add", "origin", "git@github.com:old/repo.git"},
68+
ctx := context.Background()
69+
if out, err := exec.CommandContext(ctx, "git", "init").CombinedOutput(); err != nil { //nolint:gosec
70+
t.Fatalf("git init failed: %s, %v", out, err)
6971
}
70-
for _, args := range cmds {
71-
cmd := exec.Command(args[0], args[1:]...)
72-
if out, err := cmd.CombinedOutput(); err != nil {
73-
t.Fatalf("command %v failed: %s, %v", args, out, err)
74-
}
72+
if out, err := exec.CommandContext(ctx, "git", "remote", "add", "origin", "git@github.com:old/repo.git").CombinedOutput(); err != nil { //nolint:gosec
73+
t.Fatalf("git remote add failed: %s, %v", out, err)
7574
}
7675

7776
// HandleRemote should succeed even though "origin" already exists
@@ -81,12 +80,12 @@ func TestPlugin_HandleRemote_ExistingRemote(t *testing.T) {
8180
Remote: "git@github.com:new/repo.git",
8281
},
8382
}
84-
if err := p.HandleRemote(context.Background()); err != nil {
83+
if err := p.HandleRemote(ctx); err != nil {
8584
t.Errorf("HandleRemote() with existing remote should not fail, got: %v", err)
8685
}
8786

8887
// Verify the remote URL was updated
89-
out, err := exec.Command("git", "remote", "get-url", "origin").Output()
88+
out, err := exec.CommandContext(ctx, "git", "remote", "get-url", "origin").Output() //nolint:gosec
9089
if err != nil {
9190
t.Fatal(err)
9291
}

0 commit comments

Comments
 (0)