From e9931fb8b1554bebdd8722e2ad9da4abd31f6222 Mon Sep 17 00:00:00 2001 From: Xiang Li Date: Mon, 11 May 2015 10:49:49 -0700 Subject: [PATCH] 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. --- discovery/discovery.go | 2 +- discovery/discovery_test.go | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/discovery/discovery.go b/discovery/discovery.go index bceb5bb17..85ca071f4 100644 --- a/discovery/discovery.go +++ b/discovery/discovery.go @@ -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 diff --git a/discovery/discovery_test.go b/discovery/discovery_test.go index 5f2ba641e..16147a82b 100644 --- a/discovery/discovery_test.go +++ b/discovery/discovery_test.go @@ -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 {