Exemple #1
0
func mustCheckSumFile(path string) uint64 {
	content, err := kmgFile.ReadFile(path)
	if err != nil {
		panic(err)
	}
	return xxhash.Checksum64(content)
}
Exemple #2
0
func TestGoTpl(ot *testing.T) {
	MustBuildTplInDir("testFile")
	files := kmgFile.MustGetAllFiles("testFile")
	AllCurrect := true
	ErrorMsg := ""
	for _, file := range files {
		if filepath.Ext(file) != ".gotplhtml" {
			continue
		}
		generated := kmgFile.MustReadFile(filepath.Join(filepath.Dir(file), kmgFile.GetFileBaseWithoutExt(file)+".go"))
		correct, err := kmgFile.ReadFile(filepath.Join(filepath.Dir(file), kmgFile.GetFileBaseWithoutExt(file)+".go.good"))
		if err != nil {
			ErrorMsg += fmt.Sprintf("%s read good file fail err [%s]\n", file, err)
			AllCurrect = false
			continue
		}
		if !bytes.Equal(generated, correct) {
			ErrorMsg += fmt.Sprintf("%s generated not equal correct\n", file)
			AllCurrect = false
			continue
		}
	}
	if !AllCurrect {
		panic(ErrorMsg)
	}
}
Exemple #3
0
func checkFileWithMd5(path string, shouldMd5 uint64) (ok bool) {
	content, err := kmgFile.ReadFile(path)
	if err != nil {
		if !os.IsNotExist(err) {
			panic(err)
		}
		return false
	}
	return xxhash.Checksum64(content) == shouldMd5
}
Exemple #4
0
// 如果没有数据会返回nil
func MustKvdbGetBytes(s string) (b []byte) {
	key := kmgCrypto.Md5Hex([]byte(s))
	content, err := kmgFile.ReadFile(kmgConfig.DefaultEnv().PathInTmp("kvdb/" + key))
	if err != nil {
		if os.IsNotExist(err) {
			return nil
		}
		panic(err)
	}
	return content
}