mirror of
https://github.com/spf13/cobra
synced 2025-05-06 05:17:21 +00:00
style: simply defer os.RemoveAll
This commit is contained in:
parent
7a0cf95b2a
commit
c35f8b03e4
2 changed files with 8 additions and 15 deletions
|
@ -23,15 +23,10 @@ func TestGoldenAddCmd(t *testing.T) {
|
|||
Viper: true,
|
||||
},
|
||||
}
|
||||
defer os.RemoveAll(command.AbsolutePath)
|
||||
|
||||
// init project first
|
||||
command.Project.Create()
|
||||
defer func() {
|
||||
if _, err := os.Stat(command.AbsolutePath); err == nil {
|
||||
os.RemoveAll(command.AbsolutePath)
|
||||
}
|
||||
}()
|
||||
|
||||
if err := command.Create(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
|
|
@ -12,19 +12,17 @@ func TestGoldenInitCmd(t *testing.T) {
|
|||
wd, _ := os.Getwd()
|
||||
project := &Project{
|
||||
AbsolutePath: fmt.Sprintf("%s/testproject", wd),
|
||||
PkgName: "github.com/spf13/testproject",
|
||||
Legal: getLicense(),
|
||||
Copyright: copyrightLine(),
|
||||
Viper: true,
|
||||
AppName: "testproject",
|
||||
|
||||
// required to init
|
||||
AppName: "testproject",
|
||||
PkgName: "github.com/spf13/testproject",
|
||||
Viper: true,
|
||||
}
|
||||
defer os.RemoveAll(project.AbsolutePath)
|
||||
|
||||
defer func() {
|
||||
if _, err := os.Stat(project.AbsolutePath); err == nil {
|
||||
os.RemoveAll(project.AbsolutePath)
|
||||
}
|
||||
}()
|
||||
|
||||
// init project first
|
||||
err := project.Create()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
|
Loading…
Add table
Reference in a new issue