You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by ti...@apache.org on 2020/01/06 03:55:37 UTC

[servicecomb-kie] branch master updated: #62 inconsistent naming convention (#63)

This is an automated email from the ASF dual-hosted git repository.

tianxiaoliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-kie.git


The following commit(s) were added to refs/heads/master by this push:
     new 6178472  #62 inconsistent naming convention (#63)
6178472 is described below

commit 61784729d6caf444b5ef178480ac29445c47921b
Author: Shawn <xi...@gmail.com>
AuthorDate: Mon Jan 6 11:55:29 2020 +0800

    #62 inconsistent naming convention (#63)
    
    * #62 inconsistent naming convention
    
    * #62 inconsistent naming convention,add UT
    
    * #62 inconsistent naming convention,add UT
    
    * #62 inconsistent naming convention,add UT
    
    * #62 inconsistent naming convention,add UT
---
 client/adaptor/kie_client_test.go      |  2 +-
 client/client.go                       |  3 ++-
 pkg/common/common.go                   |  2 +-
 server/resource/v1/doc_struct.go       | 13 +------------
 server/resource/v1/kv_resource.go      |  3 ++-
 server/resource/v1/kv_resource_test.go | 20 ++++++++++++++++----
 6 files changed, 23 insertions(+), 20 deletions(-)

diff --git a/client/adaptor/kie_client_test.go b/client/adaptor/kie_client_test.go
index 20443e9..2702cdc 100644
--- a/client/adaptor/kie_client_test.go
+++ b/client/adaptor/kie_client_test.go
@@ -123,7 +123,7 @@ func TestKieClient_PushConfigs(t *testing.T) {
 //TestKieClient_DeleteConfigs for test DeleteConfigs.
 func TestKieClient_DeleteConfigs(t *testing.T) {
 	//v1/calculator/kie/kv?q=env:+servicename:calculator+version:0.0.1+app:
-	helper := startHttpServer(":49800", "/v1/calculator/kie/kv/?kvID=s")
+	helper := startHttpServer(":49800", "/v1/calculator/kie/kv/?kv_id=s")
 	gopath := os.Getenv("GOPATH")
 	os.Setenv("CHASSIS_HOME", gopath+"src/github.com/go-chassis/go-chassis/examples/discovery/server/")
 	kieClient, err := NewClient(remote.Options{Labels: map[string]string{
diff --git a/client/client.go b/client/client.go
index 5d63d1e..b5a52a7 100644
--- a/client/client.go
+++ b/client/client.go
@@ -223,7 +223,8 @@ func (c *Client) Delete(ctx context.Context, kvID, labelID string, opts ...OpOpt
 	if options.Project == "" {
 		options.Project = defaultProject
 	}
-	url := fmt.Sprintf("%s/%s/%s/%s/?kvID=%s", c.opts.Endpoint, version, options.Project, APIPathKV, kvID)
+	url := fmt.Sprintf("%s/%s/%s/%s/?%s=%s", c.opts.Endpoint, version, options.Project, APIPathKV,
+		common.QueryParamKeyID, kvID)
 	if labelID != "" {
 		url = fmt.Sprintf("%s?labelID=%s", url, labelID)
 	}
diff --git a/pkg/common/common.go b/pkg/common/common.go
index fad017d..ba59d91 100644
--- a/pkg/common/common.go
+++ b/pkg/common/common.go
@@ -23,7 +23,7 @@ const (
 	QueryByLabelsCon = "&"
 	QueryParamWait   = "wait"
 	QueryParamMatch  = "match"
-	QueryParamKeyID  = "kvID"
+	QueryParamKeyID  = "kv_id"
 )
 
 //http headers
diff --git a/server/resource/v1/doc_struct.go b/server/resource/v1/doc_struct.go
index 00e2135..6af548e 100644
--- a/server/resource/v1/doc_struct.go
+++ b/server/resource/v1/doc_struct.go
@@ -68,23 +68,12 @@ var (
 		ParamType: goRestful.QueryParameterKind,
 		Required:  true,
 	}
-	DocQueryKeyParameters = &restful.Parameters{
-		DataType:  "string",
-		Name:      "key",
-		ParamType: goRestful.QueryParameterKind,
-		Desc:      "only return history about a specific key",
-	}
 	DocQueryLabelParameters = &restful.Parameters{
 		DataType:  "string",
 		Name:      "label",
 		ParamType: goRestful.QueryParameterKind,
 		Desc:      "label pairs,for example &label=service:order&label=version:1.0.0",
 	}
-	DocQueryLabelIDParameters = &restful.Parameters{
-		DataType:  "string",
-		Name:      "labelID",
-		ParamType: goRestful.QueryParameterKind,
-	}
 )
 
 //swagger doc path params
@@ -112,7 +101,7 @@ var (
 //KVBody is open api doc
 type KVBody struct {
 	Labels    map[string]string `json:"labels"`
-	ValueType string            `json:"valueType"`
+	ValueType string            `json:"value_type"`
 	Value     string            `json:"value"`
 }
 
diff --git a/server/resource/v1/kv_resource.go b/server/resource/v1/kv_resource.go
index f38c9eb..785d10b 100644
--- a/server/resource/v1/kv_resource.go
+++ b/server/resource/v1/kv_resource.go
@@ -233,6 +233,7 @@ func (r *KVResource) Delete(context *restful.Context) {
 	domain := ReadDomain(context)
 	if domain == nil {
 		WriteErrResponse(context, http.StatusInternalServerError, MsgDomainMustNotBeEmpty, common.ContentTypeText)
+		return
 	}
 	kvID := context.ReadQueryParameter(common.QueryParamKeyID)
 	if kvID == "" {
@@ -329,7 +330,7 @@ func (r *KVResource) URLPatterns() []restful.Route {
 			Method:       http.MethodDelete,
 			Path:         "/v1/{project}/kie/kv",
 			ResourceFunc: r.Delete,
-			FuncDesc:     "delete key by kvID and labelID. Want better performance, give labelID",
+			FuncDesc:     "delete key by kv ID.",
 			Parameters: []*restful.Parameters{
 				DocPathProject,
 				DocQueryKeyIDParameters,
diff --git a/server/resource/v1/kv_resource_test.go b/server/resource/v1/kv_resource_test.go
index 382e2de..85ed987 100644
--- a/server/resource/v1/kv_resource_test.go
+++ b/server/resource/v1/kv_resource_test.go
@@ -59,11 +59,10 @@ func init() {
 	if err != nil {
 		panic(err)
 	}
-}
-func TestKVResource_List(t *testing.T) {
-
 	pubsub.Init()
 	pubsub.Start()
+}
+func TestKVResource_Put(t *testing.T) {
 	t.Run("put kv, label is service", func(t *testing.T) {
 		kv := &model.KVDoc{
 			Value:  "1s",
@@ -111,6 +110,8 @@ func TestKVResource_List(t *testing.T) {
 		assert.NoError(t, err)
 		assert.NotEmpty(t, data.ID)
 	})
+}
+func TestKVResource_List(t *testing.T) {
 	t.Run("list kv by service label, should return 2 kvs", func(t *testing.T) {
 		r, _ := http.NewRequest("GET", "/v1/test/kie/kv?label=service:utService", nil)
 		noopH := &handler2.NoopAuthHandler{}
@@ -145,6 +146,9 @@ func TestKVResource_List(t *testing.T) {
 		assert.NoError(t, err)
 		assert.Equal(t, 1, len(result.Data))
 	})
+
+}
+func TestKVResource_GetByKey(t *testing.T) {
 	t.Run("get one key by label, exact match,should return 1 kv", func(t *testing.T) {
 		r, _ := http.NewRequest("GET", "/v1/test/kie/kv/timeout?label=service:utService&match=exact", nil)
 		noopH := &handler2.NoopAuthHandler{}
@@ -162,7 +166,7 @@ func TestKVResource_List(t *testing.T) {
 		assert.NoError(t, err)
 		assert.Equal(t, 1, len(result.Data))
 	})
-	t.Run("get one key by service label should return 2 kv", func(t *testing.T) {
+	t.Run("get one key by service label should return 2 kv,delete one", func(t *testing.T) {
 		r, _ := http.NewRequest("GET", "/v1/test/kie/kv/timeout?label=service:utService", nil)
 		noopH := &handler2.NoopAuthHandler{}
 		chain, _ := handler.CreateChain(common.Provider, "testchain1", noopH.Name())
@@ -178,5 +182,13 @@ func TestKVResource_List(t *testing.T) {
 		err = json.Unmarshal(body, result)
 		assert.NoError(t, err)
 		assert.Equal(t, 2, len(result.Data))
+
+		r2, _ := http.NewRequest("DELETE", "/v1/test/kie/kv?kv_id="+result.Data[0].ID, nil)
+		c2, err := restfultest.New(kvr, chain)
+		assert.NoError(t, err)
+		resp2 := httptest.NewRecorder()
+		c2.ServeHTTP(resp2, r2)
+		assert.Equal(t, http.StatusNoContent, resp2.Code)
+
 	})
 }