Ejemplo n.º 1
0
func TestPutString(t *testing.T) {
	var tmp = os.TempDir()
	kvson, err := NewKVSON(tmp)
	if err != nil {
		t.Error(err)
	}
	err = kvson.Put("foo", "bar")
	if err != nil {
		t.Errorf("It should not fail, but got an error: %s", err)
	}
}
Ejemplo n.º 2
0
func BenchmarkPut(b *testing.B) {
	var tmp = os.TempDir()
	rand.Seed(time.Now().UnixNano())
	kvson, err := NewKVSON(tmp)
	for n := 0; n < b.N; n++ {
		err = kvson.Put(string(rand.Int()), n)
		if err != nil {
			b.Errorf("It should not fail, but got an error: %s", err)
		}
	}

}
Ejemplo n.º 3
0
func TestPutStruct(t *testing.T) {
	var tmp = os.TempDir()
	kvson, err := NewKVSON(tmp)
	if err != nil {
		t.Error(err)
	}
	example := Example{
		ID:         1,
		Key:        "key",
		AnotherKey: "This is another key",
	}
	err = kvson.Put("example", example)
	if err != nil {
		t.Errorf("It should not fail, but got an error: %s", err)
	}
}
Ejemplo n.º 4
0
func TestDelete(t *testing.T) {

	var tmp = os.TempDir()
	kvson, err := NewKVSON(tmp)
	err = kvson.Delete("not_exists")
	if err == nil {
		t.Errorf("It should give an error. The key doesn't exists")
	}

	err = kvson.Put("exists_key", "foo")
	if err != nil {
		t.Errorf("It should not give an error. The key should be created")
	}

	err = kvson.Delete("exists_key")
	if err != nil {
		t.Errorf("It should not give an error. The key should be deleted")
	}

}
Ejemplo n.º 5
0
func TestExists(t *testing.T) {
	var tmp = os.TempDir()
	kvson, err := NewKVSON(tmp)
	kvson.Delete("exists")
	if err != nil {
		t.Error(err)
	}
	if kvson.Exists("exists") == true {
		t.Errorf("It should not exist, but it does")
	}
	err = kvson.Put("exists", "bar")
	if err != nil {
		t.Errorf("It should not fail, but got an error: %s", err)
	}
	if kvson.Exists("exists") == false {
		t.Errorf("It should exist, but it doesn't")
	}

	err = kvson.Delete("exists")
	if err != nil {
		t.Errorf("It should delete, but it doesn't")
	}
}