cobra/cmd: add getProject test func

This commit is contained in:
umarcor 2019-09-17 14:55:21 +02:00
parent c35f8b03e4
commit ccf60c76a2
2 changed files with 11 additions and 24 deletions

View file

@ -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)

View file

@ -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)
}