Ejemplo n.º 1
0
func Benchmark_Persist(b *testing.B) {
	for i := 0; i < b.N; i++ {
		var filename = "testfile"
		var randomString = "random string"
		storage.Persist(randomString, filename)
		os.Remove(filename)
	}
}
Ejemplo n.º 2
0
func Test_Persist(t *testing.T) {
	var filename = "testfile"
	fo, _ := os.Create(filename)

	fo.Close()
	var data = "something stored"
	var uuid, _ = utils.GenerateV4String()
	var len = strconv.Itoa(utf8.RuneCountInString(data))
	var expected = uuid + len + data

	storage.Persist(expected, filename)
	buf, _ := ioutil.ReadFile(filename)
	s := string(buf)

	if s != expected {
		t.Errorf("expecting [%s] but got [%s]", s, expected)
	}

	defer func() {
		os.Remove(filename)
	}()
}