mirror of
https://github.com/spf13/cobra
synced 2025-05-06 13:27:26 +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,
|
Viper: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
defer os.RemoveAll(command.AbsolutePath)
|
||||||
|
|
||||||
// init project first
|
// init project first
|
||||||
command.Project.Create()
|
command.Project.Create()
|
||||||
defer func() {
|
|
||||||
if _, err := os.Stat(command.AbsolutePath); err == nil {
|
|
||||||
os.RemoveAll(command.AbsolutePath)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
if err := command.Create(); err != nil {
|
if err := command.Create(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,19 +12,17 @@ func TestGoldenInitCmd(t *testing.T) {
|
||||||
wd, _ := os.Getwd()
|
wd, _ := os.Getwd()
|
||||||
project := &Project{
|
project := &Project{
|
||||||
AbsolutePath: fmt.Sprintf("%s/testproject", wd),
|
AbsolutePath: fmt.Sprintf("%s/testproject", wd),
|
||||||
PkgName: "github.com/spf13/testproject",
|
|
||||||
Legal: getLicense(),
|
Legal: getLicense(),
|
||||||
Copyright: copyrightLine(),
|
Copyright: copyrightLine(),
|
||||||
Viper: true,
|
|
||||||
|
// required to init
|
||||||
AppName: "testproject",
|
AppName: "testproject",
|
||||||
|
PkgName: "github.com/spf13/testproject",
|
||||||
|
Viper: true,
|
||||||
}
|
}
|
||||||
|
defer os.RemoveAll(project.AbsolutePath)
|
||||||
|
|
||||||
defer func() {
|
// init project first
|
||||||
if _, err := os.Stat(project.AbsolutePath); err == nil {
|
|
||||||
os.RemoveAll(project.AbsolutePath)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
err := project.Create()
|
err := project.Create()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|
Loading…
Add table
Reference in a new issue