diff --git a/cobra/cmd/init_test.go b/cobra/cmd/init_test.go index 8ee39106..80cc1516 100644 --- a/cobra/cmd/init_test.go +++ b/cobra/cmd/init_test.go @@ -2,15 +2,15 @@ package cmd import ( "fmt" + "io/ioutil" "os" "path/filepath" "testing" ) func getProject() *Project { - wd, _ := os.Getwd() return &Project{ - AbsolutePath: fmt.Sprintf("%s/testproject", wd), + AbsolutePath: fmt.Sprintf("%s/testproject", mustTempDir()), Legal: getLicense(), Copyright: copyrightLine(), AppName: "testproject", @@ -19,6 +19,14 @@ func getProject() *Project { } } +func mustTempDir() string { + dir, err := ioutil.TempDir("", "cobra_cli_test_") + if err != nil { + panic(err) + } + return dir +} + func TestGoldenInitCmd(t *testing.T) { project := getProject() defer os.RemoveAll(project.AbsolutePath)