mirror of
https://github.com/spf13/cobra
synced 2024-11-15 02:07:08 +00:00
35 lines
752 B
Go
35 lines
752 B
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestGoldenInitCmd(t *testing.T) {
|
|
wd, _ := os.Getwd()
|
|
project := &Project{
|
|
AbsolutePath: fmt.Sprintf("%s/testproject", wd),
|
|
PkgName: "github.com/spf13/testproject",
|
|
Legal: getLicense(),
|
|
Copyright: copyrightLine(),
|
|
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)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
}
|