Skip to content

Commit

Permalink
apache#79 add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
GuoYL123 committed Feb 26, 2020
1 parent 1330bb7 commit 1ecd068
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions server/resource/v1/history_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
package v1_test

import (
"bytes"
"context"
"encoding/json"
"fmt"
"github.com/apache/servicecomb-kie/pkg/model"
handler2 "github.com/apache/servicecomb-kie/server/handler"
v1 "github.com/apache/servicecomb-kie/server/resource/v1"
"github.com/apache/servicecomb-kie/server/service"
"github.com/go-chassis/go-chassis/core/common"
Expand Down Expand Up @@ -83,3 +85,49 @@ func TestHistoryResource_GetRevisions(t *testing.T) {
})

}

func TestHistoryResource_GetPollingData(t *testing.T) {
t.Run("put kv, label is service", 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/timeout", 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("get polling data", func(t *testing.T) {
r, _ := http.NewRequest("GET", "/v1/test/kie/kv/record?instanceId=test&domain=default", nil)
noopH := &handler2.NoopAuthHandler{}
chain, _ := handler.CreateChain(common.Provider, "testchain1", noopH.Name())
r.Header.Set("Content-Type", "application/json")
kvr := &v1.KVResource{}
c, err := restfultest.New(kvr, chain)
assert.NoError(t, err)
resp := httptest.NewRecorder()
c.ServeHTTP(resp, r)
body, err := ioutil.ReadAll(resp.Body)
assert.NoError(t, err)
result := &[]model.PollingDetail{}
err = json.Unmarshal(body, result)
assert.NoError(t, err)
assert.NotEmpty(t, result)
})

}

0 comments on commit 1ecd068

Please sign in to comment.