mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
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:
parent
3d242695b3
commit
e9931fb8b1
@ -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
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user