return EtcdErrorNodeExist when Create is called for existing node

This commit is contained in:
Kouhei Ueno 2014-07-31 18:23:43 +09:00
parent d46bfcb132
commit ccb7e8793b
2 changed files with 8 additions and 1 deletions

View File

@ -30,11 +30,13 @@ import (
const (
EtcdErrorCodeNotFound = 100
EtcdErrorCodeNodeExist = 105
EtcdErrorCodeValueRequired = 200
)
var (
EtcdErrorNotFound = &etcd.EtcdError{ErrorCode: EtcdErrorCodeNotFound}
EtcdErrorNodeExist = &etcd.EtcdError{ErrorCode: EtcdErrorCodeNodeExist}
EtcdErrorValueRequired = &etcd.EtcdError{ErrorCode: EtcdErrorCodeValueRequired}
)

View File

@ -137,11 +137,16 @@ func (f *FakeEtcdClient) CompareAndSwap(key, value string, ttl uint64, prevValue
}
func (f *FakeEtcdClient) Create(key, value string, ttl uint64) (*etcd.Response, error) {
if prevResult, ok := f.Data[key]; ok && prevResult.R != nil && prevResult.R.Node != nil {
return nil, EtcdErrorNodeExist
}
return f.Set(key, value, ttl)
}
func (f *FakeEtcdClient) Delete(key string, recursive bool) (*etcd.Response, error) {
if f.Err != nil {
return f.Err
return nil, f.Err
}
f.Data[key] = EtcdResponseWithError{