Skip to content

Commit

Permalink
ut
Browse files Browse the repository at this point in the history
Signed-off-by: zhulijian <zhulijian1@huawei.com>
  • Loading branch information
zhulijian1 committed Feb 27, 2020
1 parent 084e907 commit b4bd69f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
3 changes: 2 additions & 1 deletion scripts/travis/start_deps.sh
Expand Up @@ -17,4 +17,5 @@

cd build
bash build_docker.sh
sudo docker-compose -f $GOPATH/src/github.com/apache/servicecomb-kie/deployments/docker/docker-compose.yaml up -d
sudo docker-compose -f $GOPATH/src/github.com/apache/servicecomb-kie/deployments/docker/docker-compose.yaml down
sudo docker-compose -f $GOPATH/src/github.com/apache/servicecomb-kie/deployments/docker/docker-compose.yaml up -d
1 change: 1 addition & 0 deletions scripts/travis/unit_test.sh
Expand Up @@ -18,6 +18,7 @@ set -e
# Make the Coverage File
echo "mode: atomic" > coverage.txt

go clean -testcache
#Start the Test
for d in $(go list ./... | grep -v vendor | grep -v third_party | grep -v examples); do
echo $d
Expand Down
33 changes: 29 additions & 4 deletions server/resource/v1/kv_resource_test.go
Expand Up @@ -91,6 +91,31 @@ func TestKVResource_Put(t *testing.T) {
assert.Equal(t, kv.Value, data.Value)
assert.Equal(t, kv.Labels, data.Labels)
})
t.Run("put a different key, which label is same to timeout", func(t *testing.T) {
kv := &model.KVDoc{
Value: "1s",
Labels: map[string]string{"service": "utService"},
}
j, _ := json.Marshal(kv)
r, _ := http.NewRequest("PUT", "/v1/test/kie/kv/interval", bytes.NewBuffer(j))
noopH := &handler2.NoopAuthHandler{}
chain, _ := handler.CreateChain(common.Provider, "testchain1", noopH.Name())
r.Header.Set("Content-Type", "application/json")
r.Header.Set("sessionID", "test")
kvr := &v1.KVResource{}
c, _ := restfultest.New(kvr, chain)
resp := httptest.NewRecorder()
c.ServeHTTP(resp, r)

body, err := ioutil.ReadAll(resp.Body)
assert.NoError(t, err)
data := &model.KVDoc{}
err = json.Unmarshal(body, data)
assert.NoError(t, err)
assert.NotEmpty(t, data.ID)
assert.Equal(t, kv.Value, data.Value)
assert.Equal(t, kv.Labels, data.Labels)
})
t.Run("put kv,label is service and version", func(t *testing.T) {
kv := &model.KVDoc{
Value: "1s",
Expand All @@ -117,7 +142,7 @@ func TestKVResource_Put(t *testing.T) {
})
}
func TestKVResource_List(t *testing.T) {
t.Run("list kv by service label, should return 2 kvs", func(t *testing.T) {
t.Run("list kv by service label, should return 3 kvs", func(t *testing.T) {
r, _ := http.NewRequest("GET", "/v1/test/kie/kv?label=service:utService", nil)
noopH := &handler2.NoopAuthHandler{}
chain, _ := handler.CreateChain(common.Provider, "testchain1", noopH.Name())
Expand All @@ -132,10 +157,10 @@ func TestKVResource_List(t *testing.T) {
result := &model.KVResponse{}
err = json.Unmarshal(body, result)
assert.NoError(t, err)
assert.Equal(t, 2, len(result.Data))
assert.Equal(t, 3, len(result.Data))
})
var rev string
t.Run("list kv by service label, exact match,should return 1 kv", func(t *testing.T) {
t.Run("list kv by service label, exact match,should return 2 kv", func(t *testing.T) {
r, _ := http.NewRequest("GET", "/v1/test/kie/kv?label=service:utService&match=exact", nil)
noopH := &handler2.NoopAuthHandler{}
chain, _ := handler.CreateChain(common.Provider, "testchain1", noopH.Name())
Expand All @@ -150,7 +175,7 @@ func TestKVResource_List(t *testing.T) {
result := &model.KVResponse{}
err = json.Unmarshal(body, result)
assert.NoError(t, err)
assert.Equal(t, 1, len(result.Data))
assert.Equal(t, 2, len(result.Data))
rev = resp.Header().Get(common2.HeaderRevision)
})
t.Run("list kv by service label, with current rev param,should return 304 ", func(t *testing.T) {
Expand Down

0 comments on commit b4bd69f

Please sign in to comment.