diff --git a/server/resource/v1/history_resource_test.go b/server/resource/v1/history_resource_test.go index 07004c67..d0ac140e 100644 --- a/server/resource/v1/history_resource_test.go +++ b/server/resource/v1/history_resource_test.go @@ -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" @@ -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) + }) + +}