diff --git a/pkg/config/etcd/etcd.go b/pkg/config/etcd/etcd.go index ca27f023..c7df44fb 100644 --- a/pkg/config/etcd/etcd.go +++ b/pkg/config/etcd/etcd.go @@ -78,11 +78,7 @@ func (c *storeOperate) Init(options map[string]interface{}) error { func (c *storeOperate) Save(key config.PathKey, val []byte) error { _, err := c.client.Put(context.Background(), string(key), string(val)) - if err != nil { - return err - } - - return nil + return err } func (c *storeOperate) Get(key config.PathKey) ([]byte, error) { @@ -92,7 +88,7 @@ func (c *storeOperate) Get(key config.PathKey) ([]byte, error) { } if len(resp.Kvs) == 0 { - return nil, err + return nil, nil } return resp.Kvs[0].Value, nil @@ -150,7 +146,6 @@ func (c *storeOperate) Watch(key config.PathKey) (<-chan []byte, error) { ctx, cancel := context.WithCancel(context.Background()) c.cancelList = append(c.cancelList, cancel) go w.run(ctx) - } w := c.receivers[key] diff --git a/pkg/config/etcd/etcd_test.go b/pkg/config/etcd/etcd_test.go index 7f4ee964..8c75ea53 100644 --- a/pkg/config/etcd/etcd_test.go +++ b/pkg/config/etcd/etcd_test.go @@ -94,14 +94,15 @@ func Test_storeOpertae(t *testing.T) { assert.NoError(t, err, "init must success") + assert.Error(t, operate.Init(map[string]interface{}{"endpoints": "fake"})) + doDataMock() cfg, _ := config.Load(testdata.Path("fake_config.yaml")) tenantName := cfg.Data.Tenants[0].Name for k, v := range mockConfData { - err := operate.Save(k, []byte(v)) - assert.NoError(t, err, "save must success") + assert.NoError(t, operate.Save(k, []byte(v)), "save must success") } for k, v := range mockConfData { @@ -111,6 +112,9 @@ func Test_storeOpertae(t *testing.T) { t.Logf("%s => %s", k, string(ret)) } + _, err = operate.Get("fake") + assert.NoError(t, err) + receiver, err := operate.Watch(mockPath[tenantName].DefaultConfigDataUsersPath) assert.NoError(t, err, "watch must success") @@ -132,4 +136,5 @@ func Test_storeOpertae(t *testing.T) { t.Logf("acutal val : %s", string(ret)) assert.Equal(t, string(data), string(ret)) + assert.NoError(t, operate.Close()) }