/
init_go1.12_test.go
51 lines (43 loc) · 1.11 KB
/
init_go1.12_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// +build go1.12
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)
}
defer func() {
if _, err := os.Stat(project.AbsolutePath); err == nil {
os.RemoveAll(project.AbsolutePath)
}
}()
expectedFiles := []string{"LICENSE", "main.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)
}
}
rootCmd := "cmd/root.go"
generatedFile := fmt.Sprintf("%s/%s", project.AbsolutePath, rootCmd)
goldenFile := fmt.Sprintf("testdata/%s1.12.golden", filepath.Base(rootCmd))
if err = compareFiles(generatedFile, goldenFile); err != nil {
t.Fatal(err)
}
}