Example #1
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")
	}

}
Example #2
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")
	}
}