From 984374f5b622efc94388e2872915c2d97404adba Mon Sep 17 00:00:00 2001
From: jharshman <joshgreyhat@gmail.com>
Date: Wed, 30 Jan 2019 20:09:57 -0800
Subject: [PATCH] clean up testproject files after test executes

---
 cobra/cmd/add_test.go  | 13 +++++++++++++
 cobra/cmd/init_test.go |  7 +++++++
 2 files changed, 20 insertions(+)

diff --git a/cobra/cmd/add_test.go b/cobra/cmd/add_test.go
index d9ae0f6..0de1d22 100644
--- a/cobra/cmd/add_test.go
+++ b/cobra/cmd/add_test.go
@@ -16,9 +16,22 @@ func TestGoldenAddCmd(t *testing.T) {
 			AbsolutePath: fmt.Sprintf("%s/testproject", wd),
 			Legal:        getLicense(),
 			Copyright:    copyrightLine(),
+
+			// required to init
+			AppName: "testproject",
+			PkgName: "github.com/spf13/testproject",
+			Viper:   true,
 		},
 	}
 
+	// 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)
 	}
diff --git a/cobra/cmd/init_test.go b/cobra/cmd/init_test.go
index 77145fc..9540b2d 100644
--- a/cobra/cmd/init_test.go
+++ b/cobra/cmd/init_test.go
@@ -8,6 +8,7 @@ import (
 )
 
 func TestGoldenInitCmd(t *testing.T) {
+
 	wd, _ := os.Getwd()
 	project := &Project{
 		AbsolutePath: fmt.Sprintf("%s/testproject", wd),
@@ -23,6 +24,12 @@ func TestGoldenInitCmd(t *testing.T) {
 		t.Fatal(err)
 	}
 
+	defer func() {
+		if _, err := os.Stat(project.AbsolutePath); err == nil {
+			os.RemoveAll(project.AbsolutePath)
+		}
+	}()
+
 	expectedFiles := []string{"LICENSE", "main.go", "cmd/root.go"}
 	for _, f := range expectedFiles {
 		generatedFile := fmt.Sprintf("%s/%s", project.AbsolutePath, f)