fix(test): run ghq rm dry-run test cases

This commit is contained in:
nurazon59 2026-04-18 22:10:56 +09:00
parent 9201500760
commit b9fd98e162

View file

@ -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)
}
})
}
}