github.com/keysonZZZ/kmg@v0.0.0-20151121023212-05317bfd7d39/kmgView/kmgGoTpl/kmgGoTpl_test.go (about) 1 package kmgGoTpl 2 3 import ( 4 "path/filepath" 5 "testing" 6 7 "bytes" 8 "fmt" 9 "github.com/bronze1man/kmg/kmgFile" 10 ) 11 12 func TestGoTpl(ot *testing.T) { 13 MustBuildTplInDir("testFile") 14 files := kmgFile.MustGetAllFiles("testFile") 15 AllCurrect := true 16 ErrorMsg := "" 17 for _, file := range files { 18 if filepath.Ext(file) != ".gotplhtml" { 19 continue 20 } 21 generated := kmgFile.MustReadFile(filepath.Join(filepath.Dir(file), kmgFile.GetFileBaseWithoutExt(file)+".go")) 22 correct, err := kmgFile.ReadFile(filepath.Join(filepath.Dir(file), kmgFile.GetFileBaseWithoutExt(file)+".go.good")) 23 if err != nil { 24 ErrorMsg += fmt.Sprintf("%s read good file fail err [%s]\n", file, err) 25 AllCurrect = false 26 continue 27 } 28 if !bytes.Equal(generated, correct) { 29 ErrorMsg += fmt.Sprintf("%s generated not equal correct\n", file) 30 AllCurrect = false 31 continue 32 } 33 } 34 if !AllCurrect { 35 panic(ErrorMsg) 36 } 37 } 38 39 func setCurrentAsCorrect() { 40 files := kmgFile.MustGetAllFiles("testFile") 41 for _, file := range files { 42 if filepath.Ext(file) != ".gotplhtml" { 43 continue 44 } 45 kmgFile.MustCopyFile(filepath.Join(filepath.Dir(file), kmgFile.GetFileBaseWithoutExt(file)+".go"), filepath.Join(filepath.Dir(file), kmgFile.GetFileBaseWithoutExt(file)+".go.good")) 46 } 47 }