2017-05-05 08:06:27 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2019-01-30 08:33:51 +00:00
|
|
|
"fmt"
|
2017-05-05 08:06:27 +00:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2019-09-17 15:02:42 +00:00
|
|
|
func getProject() *Project {
|
2019-01-30 07:41:41 +00:00
|
|
|
wd, _ := os.Getwd()
|
2019-09-17 15:02:42 +00:00
|
|
|
return &Project{
|
2019-01-30 08:33:51 +00:00
|
|
|
AbsolutePath: fmt.Sprintf("%s/testproject", wd),
|
2019-01-30 07:41:41 +00:00
|
|
|
Legal: getLicense(),
|
2019-01-30 08:46:53 +00:00
|
|
|
Copyright: copyrightLine(),
|
2019-01-30 07:41:41 +00:00
|
|
|
AppName: "testproject",
|
2019-09-17 15:02:42 +00:00
|
|
|
PkgName: "github.com/spf13/testproject",
|
|
|
|
Viper: true,
|
2019-01-30 07:41:41 +00:00
|
|
|
}
|
2019-09-17 15:02:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestGoldenInitCmd(t *testing.T) {
|
|
|
|
project := getProject()
|
|
|
|
defer os.RemoveAll(project.AbsolutePath)
|
2019-01-30 07:41:41 +00:00
|
|
|
|
2019-09-17 15:02:42 +00:00
|
|
|
if err := project.Create(); err != nil {
|
2019-01-30 07:41:41 +00:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2019-01-30 08:33:51 +00:00
|
|
|
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 {
|
2019-01-30 08:33:51 +00:00
|
|
|
t.Fatal(err)
|
2017-05-05 08:06:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|