add compareAndDelete event action

release-0.4
rick 2013-11-30 10:08:25 -07:00
parent 5b739f6166
commit 90a8f56c96
3 changed files with 4 additions and 3 deletions

View File

@ -11,6 +11,7 @@ const (
Update = "update"
Delete = "delete"
CompareAndSwap = "compareAndSwap"
CompareAndDelete = "compareAndDelete"
Expire = "expire"
)

View File

@ -304,7 +304,7 @@ func (s *store) CompareAndDelete(nodePath string, prevValue string, prevIndex ui
// Command will be executed, only if both of the tests are successful.
if (prevValue == "" || n.Value == prevValue) && (prevIndex == 0 || n.ModifiedIndex == prevIndex) {
e := newEvent(Delete, nodePath, s.CurrentIndex+1)
e := newEvent(CompareAndDelete, nodePath, s.CurrentIndex+1)
e.PrevValue = n.Value
callback := func(path string) { // notify function

View File

@ -209,7 +209,7 @@ func TestStoreCompareAndDeletePrevValue(t *testing.T) {
s.Create("/foo", "bar", false, Permanent)
e, err := s.CompareAndDelete("/foo", "bar", 0)
assert.Nil(t, err, "")
assert.Equal(t, e.Action, "delete", "")
assert.Equal(t, e.Action, "compareAndDelete", "")
}
func TestStoreCompareAndDeletePrevValueFailsIfNotMatch(t *testing.T) {
@ -229,7 +229,7 @@ func TestStoreCompareAndDeletePrevIndex(t *testing.T) {
s.Create("/foo", "bar", false, Permanent)
e, err := s.CompareAndDelete("/foo", "", 1)
assert.Nil(t, err, "")
assert.Equal(t, e.Action, "delete", "")
assert.Equal(t, e.Action, "compareAndDelete", "")
}
func TestStoreCompareAndDeletePrevIndexFailsIfNotMatch(t *testing.T) {