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 754f559  feat: return back the data just created via POST method in 
manager API (#1277)
754f559 is described below

commit 754f5598706fe5dfe9a09bf0d51d0701406c692c
Author: Joey <[email protected]>
AuthorDate: Sun Jan 17 12:18:00 2021 +0800

    feat: return back the data just created via POST method in manager API 
(#1277)
    
    * return saving object for store.Create
    
    Signed-off-by: imjoey <[email protected]>
    
    * Add backend e2e test for returning from Create-via-POST
    
    Signed-off-by: imjoey <[email protected]>
    
    * Fix incorrect HTTP method
    
    Signed-off-by: imjoey <[email protected]>
---
 api/internal/core/store/store.go               | 19 ++++----
 api/internal/core/store/store_mock.go          |  5 +-
 api/internal/core/store/store_test.go          |  7 ++-
 api/internal/handler/route/route.go            |  9 ++--
 api/internal/handler/route/route_test.go       | 27 ++++++++---
 api/internal/handler/service/service.go        |  5 +-
 api/internal/handler/service/service_test.go   | 12 +++--
 api/internal/handler/ssl/ssl.go                |  5 +-
 api/internal/handler/ssl/ssl_test.go           |  7 ++-
 api/internal/handler/upstream/upstream.go      |  5 +-
 api/internal/handler/upstream/upstream_test.go | 14 ++++--
 api/test/e2e/route_test.go                     | 66 +++++++++++++++++++++++++
 api/test/e2e/service_test.go                   | 29 ++++++++---
 api/test/e2e/ssl_test.go                       |  1 +
 api/test/e2e/upstream_test.go                  | 67 ++++++++++++++++++++++++++
 15 files changed, 233 insertions(+), 45 deletions(-)

diff --git a/api/internal/core/store/store.go b/api/internal/core/store/store.go
index 9a4b113..794375b 100644
--- a/api/internal/core/store/store.go
+++ b/api/internal/core/store/store.go
@@ -37,7 +37,7 @@ import (
 type Interface interface {
        Get(key string) (interface{}, error)
        List(input ListInput) (*ListOutput, error)
-       Create(ctx context.Context, obj interface{}) error
+       Create(ctx context.Context, obj interface{}) (interface{}, error)
        Update(ctx context.Context, obj interface{}, createIfNotExist bool) 
error
        BatchDelete(ctx context.Context, keys []string) error
 }
@@ -240,36 +240,36 @@ func (s *GenericStore) ingestValidate(obj interface{}) 
(err error) {
        return err
 }
 
-func (s *GenericStore) Create(ctx context.Context, obj interface{}) error {
+func (s *GenericStore) Create(ctx context.Context, obj interface{}) 
(interface{}, error) {
        if setter, ok := obj.(entity.BaseInfoSetter); ok {
                info := setter.GetBaseInfo()
                info.Creating()
        }
 
        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")
        }
        _, ok := s.cache.Load(key)
        if ok {
                log.Warnf("key: %s is conflicted", key)
-               return fmt.Errorf("key: %s is conflicted", key)
+               return nil, fmt.Errorf("key: %s is conflicted", key)
        }
 
        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.Create(ctx, s.GetObjStorageKey(obj), string(bs)); err 
!= nil {
-               return err
+               return nil, err
        }
 
-       return nil
+       return obj, nil
 }
 
 func (s *GenericStore) Update(ctx context.Context, obj interface{}, 
createIfNotExist bool) error {
@@ -284,7 +284,8 @@ func (s *GenericStore) Update(ctx context.Context, obj 
interface{}, createIfNotE
        storedObj, ok := s.cache.Load(key)
        if !ok {
                if createIfNotExist {
-                       return s.Create(ctx, obj)
+                       _, err := s.Create(ctx, obj)
+                       return err
                }
                log.Warnf("key: %s is not found", key)
                return fmt.Errorf("key: %s is not found", key)
diff --git a/api/internal/core/store/store_mock.go 
b/api/internal/core/store/store_mock.go
index 258f083..a974ed6 100644
--- a/api/internal/core/store/store_mock.go
+++ b/api/internal/core/store/store_mock.go
@@ -18,6 +18,7 @@ package store
 
 import (
        "context"
+
        "github.com/stretchr/testify/mock"
 )
 
@@ -48,9 +49,9 @@ func (m *MockInterface) List(input ListInput) (*ListOutput, 
error) {
        return r0, r1
 }
 
-func (m *MockInterface) Create(ctx context.Context, obj interface{}) error {
+func (m *MockInterface) Create(ctx context.Context, obj interface{}) 
(interface{}, error) {
        ret := m.Mock.Called(ctx, obj)
-       return ret.Error(0)
+       return ret.Get(0), ret.Error(1)
 }
 
 func (m *MockInterface) Update(ctx context.Context, obj interface{}, 
createOnFail bool) error {
diff --git a/api/internal/core/store/store_test.go 
b/api/internal/core/store/store_test.go
index 9bc1159..8763a4d 100644
--- a/api/internal/core/store/store_test.go
+++ b/api/internal/core/store/store_test.go
@@ -613,12 +613,17 @@ func TestGenericStore_Create(t *testing.T) {
 
                tc.giveStore.Stg = mStorage
                tc.giveStore.opt.Validator = mValidator
-               err := tc.giveStore.Create(context.TODO(), tc.giveObj)
+               ret, err := tc.giveStore.Create(context.TODO(), tc.giveObj)
                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/route/route.go 
b/api/internal/handler/route/route.go
index 73f0fa6..6f4fadb 100644
--- a/api/internal/handler/route/route.go
+++ b/api/internal/handler/route/route.go
@@ -348,16 +348,17 @@ func (h *Handler) Create(c droplet.Context) (interface{}, 
error) {
                }
 
                //save original conf
-               if err = h.scriptStore.Create(c.Context(), script); err != nil {
+               if _, err = h.scriptStore.Create(c.Context(), script); err != 
nil {
                        return nil, err
                }
        }
 
-       if err := h.routeStore.Create(c.Context(), input); err != nil {
+       ret, err := h.routeStore.Create(c.Context(), input)
+       if err != nil {
                return handler.SpecCodeResponse(err), err
        }
 
-       return nil, nil
+       return ret, nil
 }
 
 type UpdateInput struct {
@@ -429,7 +430,7 @@ func (h *Handler) Update(c droplet.Context) (interface{}, 
error) {
                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 {
+                               if _, err := h.scriptStore.Create(c.Context(), 
script); err != nil {
                                        return handler.SpecCodeResponse(err), 
err
                                }
                        } else {
diff --git a/api/internal/handler/route/route_test.go 
b/api/internal/handler/route/route_test.go
index 5630d31..af7caf1 100644
--- a/api/internal/handler/route/route_test.go
+++ b/api/internal/handler/route/route_test.go
@@ -391,8 +391,12 @@ func TestRoute(t *testing.T) {
        err = json.Unmarshal([]byte(reqBody), route)
        assert.Nil(t, err)
        ctx.SetInput(route)
-       _, err = handler.Create(ctx)
+       ret, err := handler.Create(ctx)
        assert.Nil(t, err)
+       // check the returned valued
+       objRet, ok := ret.(*entity.Route)
+       assert.True(t, ok)
+       assert.Equal(t, "1", objRet.ID)
 
        //sleep
        time.Sleep(time.Duration(100) * time.Millisecond)
@@ -401,7 +405,7 @@ func TestRoute(t *testing.T) {
        input := &GetInput{}
        input.ID = "1"
        ctx.SetInput(input)
-       ret, err := handler.Get(ctx)
+       ret, err = handler.Get(ctx)
        stored := ret.(*entity.Route)
        assert.Nil(t, err)
        assert.Equal(t, stored.ID, route.ID)
@@ -938,7 +942,7 @@ func TestRoute(t *testing.T) {
        dataPage = retPage.(*store.ListOutput)
        assert.Equal(t, len(dataPage.Rows), 1)
 
-       //sleep
+       // sleep
        time.Sleep(time.Duration(100) * time.Millisecond)
 
        // list search and status not match
@@ -1024,8 +1028,11 @@ func TestRoute(t *testing.T) {
        err = json.Unmarshal([]byte(reqBody), route3)
        assert.Nil(t, err)
        ctx.SetInput(route3)
-       _, err = handler.Create(ctx)
+       ret, err = handler.Create(ctx)
        assert.Nil(t, err)
+       objRet, ok = ret.(*entity.Route)
+       assert.True(t, ok)
+       assert.Equal(t, "2", objRet.ID)
 
        //sleep
        time.Sleep(time.Duration(100) * time.Millisecond)
@@ -1153,8 +1160,11 @@ func TestRoute(t *testing.T) {
        err = json.Unmarshal([]byte(reqBody), route11)
        assert.Nil(t, err)
        ctx.SetInput(route11)
-       _, err = handler.Create(ctx)
+       ret, err = handler.Create(ctx)
        assert.Nil(t, err)
+       objRet, ok = ret.(*entity.Route)
+       assert.True(t, ok)
+       assert.Equal(t, "11", objRet.ID)
 
        //sleep
        time.Sleep(time.Duration(100) * time.Millisecond)
@@ -1288,8 +1298,11 @@ func Test_Route_With_Script_Dag2lua(t *testing.T) {
        err = json.Unmarshal([]byte(reqBody), route)
        assert.Nil(t, err)
        ctx.SetInput(route)
-       _, err = handler.Create(ctx)
+       ret, err := handler.Create(ctx)
        assert.Nil(t, err)
+       objRet, ok := ret.(*entity.Route)
+       assert.True(t, ok)
+       assert.Equal(t, "1", objRet.ID)
 
        //sleep
        time.Sleep(time.Duration(20) * time.Millisecond)
@@ -1298,7 +1311,7 @@ func Test_Route_With_Script_Dag2lua(t *testing.T) {
        input := &GetInput{}
        input.ID = "1"
        ctx.SetInput(input)
-       ret, err := handler.Get(ctx)
+       ret, err = handler.Get(ctx)
        stored := ret.(*entity.Route)
        assert.Nil(t, err)
        assert.Equal(t, stored.ID, route.ID)
diff --git a/api/internal/handler/service/service.go 
b/api/internal/handler/service/service.go
index 799e58a..dbd3714 100644
--- a/api/internal/handler/service/service.go
+++ b/api/internal/handler/service/service.go
@@ -165,11 +165,12 @@ func (h *Handler) Create(c droplet.Context) (interface{}, 
error) {
                }
        }
 
-       if err := h.serviceStore.Create(c.Context(), input); err != nil {
+       ret, err := h.serviceStore.Create(c.Context(), input)
+       if err != nil {
                return handler.SpecCodeResponse(err), err
        }
 
-       return nil, nil
+       return ret, nil
 }
 
 type UpdateInput struct {
diff --git a/api/internal/handler/service/service_test.go 
b/api/internal/handler/service/service_test.go
index d7be7b8..f0b5bdc 100644
--- a/api/internal/handler/service/service_test.go
+++ b/api/internal/handler/service/service_test.go
@@ -68,8 +68,11 @@ func TestService(t *testing.T) {
        err = json.Unmarshal([]byte(reqBody), service)
        assert.Nil(t, err)
        ctx.SetInput(service)
-       _, err = handler.Create(ctx)
+       ret, err := handler.Create(ctx)
        assert.Nil(t, err)
+       objRet, ok := ret.(*entity.Service)
+       assert.True(t, ok)
+       assert.Equal(t, "1", objRet.ID)
 
        //sleep
        time.Sleep(time.Duration(100) * time.Millisecond)
@@ -78,7 +81,7 @@ func TestService(t *testing.T) {
        input := &GetInput{}
        input.ID = "1"
        ctx.SetInput(input)
-       ret, err := handler.Get(ctx)
+       ret, err = handler.Get(ctx)
        stored := ret.(*entity.Service)
        assert.Nil(t, err)
        assert.Equal(t, stored.ID, service.ID)
@@ -173,8 +176,11 @@ func TestService(t *testing.T) {
        err = json.Unmarshal([]byte(reqBody), service11)
        assert.Nil(t, err)
        ctx.SetInput(service11)
-       _, err = handler.Create(ctx)
+       ret, err = handler.Create(ctx)
        assert.Nil(t, err)
+       objRet, ok = ret.(*entity.Service)
+       assert.True(t, ok)
+       assert.Equal(t, "11", objRet.ID)
 
        //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 0c9a3f2..426d286 100644
--- a/api/internal/handler/ssl/ssl.go
+++ b/api/internal/handler/ssl/ssl.go
@@ -189,11 +189,12 @@ func (h *Handler) Create(c droplet.Context) (interface{}, 
error) {
        ssl.ID = input.ID
        //set default value for SSL status, if not set, it will be 0 which 
means disable.
        ssl.Status = conf.SSLDefaultStatus
-       if err := h.sslStore.Create(c.Context(), ssl); err != nil {
+       ret, err := h.sslStore.Create(c.Context(), ssl)
+       if err != nil {
                return handler.SpecCodeResponse(err), err
        }
 
-       return nil, nil
+       return ret, nil
 }
 
 type UpdateInput struct {
diff --git a/api/internal/handler/ssl/ssl_test.go 
b/api/internal/handler/ssl/ssl_test.go
index 057d7ed..1a4b932 100644
--- a/api/internal/handler/ssl/ssl_test.go
+++ b/api/internal/handler/ssl/ssl_test.go
@@ -54,8 +54,11 @@ func TestSSL(t *testing.T) {
        err = json.Unmarshal([]byte(reqBody), ssl)
        assert.Nil(t, err)
        ctx.SetInput(ssl)
-       _, err = handler.Create(ctx)
+       ret, err := handler.Create(ctx)
        assert.Nil(t, err)
+       objRet, ok := ret.(*entity.SSL)
+       assert.True(t, ok)
+       assert.Equal(t, "1", objRet.ID)
 
        //sleep
        time.Sleep(time.Duration(100) * time.Millisecond)
@@ -64,7 +67,7 @@ func TestSSL(t *testing.T) {
        input := &GetInput{}
        input.ID = "1"
        ctx.SetInput(input)
-       ret, err := handler.Get(ctx)
+       ret, err = handler.Get(ctx)
        stored := ret.(*entity.SSL)
        assert.Nil(t, err)
        assert.Equal(t, stored.ID, ssl.ID)
diff --git a/api/internal/handler/upstream/upstream.go 
b/api/internal/handler/upstream/upstream.go
index 790fbf0..77b0af2 100644
--- a/api/internal/handler/upstream/upstream.go
+++ b/api/internal/handler/upstream/upstream.go
@@ -149,11 +149,12 @@ func (h *Handler) List(c droplet.Context) (interface{}, 
error) {
 func (h *Handler) Create(c droplet.Context) (interface{}, error) {
        input := c.Input().(*entity.Upstream)
 
-       if err := h.upstreamStore.Create(c.Context(), input); err != nil {
+       ret, err := h.upstreamStore.Create(c.Context(), input)
+       if err != nil {
                return handler.SpecCodeResponse(err), err
        }
 
-       return nil, nil
+       return ret, nil
 }
 
 type UpdateInput struct {
diff --git a/api/internal/handler/upstream/upstream_test.go 
b/api/internal/handler/upstream/upstream_test.go
index 6216633..e50bd7a 100644
--- a/api/internal/handler/upstream/upstream_test.go
+++ b/api/internal/handler/upstream/upstream_test.go
@@ -96,8 +96,11 @@ func TestUpstream(t *testing.T) {
        err = json.Unmarshal([]byte(reqBody), upstream)
        assert.Nil(t, err)
        ctx.SetInput(upstream)
-       _, err = upstreamHandler.Create(ctx)
+       ret, err := upstreamHandler.Create(ctx)
        assert.Nil(t, err)
+       objRet, ok := ret.(*entity.Upstream)
+       assert.True(t, ok)
+       assert.Equal(t, "1", objRet.ID)
 
        //sleep
        time.Sleep(time.Duration(100) * time.Millisecond)
@@ -106,7 +109,7 @@ func TestUpstream(t *testing.T) {
        input := &GetInput{}
        input.ID = "1"
        ctx.SetInput(input)
-       ret, err := upstreamHandler.Get(ctx)
+       ret, err = upstreamHandler.Get(ctx)
        stored := ret.(*entity.Upstream)
        assert.Nil(t, err)
        assert.Equal(t, stored.ID, upstream.ID)
@@ -205,8 +208,11 @@ func TestUpstream_Pass_Host(t *testing.T) {
        err := json.Unmarshal([]byte(reqBody), upstream)
        assert.Nil(t, err)
        ctx.SetInput(upstream)
-       _, err = upstreamHandler.Create(ctx)
+       ret, err := upstreamHandler.Create(ctx)
        assert.Nil(t, err)
+       objRet, ok := ret.(*entity.Upstream)
+       assert.True(t, ok)
+       assert.Equal(t, "2", objRet.ID)
 
        //sleep
        time.Sleep(time.Duration(20) * time.Millisecond)
@@ -215,7 +221,7 @@ func TestUpstream_Pass_Host(t *testing.T) {
        input := &GetInput{}
        input.ID = "2"
        ctx.SetInput(input)
-       ret, err := upstreamHandler.Get(ctx)
+       ret, err = upstreamHandler.Get(ctx)
        stored := ret.(*entity.Upstream)
        assert.Nil(t, err)
        assert.Equal(t, stored.ID, upstream.ID)
diff --git a/api/test/e2e/route_test.go b/api/test/e2e/route_test.go
index 15f680e..7bd4a13 100644
--- a/api/test/e2e/route_test.go
+++ b/api/test/e2e/route_test.go
@@ -506,3 +506,69 @@ func TestRoute_With_Empty_Array(t *testing.T) {
                testCaseCheck(tc, t)
        }
 }
+
+func TestRoute_Create_via_POST(t *testing.T) {
+       tests := []HttpTestCase{
+               {
+                       Desc:         "hit route that not exist",
+                       Object:       APISIXExpect(t),
+                       Method:       http.MethodGet,
+                       Path:         "/hello_",
+                       Headers:      map[string]string{"Host": "foo.com"},
+                       ExpectStatus: http.StatusNotFound,
+                       ExpectBody:   "{\"error_msg\":\"404 Route Not 
Found\"}\n",
+               },
+               {
+                       Desc:   "create route via HTTP POST",
+                       Object: ManagerApiExpect(t),
+                       Method: http.MethodPost,
+                       Path:   "/apisix/admin/routes",
+                       Body: `{
+                               "id": "r1",
+                               "uri": "/hello_",
+                               "hosts": ["foo.com", "*.bar.com"],
+                               "upstream": {
+                                       "nodes": {
+                                               "172.16.238.20:1980": 1
+                                       },
+                                       "type": "roundrobin"
+                               }
+                       }`,
+                       Headers:      map[string]string{"Authorization": token},
+                       ExpectStatus: http.StatusOK,
+                       // Check the returned value
+                       ExpectBody: "\"id\":\"r1\"",
+               },
+               {
+                       Desc:         "hit the route just created",
+                       Object:       APISIXExpect(t),
+                       Method:       http.MethodGet,
+                       Path:         "/hello_",
+                       Headers:      map[string]string{"Host": "foo.com"},
+                       ExpectStatus: http.StatusOK,
+                       ExpectBody:   "hello world\n",
+               },
+               {
+                       Desc:         "delete the route just created",
+                       Object:       ManagerApiExpect(t),
+                       Method:       http.MethodDelete,
+                       Path:         "/apisix/admin/routes/r1",
+                       Headers:      map[string]string{"Authorization": token},
+                       ExpectStatus: http.StatusOK,
+               },
+               {
+                       Desc:         "hit the route just deleted",
+                       Object:       APISIXExpect(t),
+                       Method:       http.MethodGet,
+                       Path:         "/hello_",
+                       Headers:      map[string]string{"Host": "bar.com"},
+                       ExpectStatus: http.StatusNotFound,
+                       ExpectBody:   "{\"error_msg\":\"404 Route Not 
Found\"}\n",
+                       Sleep:        sleepTime,
+               },
+       }
+
+       for _, tc := range tests {
+               testCaseCheck(tc, t)
+       }
+}
diff --git a/api/test/e2e/service_test.go b/api/test/e2e/service_test.go
index 3af434b..2f73b37 100644
--- a/api/test/e2e/service_test.go
+++ b/api/test/e2e/service_test.go
@@ -156,14 +156,17 @@ func TestService(t *testing.T) {
        assert.Equal(t, "100", resp.Header["X-Ratelimit-Limit"][0])
        assert.Equal(t, "99", resp.Header["X-Ratelimit-Remaining"][0])
 
+       // Create another service(id=s2) via HTTP POST to check the
+       // returned value, still attached to route(id=r1)
        tests = []HttpTestCase{
                {
-                       Desc:    "create service with all options",
+                       Desc:    "create service with all options via POST 
method",
                        Object:  ManagerApiExpect(t),
-                       Method:  http.MethodPut,
-                       Path:    "/apisix/admin/services/s1",
+                       Method:  http.MethodPost,
+                       Path:    "/apisix/admin/services",
                        Headers: map[string]string{"Authorization": token},
                        Body: `{
+                               "id": "s2",
                                "name": "testservice",
                                "desc": "testservice_desc",
                                "labels": {
@@ -192,12 +195,13 @@ func TestService(t *testing.T) {
                                }
                        }`,
                        ExpectStatus: http.StatusOK,
+                       ExpectBody:   "\"id\":\"s2\"",
                },
                {
-                       Desc:       "get the service s1",
+                       Desc:       "get the service s2",
                        Object:     ManagerApiExpect(t),
                        Method:     http.MethodGet,
-                       Path:       "/apisix/admin/services/s1",
+                       Path:       "/apisix/admin/services/s2",
                        Headers:    map[string]string{"Authorization": token},
                        ExpectCode: http.StatusOK,
                        ExpectBody: 
"\"name\":\"testservice\",\"desc\":\"testservice_desc\",\"upstream\":{\"nodes\":[{\"host\":\"172.16.238.20\",\"port\":1980,\"weight\":1}],\"type\":\"roundrobin\"},\"plugins\":{\"limit-count\":{\"count\":100,\"key\":\"remote_addr\",\"rejected_code\":503,\"time_window\":60}},\"labels\":{\"build\":\"16\",\"env\":\"production\",\"version\":\"v2\"},\"enable_websocket\":true}",
@@ -209,7 +213,7 @@ func TestService(t *testing.T) {
                        Path:   "/apisix/admin/routes/r1",
                        Body: `{
                                "uri": "/hello",
-                               "service_id": "s1"
+                               "service_id": "s2"
                        }`,
                        Headers:      map[string]string{"Authorization": token},
                        ExpectStatus: http.StatusOK,
@@ -232,7 +236,8 @@ func TestService(t *testing.T) {
 func TestService_Teardown(t *testing.T) {
        tests := []HttpTestCase{
                {
-                       Desc:         "delete the service",
+                       // Delete the service created via HTTP PUT
+                       Desc:         "delete the service(id=s1)",
                        Object:       ManagerApiExpect(t),
                        Method:       http.MethodDelete,
                        Path:         "/apisix/admin/services/s1",
@@ -241,6 +246,16 @@ func TestService_Teardown(t *testing.T) {
                        Sleep:        sleepTime,
                },
                {
+                       // Delete the service created via HTTP POST
+                       Desc:         "delete the service(id=s2)",
+                       Object:       ManagerApiExpect(t),
+                       Method:       http.MethodDelete,
+                       Path:         "/apisix/admin/services/s2",
+                       Headers:      map[string]string{"Authorization": token},
+                       ExpectStatus: http.StatusOK,
+                       Sleep:        sleepTime,
+               },
+               {
                        Desc:         "delete route",
                        Object:       ManagerApiExpect(t),
                        Method:       http.MethodDelete,
diff --git a/api/test/e2e/ssl_test.go b/api/test/e2e/ssl_test.go
index 6168900..c1be9b1 100644
--- a/api/test/e2e/ssl_test.go
+++ b/api/test/e2e/ssl_test.go
@@ -82,6 +82,7 @@ func TestSSL_Basic(t *testing.T) {
                        Body:         string(body),
                        Headers:      map[string]string{"Authorization": token},
                        ExpectStatus: http.StatusOK,
+                       ExpectBody:   "\"id\":\"1\"",
                },
                {
                        Desc:   "create route",
diff --git a/api/test/e2e/upstream_test.go b/api/test/e2e/upstream_test.go
index 2f947f0..5d8d247 100644
--- a/api/test/e2e/upstream_test.go
+++ b/api/test/e2e/upstream_test.go
@@ -424,3 +424,70 @@ func TestUpstream_Delete(t *testing.T) {
                testCaseCheck(tc, t)
        }
 }
+
+func TestUpstream_Create_via_Post(t *testing.T) {
+       tests := []HttpTestCase{
+               {
+                       Desc:   "create upstream via POST",
+                       Object: ManagerApiExpect(t),
+                       Method: http.MethodPost,
+                       Path:   "/apisix/admin/upstreams",
+                       Body: `{
+                               "id": "u1",
+                               "nodes": [{
+                                       "host": "172.16.238.20",
+                                       "port": 1980,
+                                       "weight": 1
+                               }],
+                               "type": "roundrobin"
+                       }`,
+                       Headers:      map[string]string{"Authorization": token},
+                       ExpectStatus: http.StatusOK,
+                       // should return id and other request body content
+                       ExpectBody: []string{"\"id\":\"u1\"", 
"\"type\":\"roundrobin\""},
+               },
+               {
+                       Desc:   "create route using the upstream just created",
+                       Object: ManagerApiExpect(t),
+                       Method: http.MethodPut,
+                       Path:   "/apisix/admin/routes/1",
+                       Body: `{
+                               "uri": "/hello",
+                               "upstream_id": "u1"
+                       }`,
+                       Headers:      map[string]string{"Authorization": token},
+                       ExpectStatus: http.StatusOK,
+                       Sleep:        sleepTime,
+               },
+               {
+                       Desc:         "hit the route just created",
+                       Object:       APISIXExpect(t),
+                       Method:       http.MethodGet,
+                       Path:         "/hello",
+                       ExpectStatus: http.StatusOK,
+                       ExpectBody:   "hello world",
+                       Sleep:        sleepTime,
+               },
+               //
+               {
+                       Desc:         "delete route",
+                       Object:       ManagerApiExpect(t),
+                       Method:       http.MethodDelete,
+                       Path:         "/apisix/admin/routes/1",
+                       Headers:      map[string]string{"Authorization": token},
+                       ExpectStatus: http.StatusOK,
+               },
+               {
+                       Desc:         "delete upstream",
+                       Object:       ManagerApiExpect(t),
+                       Method:       http.MethodDelete,
+                       Path:         "/apisix/admin/upstreams/u1",
+                       Headers:      map[string]string{"Authorization": token},
+                       ExpectStatus: http.StatusOK,
+               },
+       }
+
+       for _, tc := range tests {
+               testCaseCheck(tc, t)
+       }
+}

Reply via email to