clean up testproject files after test executes
This commit is contained in:
parent
11aa612384
commit
984374f5b6
@ -16,9 +16,22 @@ func TestGoldenAddCmd(t *testing.T) {
|
|||||||
AbsolutePath: fmt.Sprintf("%s/testproject", wd),
|
AbsolutePath: fmt.Sprintf("%s/testproject", wd),
|
||||||
Legal: getLicense(),
|
Legal: getLicense(),
|
||||||
Copyright: copyrightLine(),
|
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 {
|
if err := command.Create(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestGoldenInitCmd(t *testing.T) {
|
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),
|
||||||
@ -23,6 +24,12 @@ func TestGoldenInitCmd(t *testing.T) {
|
|||||||
t.Fatal(err)
|
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"}
|
expectedFiles := []string{"LICENSE", "main.go", "cmd/root.go"}
|
||||||
for _, f := range expectedFiles {
|
for _, f := range expectedFiles {
|
||||||
generatedFile := fmt.Sprintf("%s/%s", project.AbsolutePath, f)
|
generatedFile := fmt.Sprintf("%s/%s", project.AbsolutePath, f)
|
||||||
|
Loading…
Reference in New Issue
Block a user