You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by as...@apache.org on 2019/06/28 13:21:01 UTC
[servicecomb-kie] branch master updated: add UT for put kv by rest
API
This is an automated email from the ASF dual-hosted git repository.
asifdxtreme 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 b3fb75a add UT for put kv by rest API
new 4d11050 Merge pull request #15 from tianxiaoliang/master
b3fb75a is described below
commit b3fb75a17d99bad7948679bf65fabc942d90a193
Author: tian <xi...@gmail.com>
AuthorDate: Fri Jun 28 18:38:05 2019 +0800
add UT for put kv by rest API
---
client/client.go | 9 +++---
client/options.go | 11 +++----
go.mod | 2 +-
server/config/config.go | 9 +++---
server/resource/v1/kv_resource_test.go | 58 ++++++++++++++++++++++++++++++++++
server/resource/v1/v1_suite_test.go | 1 +
6 files changed, 75 insertions(+), 15 deletions(-)
diff --git a/client/client.go b/client/client.go
index f9df929..58a3c49 100644
--- a/client/client.go
+++ b/client/client.go
@@ -23,7 +23,6 @@ import (
"encoding/json"
"errors"
"fmt"
- "github.com/apache/servicecomb-kie/pkg/common"
"github.com/apache/servicecomb-kie/pkg/model"
"github.com/go-chassis/foundation/httpclient"
"github.com/go-chassis/foundation/security"
@@ -88,9 +87,6 @@ func (c *Client) Get(ctx context.Context, key string, opts ...GetOption) ([]*mod
}
url := fmt.Sprintf("%s/%s/%s", c.opts.Endpoint, APIPathKV, key)
h := http.Header{}
- if options.MatchMode != "" {
- h.Set(common.HeaderMatch, options.MatchMode)
- }
resp, err := c.c.HTTPDoWithContext(ctx, "GET", url, h, nil)
if err != nil {
return nil, err
@@ -100,6 +96,11 @@ func (c *Client) Get(ctx context.Context, key string, opts ...GetOption) ([]*mod
if resp.StatusCode == http.StatusNotFound {
return nil, ErrKeyNotExist
}
+ openlogging.Error("get failed", openlogging.WithTags(openlogging.Tags{
+ "k": key,
+ "status": resp.Status,
+ "body": b,
+ }))
return nil, fmt.Errorf("get %s failed,http status [%s], body [%s]", key, resp.Status, b)
}
diff --git a/client/options.go b/client/options.go
index e56b76e..722175d 100644
--- a/client/options.go
+++ b/client/options.go
@@ -22,8 +22,8 @@ type GetOption func(*GetOptions)
//GetOptions is the options of client func
type GetOptions struct {
- Labels map[string]string
- MatchMode string
+ Labels map[string]string
+ Depth int
}
//WithLabels query kv by labels
@@ -33,10 +33,9 @@ func WithLabels(l map[string]string) GetOption {
}
}
-//WithMatchMode has 2 modes
-//exact and greedy
-func WithMatchMode(m string) GetOption {
+//WithDepth query keys with partial match query labels
+func WithDepth(d int) GetOption {
return func(options *GetOptions) {
- options.MatchMode = m
+ options.Depth = d
}
}
diff --git a/go.mod b/go.mod
index 2540c72..77abed3 100644
--- a/go.mod
+++ b/go.mod
@@ -4,7 +4,7 @@ require (
github.com/emicklei/go-restful v2.8.0+incompatible
github.com/go-chassis/foundation v0.0.0-20190516083152-b8b2476b6db7
github.com/go-chassis/go-archaius v0.18.0
- github.com/go-chassis/go-chassis v1.4.3
+ github.com/go-chassis/go-chassis v1.5.0
github.com/go-chassis/paas-lager v1.0.2-0.20190328010332-cf506050ddb2
github.com/go-mesh/openlogging v1.0.1-0.20181205082104-3d418c478b2d
github.com/onsi/ginkgo v1.8.0
diff --git a/server/config/config.go b/server/config/config.go
index 36b66c2..00494ad 100644
--- a/server/config/config.go
+++ b/server/config/config.go
@@ -24,7 +24,8 @@ import (
"path/filepath"
)
-var configurations *Config
+//Configurations is kie config items
+var Configurations *Config
//Init initiate config files
func Init(file string) error {
@@ -33,8 +34,8 @@ func Init(file string) error {
}
_, filename := filepath.Split(file)
content := archaius.GetString(filename, "")
- configurations = &Config{}
- if err := yaml.Unmarshal([]byte(content), configurations); err != nil {
+ Configurations = &Config{}
+ if err := yaml.Unmarshal([]byte(content), Configurations); err != nil {
return err
}
return nil
@@ -42,5 +43,5 @@ func Init(file string) error {
//GetDB return db configs
func GetDB() DB {
- return configurations.DB
+ return Configurations.DB
}
diff --git a/server/resource/v1/kv_resource_test.go b/server/resource/v1/kv_resource_test.go
new file mode 100644
index 0000000..8119ef0
--- /dev/null
+++ b/server/resource/v1/kv_resource_test.go
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package v1_test
+
+import (
+ . "github.com/onsi/ginkgo"
+ . "github.com/onsi/gomega"
+
+ "bytes"
+ "context"
+ "encoding/json"
+ "github.com/apache/servicecomb-kie/pkg/model"
+ "github.com/apache/servicecomb-kie/server/config"
+ "github.com/apache/servicecomb-kie/server/resource/v1"
+ "github.com/go-chassis/go-chassis/server/restful/restfultest"
+ "net/http"
+)
+
+var _ = Describe("v1 kv resource", func() {
+ //for UT
+ config.Configurations = &config.Config{
+ DB: config.DB{},
+ }
+ Describe("put kv", func() {
+ config.Configurations.DB.URI = "mongodb://kie:123@127.0.0.1:27017"
+ Context("valid param", func() {
+ kv := &model.KVDoc{
+ Value: "1s",
+ Labels: map[string]string{"service": "tester"},
+ }
+ j, _ := json.Marshal(kv)
+ r, _ := http.NewRequest("PUT", "/v1/kv/timeout", bytes.NewBuffer(j))
+ rctx := restfultest.NewRestfulContext(context.Background(), r)
+ rctx.ReadRestfulRequest().SetAttribute("domain", "default")
+ kvr := &v1.KVResource{}
+ kvr.Put(rctx)
+ It("should be 200 ", func() {
+ Expect(rctx.Resp.StatusCode()).Should(Equal(http.StatusOK))
+ })
+
+ })
+ })
+})
diff --git a/server/resource/v1/v1_suite_test.go b/server/resource/v1/v1_suite_test.go
index 99a2884..545cd80 100644
--- a/server/resource/v1/v1_suite_test.go
+++ b/server/resource/v1/v1_suite_test.go
@@ -27,4 +27,5 @@ import (
func TestV1(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "V1 Suite")
+
}