Explorar o código

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.
Xiang Li %!s(int64=10) %!d(string=hai) anos
pai
achega
e9931fb8b1
Modificáronse 2 ficheiros con 4 adicións e 1 borrados
  1. 1 1
      discovery/discovery.go
  2. 3 0
      discovery/discovery_test.go

+ 1 - 1
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

+ 3 - 0
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 {