This is an automated email from the ASF dual-hosted git repository.
juzhiyuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix-dashboard.git
The following commit(s) were added to refs/heads/master by this push:
new 4cf46b0 feat: Add returning value for HTTP PUT and PATCH methods
(#1322)
4cf46b0 is described below
commit 4cf46b054ce5d9cfc24c29e49321dba266db511e
Author: Joey <[email protected]>
AuthorDate: Tue Jan 19 10:20:21 2021 +0800
feat: Add returning value for HTTP PUT and PATCH methods (#1322)
* Add returning value for Updating entity (PUT/PATCH)
Signed-off-by: imjoey <[email protected]>
* Fix missing return obj when create-if-not-exist
Signed-off-by: imjoey <[email protected]>
* Fix backend Unit and e2e test
Signed-off-by: imjoey <[email protected]>
---
api/internal/core/store/store.go | 19 ++++---
api/internal/core/store/store_mock.go | 4 +-
api/internal/core/store/store_test.go | 7 ++-
api/internal/handler/consumer/consumer.go | 5 +-
api/internal/handler/consumer/consumer_test.go | 58 ++++++++++++++++++++--
api/internal/handler/global_rule/global_rule.go | 10 ++--
.../handler/global_rule/global_rule_test.go | 19 ++++++-
api/internal/handler/route/route.go | 12 +++--
api/internal/handler/route/route_test.go | 31 ++++++++++--
api/internal/handler/service/service.go | 10 ++--
api/internal/handler/service/service_test.go | 7 ++-
api/internal/handler/ssl/ssl.go | 10 ++--
api/internal/handler/ssl/ssl_test.go | 8 ++-
api/internal/handler/upstream/upstream.go | 10 ++--
api/internal/handler/upstream/upstream_test.go | 6 ++-
api/test/e2e/consumer_test.go | 6 +--
api/test/e2e/global_rule_test.go | 4 ++
api/test/e2e/route_test.go | 3 ++
api/test/e2e/service_test.go | 1 +
api/test/e2e/ssl_test.go | 2 +
.../upstream_chash_query_string_arg_xxx_test.go | 2 +
21 files changed, 183 insertions(+), 51 deletions(-)
diff --git a/api/internal/core/store/store.go b/api/internal/core/store/store.go
index e71e5df..eff9435 100644
--- a/api/internal/core/store/store.go
+++ b/api/internal/core/store/store.go
@@ -38,7 +38,7 @@ type Interface interface {
Get(ctx context.Context, key string) (interface{}, error)
List(ctx context.Context, input ListInput) (*ListOutput, error)
Create(ctx context.Context, obj interface{}) (interface{}, error)
- Update(ctx context.Context, obj interface{}, createIfNotExist bool)
error
+ Update(ctx context.Context, obj interface{}, createIfNotExist bool)
(interface{}, error)
BatchDelete(ctx context.Context, keys []string) error
}
@@ -272,23 +272,22 @@ func (s *GenericStore) Create(ctx context.Context, obj
interface{}) (interface{}
return obj, nil
}
-func (s *GenericStore) Update(ctx context.Context, obj interface{},
createIfNotExist bool) error {
+func (s *GenericStore) Update(ctx context.Context, obj interface{},
createIfNotExist bool) (interface{}, error) {
if err := s.ingestValidate(obj); err != nil {
- return err
+ return nil, err
}
key := s.opt.KeyFunc(obj)
if key == "" {
- return fmt.Errorf("key is required")
+ return nil, fmt.Errorf("key is required")
}
storedObj, ok := s.cache.Load(key)
if !ok {
if createIfNotExist {
- _, err := s.Create(ctx, obj)
- return err
+ return s.Create(ctx, obj)
}
log.Warnf("key: %s is not found", key)
- return fmt.Errorf("key: %s is not found", key)
+ return nil, fmt.Errorf("key: %s is not found", key)
}
if setter, ok := obj.(entity.BaseInfoGetter); ok {
@@ -301,13 +300,13 @@ func (s *GenericStore) Update(ctx context.Context, obj
interface{}, createIfNotE
bs, err := json.Marshal(obj)
if err != nil {
log.Errorf("json marshal failed: %s", err)
- return fmt.Errorf("json marshal failed: %s", err)
+ return nil, fmt.Errorf("json marshal failed: %s", err)
}
if err := s.Stg.Update(ctx, s.GetObjStorageKey(obj), string(bs)); err
!= nil {
- return err
+ return nil, err
}
- return nil
+ return obj, nil
}
func (s *GenericStore) BatchDelete(ctx context.Context, keys []string) error {
diff --git a/api/internal/core/store/store_mock.go
b/api/internal/core/store/store_mock.go
index 8d29757..436ef6b 100644
--- a/api/internal/core/store/store_mock.go
+++ b/api/internal/core/store/store_mock.go
@@ -54,9 +54,9 @@ func (m *MockInterface) Create(ctx context.Context, obj
interface{}) (interface{
return ret.Get(0), ret.Error(1)
}
-func (m *MockInterface) Update(ctx context.Context, obj interface{},
createOnFail bool) error {
+func (m *MockInterface) Update(ctx context.Context, obj interface{},
createOnFail bool) (interface{}, error) {
ret := m.Mock.Called(ctx, obj, createOnFail)
- return ret.Error(0)
+ return ret.Get(0), ret.Error(1)
}
func (m *MockInterface) BatchDelete(ctx context.Context, keys []string) error {
diff --git a/api/internal/core/store/store_test.go
b/api/internal/core/store/store_test.go
index 990ddd6..5d682c2 100644
--- a/api/internal/core/store/store_test.go
+++ b/api/internal/core/store/store_test.go
@@ -726,12 +726,17 @@ func TestGenericStore_Update(t *testing.T) {
tc.giveStore.Stg = mStorage
tc.giveStore.opt.Validator = mValidator
- err := tc.giveStore.Update(context.TODO(), tc.giveObj, false)
+ ret, err := tc.giveStore.Update(context.TODO(), tc.giveObj,
false)
assert.True(t, validateCalled, tc.caseDesc)
if err != nil {
assert.Equal(t, tc.wantErr, err, tc.caseDesc)
continue
}
+ retTs, ok := ret.(*TestStruct)
+ assert.True(t, ok)
+ // The returned value (retTs) should be the same as the input
(tc.giveObj)
+ assert.Equal(t, tc.giveObj.Field1, retTs.Field1, tc.caseDesc)
+ assert.Equal(t, tc.giveObj.Field2, retTs.Field2, tc.caseDesc)
assert.True(t, createCalled, tc.caseDesc)
}
}
diff --git a/api/internal/handler/consumer/consumer.go
b/api/internal/handler/consumer/consumer.go
index 2c0cde2..62b1b3d 100644
--- a/api/internal/handler/consumer/consumer.go
+++ b/api/internal/handler/consumer/consumer.go
@@ -147,11 +147,12 @@ func (h *Handler) Set(c droplet.Context) (interface{},
error) {
input.Consumer.ID = input.Consumer.Username
ensurePluginsDefValue(input.Plugins)
- if err := h.consumerStore.Update(c.Context(), &input.Consumer, true);
err != nil {
+ ret, err := h.consumerStore.Update(c.Context(), &input.Consumer, true)
+ if err != nil {
return handler.SpecCodeResponse(err), err
}
- return nil, nil
+ return ret, nil
}
func ensurePluginsDefValue(plugins map[string]interface{}) {
diff --git a/api/internal/handler/consumer/consumer_test.go
b/api/internal/handler/consumer/consumer_test.go
index 873b52a..0bc5eab 100644
--- a/api/internal/handler/consumer/consumer_test.go
+++ b/api/internal/handler/consumer/consumer_test.go
@@ -177,6 +177,7 @@ func TestHandler_Create(t *testing.T) {
giveInput *SetInput
giveCtx context.Context
giveErr error
+ giveRet interface{}
wantErr error
wantInput *SetInput
wantRet interface{}
@@ -193,6 +194,17 @@ func TestHandler_Create(t *testing.T) {
},
},
giveCtx: context.WithValue(context.Background(),
"test", "value"),
+ giveRet: &entity.Consumer{
+ BaseInfo: entity.BaseInfo{
+ ID: "name",
+ },
+ Username: "name",
+ Plugins: map[string]interface{}{
+ "jwt-auth": map[string]interface{}{
+ "exp": 86400,
+ },
+ },
+ },
wantInput: &SetInput{
Consumer: entity.Consumer{
BaseInfo: entity.BaseInfo{
@@ -206,7 +218,17 @@ func TestHandler_Create(t *testing.T) {
},
},
},
- wantRet: nil,
+ wantRet: &entity.Consumer{
+ BaseInfo: entity.BaseInfo{
+ ID: "name",
+ },
+ Username: "name",
+ Plugins: map[string]interface{}{
+ "jwt-auth": map[string]interface{}{
+ "exp": 86400,
+ },
+ },
+ },
wantCalled: true,
},
{
@@ -221,6 +243,9 @@ func TestHandler_Create(t *testing.T) {
},
},
},
+ giveRet: &data.SpecCodeResponse{
+ StatusCode: http.StatusInternalServerError,
+ },
giveErr: fmt.Errorf("create failed"),
wantInput: &SetInput{
Consumer: entity.Consumer{
@@ -252,7 +277,7 @@ func TestHandler_Create(t *testing.T) {
assert.Equal(t, tc.giveCtx, args.Get(0))
assert.Equal(t, &tc.wantInput.Consumer,
args.Get(1))
assert.True(t, args.Bool(2))
- }).Return(tc.giveErr)
+ }).Return(tc.giveRet, tc.giveErr)
h := Handler{consumerStore: mStore}
ctx := droplet.NewContext()
@@ -271,6 +296,7 @@ func TestHandler_Update(t *testing.T) {
caseDesc string
giveInput *SetInput
giveCtx context.Context
+ giveRet interface{}
giveErr error
wantErr error
wantInput *entity.Consumer
@@ -290,6 +316,17 @@ func TestHandler_Update(t *testing.T) {
},
},
giveCtx: context.WithValue(context.Background(),
"test", "value"),
+ giveRet: &entity.Consumer{
+ BaseInfo: entity.BaseInfo{
+ ID: "name",
+ },
+ Username: "name",
+ Plugins: map[string]interface{}{
+ "jwt-auth": map[string]interface{}{
+ "exp": 500,
+ },
+ },
+ },
wantInput: &entity.Consumer{
BaseInfo: entity.BaseInfo{
ID: "name",
@@ -301,7 +338,17 @@ func TestHandler_Update(t *testing.T) {
},
},
},
- wantRet: nil,
+ wantRet: &entity.Consumer{
+ BaseInfo: entity.BaseInfo{
+ ID: "name",
+ },
+ Username: "name",
+ Plugins: map[string]interface{}{
+ "jwt-auth": map[string]interface{}{
+ "exp": 500,
+ },
+ },
+ },
wantCalled: true,
},
{
@@ -314,6 +361,9 @@ func TestHandler_Update(t *testing.T) {
},
},
},
+ giveRet: &data.SpecCodeResponse{
+ StatusCode: http.StatusInternalServerError,
+ },
giveErr: fmt.Errorf("create failed"),
wantInput: &entity.Consumer{
BaseInfo: entity.BaseInfo{
@@ -343,7 +393,7 @@ func TestHandler_Update(t *testing.T) {
assert.Equal(t, tc.giveCtx, args.Get(0))
assert.Equal(t, tc.wantInput, args.Get(1))
assert.True(t, args.Bool(2))
- }).Return(tc.giveErr)
+ }).Return(tc.giveRet, tc.giveErr)
h := Handler{consumerStore: mStore}
ctx := droplet.NewContext()
diff --git a/api/internal/handler/global_rule/global_rule.go
b/api/internal/handler/global_rule/global_rule.go
index 8a5975b..cb7630a 100644
--- a/api/internal/handler/global_rule/global_rule.go
+++ b/api/internal/handler/global_rule/global_rule.go
@@ -141,11 +141,12 @@ func (h *Handler) Set(c droplet.Context) (interface{},
error) {
input.GlobalPlugins.ID = input.ID
}
- if err := h.globalRuleStore.Update(c.Context(), &input.GlobalPlugins,
true); err != nil {
+ ret, err := h.globalRuleStore.Update(c.Context(), &input.GlobalPlugins,
true)
+ if err != nil {
return handler.SpecCodeResponse(err), err
}
- return nil, nil
+ return ret, nil
}
func Patch(c *gin.Context) (interface{}, error) {
@@ -170,11 +171,12 @@ func Patch(c *gin.Context) (interface{}, error) {
return handler.SpecCodeResponse(err), err
}
- if err := routeStore.Update(c, &globalRule, false); err != nil {
+ ret, err := routeStore.Update(c, &globalRule, false)
+ if err != nil {
return handler.SpecCodeResponse(err), err
}
- return nil, nil
+ return ret, nil
}
type BatchDeleteInput struct {
diff --git a/api/internal/handler/global_rule/global_rule_test.go
b/api/internal/handler/global_rule/global_rule_test.go
index 8b8594e..6e13e9f 100644
--- a/api/internal/handler/global_rule/global_rule_test.go
+++ b/api/internal/handler/global_rule/global_rule_test.go
@@ -211,6 +211,7 @@ func TestHandler_Set(t *testing.T) {
caseDesc string
giveInput *SetInput
giveCtx context.Context
+ giveRet interface{}
giveErr error
wantErr error
wantInput *entity.GlobalPlugins
@@ -228,13 +229,24 @@ func TestHandler_Set(t *testing.T) {
},
},
giveCtx: context.WithValue(context.Background(),
"test", "value"),
+ giveRet: &entity.GlobalPlugins{
+ BaseInfo: entity.BaseInfo{ID: "name"},
+ Plugins: map[string]interface{}{
+ "jwt-auth": map[string]interface{}{},
+ },
+ },
wantInput: &entity.GlobalPlugins{
BaseInfo: entity.BaseInfo{ID: "name"},
Plugins: map[string]interface{}{
"jwt-auth": map[string]interface{}{},
},
},
- wantRet: nil,
+ wantRet: &entity.GlobalPlugins{
+ BaseInfo: entity.BaseInfo{ID: "name"},
+ Plugins: map[string]interface{}{
+ "jwt-auth": map[string]interface{}{},
+ },
+ },
wantCalled: true,
},
{
@@ -244,6 +256,9 @@ func TestHandler_Set(t *testing.T) {
GlobalPlugins: entity.GlobalPlugins{},
},
giveErr: fmt.Errorf("create failed"),
+ giveRet: &data.SpecCodeResponse{
+ StatusCode: http.StatusInternalServerError,
+ },
wantInput: &entity.GlobalPlugins{
BaseInfo: entity.BaseInfo{ID: "name"},
Plugins: map[string]interface{}(nil),
@@ -265,7 +280,7 @@ func TestHandler_Set(t *testing.T) {
assert.Equal(t, tc.giveCtx, args.Get(0))
assert.Equal(t, tc.wantInput, args.Get(1))
assert.True(t, args.Bool(2))
- }).Return(tc.giveErr)
+ }).Return(tc.giveRet, tc.giveErr)
h := Handler{globalRuleStore: mStore}
ctx := droplet.NewContext()
diff --git a/api/internal/handler/route/route.go
b/api/internal/handler/route/route.go
index c462c42..764bf7a 100644
--- a/api/internal/handler/route/route.go
+++ b/api/internal/handler/route/route.go
@@ -101,11 +101,12 @@ func Patch(c *gin.Context) (interface{}, error) {
return handler.SpecCodeResponse(err), err
}
- if err := routeStore.Update(c, &route, false); err != nil {
+ ret, err := routeStore.Update(c, &route, false)
+ if err != nil {
return handler.SpecCodeResponse(err), err
}
- return nil, nil
+ return ret, nil
}
type GetInput struct {
@@ -427,7 +428,7 @@ func (h *Handler) Update(c droplet.Context) (interface{},
error) {
}
//save original conf
- if err = h.scriptStore.Update(c.Context(), script, true); err
!= nil {
+ if _, err = h.scriptStore.Update(c.Context(), script, true);
err != nil {
//if not exists, create
if err.Error() == fmt.Sprintf("key: %s is not found",
script.ID) {
if _, err := h.scriptStore.Create(c.Context(),
script); err != nil {
@@ -448,11 +449,12 @@ func (h *Handler) Update(c droplet.Context) (interface{},
error) {
}
}
- if err := h.routeStore.Update(c.Context(), &input.Route, true); err !=
nil {
+ ret, err := h.routeStore.Update(c.Context(), &input.Route, true)
+ if err != nil {
return handler.SpecCodeResponse(err), err
}
- return nil, nil
+ return ret, nil
}
type BatchDelete struct {
diff --git a/api/internal/handler/route/route_test.go
b/api/internal/handler/route/route_test.go
index af7caf1..d875b21 100644
--- a/api/internal/handler/route/route_test.go
+++ b/api/internal/handler/route/route_test.go
@@ -757,8 +757,13 @@ func TestRoute(t *testing.T) {
err = json.Unmarshal([]byte(reqBody), route2)
assert.Nil(t, err)
ctx.SetInput(route2)
- _, err = handler.Update(ctx)
+ ret, err = handler.Update(ctx)
assert.Nil(t, err)
+ // check the returned value
+ objRet, ok = ret.(*entity.Route)
+ assert.True(t, ok)
+ assert.Equal(t, route2.ID, objRet.ID)
+ assert.Equal(t, route2.Labels, objRet.Labels)
//sleep
time.Sleep(time.Duration(100) * time.Millisecond)
@@ -819,6 +824,10 @@ func TestRoute(t *testing.T) {
ctx.SetInput(errRoute)
ret, err = handler.Update(ctx)
assert.Nil(t, err)
+ // Check the returned value
+ objRet, ok = ret.(*entity.Route)
+ assert.True(t, ok)
+ assert.Equal(t, errRoute.ID, objRet.ID)
// Success: tests the Body ID can be nil
reqBodyErr = `{
@@ -839,6 +848,10 @@ func TestRoute(t *testing.T) {
ctx.SetInput(errRoute)
ret, err = handler.Update(ctx)
assert.Nil(t, err)
+ // Check the returned value
+ objRet, ok = ret.(*entity.Route)
+ assert.True(t, ok)
+ assert.Equal(t, errRoute.ID, objRet.ID)
//sleep
time.Sleep(time.Duration(100) * time.Millisecond)
@@ -1337,8 +1350,14 @@ func Test_Route_With_Script_Dag2lua(t *testing.T) {
err = json.Unmarshal([]byte(reqBody), route2)
assert.Nil(t, err)
ctx.SetInput(route2)
- _, err = handler.Update(ctx)
+ ret, err = handler.Update(ctx)
assert.Nil(t, err)
+ // check the returned value
+ objRet, ok = ret.(*entity.Route)
+ assert.True(t, ok)
+ assert.Equal(t, route2.ID, objRet.ID)
+ // script returned should be nil
+ assert.Nil(t, objRet.Script)
//sleep
time.Sleep(time.Duration(100) * time.Millisecond)
@@ -1433,8 +1452,14 @@ func Test_Route_With_Script_Luacode(t *testing.T) {
err = json.Unmarshal([]byte(reqBody), route2)
assert.Nil(t, err)
ctx.SetInput(route2)
- _, err = handler.Update(ctx)
+ ret, err = handler.Update(ctx)
assert.Nil(t, err)
+ // check the returned value
+ objRet, ok := ret.(*entity.Route)
+ assert.True(t, ok)
+ assert.Equal(t, route2.ID, objRet.ID)
+ // script returned should be nil
+ assert.Nil(t, objRet.Script)
//sleep
time.Sleep(time.Duration(100) * time.Millisecond)
diff --git a/api/internal/handler/service/service.go
b/api/internal/handler/service/service.go
index 4272739..240e416 100644
--- a/api/internal/handler/service/service.go
+++ b/api/internal/handler/service/service.go
@@ -202,11 +202,12 @@ func (h *Handler) Update(c droplet.Context) (interface{},
error) {
}
}
- if err := h.serviceStore.Update(c.Context(), &input.Service, true); err
!= nil {
+ ret, err := h.serviceStore.Update(c.Context(), &input.Service, true)
+ if err != nil {
return handler.SpecCodeResponse(err), err
}
- return nil, nil
+ return ret, nil
}
type BatchDelete struct {
@@ -255,9 +256,10 @@ func (h *Handler) Patch(c droplet.Context) (interface{},
error) {
return handler.SpecCodeResponse(err), err
}
- if err := h.serviceStore.Update(c.Context(), &stored, false); err !=
nil {
+ ret, err := h.serviceStore.Update(c.Context(), &stored, false)
+ if err != nil {
return handler.SpecCodeResponse(err), err
}
- return nil, nil
+ return ret, nil
}
diff --git a/api/internal/handler/service/service_test.go
b/api/internal/handler/service/service_test.go
index f0b5bdc..88cd5c3 100644
--- a/api/internal/handler/service/service_test.go
+++ b/api/internal/handler/service/service_test.go
@@ -112,8 +112,13 @@ func TestService(t *testing.T) {
err = json.Unmarshal([]byte(reqBody), service2)
assert.Nil(t, err)
ctx.SetInput(service2)
- _, err = handler.Update(ctx)
+ ret, err = handler.Update(ctx)
assert.Nil(t, err)
+ // Check the returned value
+ objRet, ok = ret.(*entity.Service)
+ assert.True(t, ok)
+ assert.Equal(t, service2.ID, objRet.ID)
+ assert.Equal(t, service2.Name, objRet.Name)
//sleep
time.Sleep(time.Duration(100) * time.Millisecond)
diff --git a/api/internal/handler/ssl/ssl.go b/api/internal/handler/ssl/ssl.go
index da645d8..89793a2 100644
--- a/api/internal/handler/ssl/ssl.go
+++ b/api/internal/handler/ssl/ssl.go
@@ -226,11 +226,12 @@ func (h *Handler) Update(c droplet.Context) (interface{},
error) {
//set default value for SSL status, if not set, it will be 0 which
means disable.
ssl.Status = conf.SSLDefaultStatus
- if err := h.sslStore.Update(c.Context(), ssl, true); err != nil {
+ ret, err := h.sslStore.Update(c.Context(), ssl, true)
+ if err != nil {
return handler.SpecCodeResponse(err), err
}
- return nil, nil
+ return ret, nil
}
func Patch(c *gin.Context) (interface{}, error) {
@@ -255,11 +256,12 @@ func Patch(c *gin.Context) (interface{}, error) {
return handler.SpecCodeResponse(err), err
}
- if err := sslStore.Update(c, &ssl, false); err != nil {
+ ret, err := sslStore.Update(c, &ssl, false)
+ if err != nil {
return handler.SpecCodeResponse(err), err
}
- return nil, nil
+ return ret, nil
}
type BatchDelete struct {
diff --git a/api/internal/handler/ssl/ssl_test.go
b/api/internal/handler/ssl/ssl_test.go
index 52ff8b9..01616a6 100644
--- a/api/internal/handler/ssl/ssl_test.go
+++ b/api/internal/handler/ssl/ssl_test.go
@@ -96,8 +96,14 @@ func TestSSL(t *testing.T) {
err = json.Unmarshal([]byte(reqBody), ssl2)
assert.Nil(t, err)
ctx.SetInput(ssl2)
- _, err = handler.Update(ctx)
+ ret, err = handler.Update(ctx)
assert.Nil(t, err)
+ // check the returned value
+ objRet, ok = ret.(*entity.SSL)
+ assert.True(t, ok)
+ assert.Equal(t, "1", objRet.ID)
+ assert.Equal(t, ssl2.Key, objRet.Key)
+ assert.Equal(t, ssl2.Cert, objRet.Cert)
//sleep
time.Sleep(time.Duration(100) * time.Millisecond)
diff --git a/api/internal/handler/upstream/upstream.go
b/api/internal/handler/upstream/upstream.go
index 2e8cf87..54c3a6e 100644
--- a/api/internal/handler/upstream/upstream.go
+++ b/api/internal/handler/upstream/upstream.go
@@ -174,11 +174,12 @@ func (h *Handler) Update(c droplet.Context) (interface{},
error) {
input.Upstream.ID = input.ID
}
- if err := h.upstreamStore.Update(c.Context(), &input.Upstream, true);
err != nil {
+ ret, err := h.upstreamStore.Update(c.Context(), &input.Upstream, true)
+ if err != nil {
return handler.SpecCodeResponse(err), err
}
- return nil, nil
+ return ret, nil
}
type BatchDelete struct {
@@ -227,11 +228,12 @@ func (h *Handler) Patch(c droplet.Context) (interface{},
error) {
return handler.SpecCodeResponse(err), err
}
- if err := h.upstreamStore.Update(c.Context(), &stored, false); err !=
nil {
+ ret, err := h.upstreamStore.Update(c.Context(), &stored, false)
+ if err != nil {
return handler.SpecCodeResponse(err), err
}
- return nil, nil
+ return ret, nil
}
type ExistInput struct {
diff --git a/api/internal/handler/upstream/upstream_test.go
b/api/internal/handler/upstream/upstream_test.go
index e50bd7a..103fe3c 100644
--- a/api/internal/handler/upstream/upstream_test.go
+++ b/api/internal/handler/upstream/upstream_test.go
@@ -166,8 +166,12 @@ func TestUpstream(t *testing.T) {
err = json.Unmarshal([]byte(reqBody), upstream2)
assert.Nil(t, err)
ctx.SetInput(upstream2)
- _, err = upstreamHandler.Update(ctx)
+ ret, err = upstreamHandler.Update(ctx)
assert.Nil(t, err)
+ // check the returned value
+ objRet, ok = ret.(*entity.Upstream)
+ assert.True(t, ok)
+ assert.Equal(t, upstream2.ID, objRet.ID)
//list
listInput := &ListInput{}
diff --git a/api/test/e2e/consumer_test.go b/api/test/e2e/consumer_test.go
index 6c26170..e16d53c 100644
--- a/api/test/e2e/consumer_test.go
+++ b/api/test/e2e/consumer_test.go
@@ -87,7 +87,7 @@ func TestConsumer_Create_And_Get(t *testing.T) {
}`,
Headers: map[string]string{"Authorization": token},
ExpectStatus: http.StatusOK,
- ExpectBody: "\"code\":0",
+ ExpectBody: []string{"\"code\":0",
"\"username\":\"consumer_2\""},
},
{
Desc: "get consumer",
@@ -156,7 +156,7 @@ func TestConsumer_Update_And_Get(t *testing.T) {
}`,
Headers: map[string]string{"Authorization": token},
ExpectStatus: http.StatusOK,
- ExpectBody: "\"code\":0",
+ ExpectBody: []string{"\"code\":0",
"\"username\":\"consumer_3\"", "\"rejected_code\":503"},
},
{
Desc: "update consumer by PUT",
@@ -177,7 +177,7 @@ func TestConsumer_Update_And_Get(t *testing.T) {
}`,
Headers: map[string]string{"Authorization": token},
ExpectStatus: http.StatusOK,
- ExpectBody: "\"code\":0",
+ ExpectBody: []string{"\"code\":0",
"\"username\":\"consumer_3\"", "\"rejected_code\":504"},
},
{
Desc: "get consumer",
diff --git a/api/test/e2e/global_rule_test.go b/api/test/e2e/global_rule_test.go
index f94a5eb..0ea2d0a 100644
--- a/api/test/e2e/global_rule_test.go
+++ b/api/test/e2e/global_rule_test.go
@@ -74,6 +74,7 @@ func TestGlobalRule(t *testing.T) {
}`,
Headers: map[string]string{"Authorization": token},
ExpectStatus: http.StatusOK,
+ ExpectBody: "\"X-VERSION\":\"1.0\"",
},
{
Desc: "verify route with header",
@@ -119,6 +120,7 @@ func TestGlobalRule(t *testing.T) {
}`,
Headers: map[string]string{"Authorization": token},
ExpectStatus: http.StatusOK,
+ ExpectBody: "\"X-VERSION\":\"2.0\"",
},
{
Desc: "verify route that header should be the
same as the route config",
@@ -154,6 +156,7 @@ func TestGlobalRule(t *testing.T) {
}`,
Headers: map[string]string{"Authorization": token},
ExpectStatus: http.StatusOK,
+ ExpectBody: "\"key-auth\":{}",
},
{
Desc: "make sure that patch succeeded",
@@ -175,6 +178,7 @@ func TestGlobalRule(t *testing.T) {
}`,
Headers: map[string]string{"Authorization": token},
ExpectStatus: http.StatusOK,
+ UnexpectBody: "\"key-auth\":{}",
},
{
Desc: "make sure that patch succeeded",
diff --git a/api/test/e2e/route_test.go b/api/test/e2e/route_test.go
index 7bd4a13..0a606b2 100644
--- a/api/test/e2e/route_test.go
+++ b/api/test/e2e/route_test.go
@@ -131,6 +131,7 @@ func TestRoute_Create_With_Hosts(t *testing.T) {
}`,
Headers: map[string]string{"Authorization": token},
ExpectStatus: http.StatusOK,
+ ExpectBody: []string{"\"id\":\"r1\"",
"\"uri\":\"/hello_\""},
},
{
Desc: "create route with int uri",
@@ -227,6 +228,7 @@ func TestRoute_Update_Routes_With_Hosts(t *testing.T) {
}`,
Headers: map[string]string{"Authorization": token},
ExpectStatus: http.StatusOK,
+ ExpectBody: []string{"\"id\":\"r1\"",
"\"hosts\":[\"foo.com\"]"},
},
{
Desc: "hit the route just create",
@@ -254,6 +256,7 @@ func TestRoute_Update_Routes_With_Hosts(t *testing.T) {
}`,
Headers: map[string]string{"Authorization": token},
ExpectStatus: http.StatusOK,
+ ExpectBody: []string{"\"id\":\"r1\"",
"\"hosts\":[\"bar.com\"]"},
},
{
Desc: "hit the route with host foo.com",
diff --git a/api/test/e2e/service_test.go b/api/test/e2e/service_test.go
index 2f73b37..4d9ebe2 100644
--- a/api/test/e2e/service_test.go
+++ b/api/test/e2e/service_test.go
@@ -54,6 +54,7 @@ func TestService(t *testing.T) {
}
}`,
ExpectStatus: http.StatusOK,
+ ExpectBody: []string{"\"id\":\"s1\"",
"\"name\":\"testservice\""},
},
{
Desc: "get the service s1",
diff --git a/api/test/e2e/ssl_test.go b/api/test/e2e/ssl_test.go
index 8f44c4e..8aafbcf 100644
--- a/api/test/e2e/ssl_test.go
+++ b/api/test/e2e/ssl_test.go
@@ -145,6 +145,7 @@ func TestSSL_Basic(t *testing.T) {
}`,
Headers: map[string]string{"Authorization": token},
ExpectStatus: http.StatusOK,
+ ExpectBody: "\"status\":0",
},
}
@@ -169,6 +170,7 @@ func TestSSL_Basic(t *testing.T) {
Body: `1`,
Headers: map[string]string{"Authorization": token},
ExpectStatus: http.StatusOK,
+ ExpectBody: "\"status\":1",
},
{
Desc: "hit the route using HTTPS, make sure
enable successful",
diff --git a/api/test/e2e/upstream_chash_query_string_arg_xxx_test.go
b/api/test/e2e/upstream_chash_query_string_arg_xxx_test.go
index 02e5149..b176692 100644
--- a/api/test/e2e/upstream_chash_query_string_arg_xxx_test.go
+++ b/api/test/e2e/upstream_chash_query_string_arg_xxx_test.go
@@ -55,6 +55,7 @@ func TestUpstream_chash_query_string(t *testing.T) {
}`,
Headers: map[string]string{"Authorization": token},
ExpectStatus: http.StatusOK,
+ ExpectBody: []string{"\"id\":\"1\"",
"\"key\":\"query_string\""},
},
{
Desc: "create route using the upstream just created",
@@ -131,6 +132,7 @@ func TestUpstream_chash_arg_xxx(t *testing.T) {
}`,
Headers: map[string]string{"Authorization": token},
ExpectStatus: http.StatusOK,
+ ExpectBody: []string{"\"id\":\"1\"",
"\"key\":\"arg_device_id\""},
},
}