diff --git a/cmd_rm_test.go b/cmd_rm_test.go index 141bd81..fa72ac8 100644 --- a/cmd_rm_test.go +++ b/cmd_rm_test.go @@ -146,7 +146,9 @@ func TestRmDryRunCommand(t *testing.T) { name: "simple", input: []string{"rm", "--dry-run", "motemen/ghqq"}, setup: func(t *testing.T) { - os.MkdirAll(filepath.Join(tmpd, "github.com", "motemen", "ghqq"), 0755) + if err := os.MkdirAll(filepath.Join(tmpd, "github.com", "motemen", "ghqq", ".git"), 0755); err != nil { + t.Fatal(err) + } }, expectErr: false, }, @@ -166,9 +168,9 @@ func TestRmDryRunCommand(t *testing.T) { }, { name: "permission denied", - input: []string{"rm", "--dry-run", "motemen/ghqq"}, + input: []string{"rm", "--dry-run", "motemen/ghq-notpermitted"}, setup: func(t *testing.T) { - f := filepath.Join(tmpd, "github.com", "motemen", "ghqq") + f := filepath.Join(tmpd, "github.com", "motemen", "ghq-notpermitted") os.MkdirAll(f, 0000) t.Cleanup(func() { os.Chmod(f, 0755) @@ -192,6 +194,21 @@ func TestRmDryRunCommand(t *testing.T) { if tc.cmdRun != nil { cmdutil.CommandRunner = tc.cmdRun } + + var runErr error + _, _, err := capture(func() { + a := newApp() + args := append([]string{"ghq"}, tc.input...) + runErr = a.Run(context.Background(), args) + }) + + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + + if gotErr := runErr != nil; gotErr != tc.expectErr { + t.Fatalf("error = %v, expectErr = %v", runErr, tc.expectErr) + } }) } }