#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
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 @@
//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 @@
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 @@
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 @@
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 @@
//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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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)
+
})
}