diff --git a/cobra/cmd/add_test.go b/cobra/cmd/add_test.go index b3d01016b..de92fcea6 100644 --- a/cobra/cmd/add_test.go +++ b/cobra/cmd/add_test.go @@ -7,25 +7,13 @@ import ( ) func TestGoldenAddCmd(t *testing.T) { - - wd, _ := os.Getwd() command := &Command{ CmdName: "test", CmdParent: parentName, - Project: &Project{ - AbsolutePath: fmt.Sprintf("%s/testproject", wd), - Legal: getLicense(), - Copyright: copyrightLine(), - - // required to init - AppName: "testproject", - PkgName: "github.com/spf13/testproject", - Viper: true, - }, + Project: getProject(), } defer os.RemoveAll(command.AbsolutePath) - // init project first command.Project.Create() if err := command.Create(); err != nil { t.Fatal(err) diff --git a/cobra/cmd/init_test.go b/cobra/cmd/init_test.go index fd8f87f03..8ee391061 100644 --- a/cobra/cmd/init_test.go +++ b/cobra/cmd/init_test.go @@ -7,24 +7,23 @@ import ( "testing" ) -func TestGoldenInitCmd(t *testing.T) { - +func getProject() *Project { wd, _ := os.Getwd() - project := &Project{ + return &Project{ AbsolutePath: fmt.Sprintf("%s/testproject", wd), Legal: getLicense(), Copyright: copyrightLine(), - - // required to init - AppName: "testproject", - PkgName: "github.com/spf13/testproject", - Viper: true, + AppName: "testproject", + PkgName: "github.com/spf13/testproject", + Viper: true, } +} + +func TestGoldenInitCmd(t *testing.T) { + project := getProject() defer os.RemoveAll(project.AbsolutePath) - // init project first - err := project.Create() - if err != nil { + if err := project.Create(); err != nil { t.Fatal(err) }