discovery: do not return error from etcd

We used to return `key not found` directly to the
user due to a bug. We fixed the bug and added a test
case in this commit.
This commit is contained in:
Xiang Li 2015-05-11 10:49:49 -07:00
parent 3d242695b3
commit e9931fb8b1
2 changed files with 4 additions and 1 deletions

View File

@ -183,7 +183,7 @@ func (d *discovery) createSelf(contents string) error {
resp, err := d.c.Create(ctx, d.selfKey(), contents)
cancel()
if err != nil {
if eerr, ok := err.(*client.Error); ok && eerr.Code == client.ErrorCodeNodeExist {
if eerr, ok := err.(client.Error); ok && eerr.Code == client.ErrorCodeNodeExist {
return ErrDuplicateID
}
return err

View File

@ -318,6 +318,7 @@ func TestCreateSelf(t *testing.T) {
c := &clientWithResp{rs: rs, w: w}
errc := &clientWithErr{err: errors.New("create err"), w: w}
errdupc := &clientWithErr{err: client.Error{Code: client.ErrorCodeNodeExist}}
errwc := &clientWithResp{rs: rs, w: errw}
tests := []struct {
@ -330,6 +331,8 @@ func TestCreateSelf(t *testing.T) {
{errc, errc.err},
// watcher.next retuens an error
{errwc, errw.err},
// parse key exist error to duplciate ID error
{errdupc, ErrDuplicateID},
}
for i, tt := range tests {