Skip to content

Commit

Permalink
style: simply defer os.RemoveAll
Browse files Browse the repository at this point in the history
  • Loading branch information
umarcor committed Sep 17, 2019
1 parent 7a0cf95 commit c35f8b0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
7 changes: 1 addition & 6 deletions cobra/cmd/add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
16 changes: 7 additions & 9 deletions cobra/cmd/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}

defer func() {
if _, err := os.Stat(project.AbsolutePath); err == nil {
os.RemoveAll(project.AbsolutePath)
}
}()
// required to init
AppName: "testproject",
PkgName: "github.com/spf13/testproject",
Viper: true,
}
defer os.RemoveAll(project.AbsolutePath)

// init project first
err := project.Create()
if err != nil {
t.Fatal(err)
Expand Down

0 comments on commit c35f8b0

Please sign in to comment.