spf13--cobra/cobra/cmd/init_test.go

36 lines
752 B
Go
Raw Normal View History

2017-05-05 08:06:27 +00:00
package cmd
import (
"fmt"
2017-05-05 08:06:27 +00:00
"os"
"path/filepath"
"testing"
)
2019-01-30 07:41:41 +00:00
func TestGoldenInitCmd(t *testing.T) {
wd, _ := os.Getwd()
project := &Project{
AbsolutePath: fmt.Sprintf("%s/testproject", wd),
2019-01-30 07:41:41 +00:00
PkgName: "github.com/spf13/testproject",
Legal: getLicense(),
2019-01-30 08:46:53 +00:00
Copyright: copyrightLine(),
2019-01-30 07:41:41 +00:00
Viper: true,
AppName: "testproject",
}
err := project.Create()
if err != nil {
t.Fatal(err)
}
expectedFiles := []string{"LICENSE", "main.go", "cmd/root.go"}
for _, f := range expectedFiles {
generatedFile := fmt.Sprintf("%s/%s", project.AbsolutePath, f)
goldenFile := fmt.Sprintf("testdata/%s.golden", filepath.Base(f))
err := compareFiles(generatedFile, goldenFile)
2017-05-05 08:06:27 +00:00
if err != nil {
t.Fatal(err)
2017-05-05 08:06:27 +00:00
}
}
}