Skip to content

Commit

Permalink
fix: set create_time/update_time as omitempty
Browse files Browse the repository at this point in the history
Signed-off-by: imjoey <majunjiev@gmail.com>
  • Loading branch information
imjoey committed Jan 5, 2021
1 parent 45e90ec commit 24952c3
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 22 deletions.
4 changes: 2 additions & 2 deletions api/internal/core/entity/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import (

type BaseInfo struct {
ID interface{} `json:"id"`
CreateTime int64 `json:"create_time"`
UpdateTime int64 `json:"update_time"`
CreateTime int64 `json:"create_time,omitempty"`
UpdateTime int64 `json:"update_time,omitempty"`
}

func (info *BaseInfo) GetBaseInfo() *BaseInfo {
Expand Down
47 changes: 27 additions & 20 deletions api/test/e2e/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,20 +157,21 @@ func BatchTestServerPort(t *testing.T, times int) map[string]int {
var sleepTime = time.Duration(300) * time.Millisecond

type HttpTestCase struct {
Desc string
Object *httpexpect.Expect
Method string
Path string
Query string
Body string
Headers map[string]string
Headers_test map[string]interface{}
ExpectStatus int
ExpectCode int
ExpectMessage string
ExpectBody string
ExpectHeaders map[string]string
Sleep time.Duration //ms
Desc string
Object *httpexpect.Expect
Method string
Path string
Query string
Body string
Headers map[string]string
Headers_test map[string]interface{}
ExpectStatus int
ExpectCode int
ExpectMessage string
ExpectBody string
UnexpectedBody string
ExpectHeaders map[string]string
Sleep time.Duration //ms
}

func testCaseCheck(tc HttpTestCase, t *testing.T) {
Expand Down Expand Up @@ -208,34 +209,40 @@ func testCaseCheck(tc HttpTestCase, t *testing.T) {
req.WithQueryString(tc.Query)
}

//set header
// set header
for key, val := range tc.Headers {
req.WithHeader(key, val)
}

//set body
// set body
if tc.Body != "" {
req.WithText(tc.Body)
}

//respond check
// respond check
resp := req.Expect()

//match http status
// match http status
if tc.ExpectStatus != 0 {
resp.Status(tc.ExpectStatus)
}

//match headers
// match headers
if tc.ExpectHeaders != nil {
for key, val := range tc.ExpectHeaders {
resp.Header(key).Equal(val)
}
}

//match body
// match body
if tc.ExpectBody != "" {
resp.Body().Contains(tc.ExpectBody)
}

// match UnexpectedBody
if tc.UnexpectedBody != "" {
resp.Body().NotContains(tc.UnexpectedBody)
}

})
}
59 changes: 59 additions & 0 deletions api/test/e2e/server_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,62 @@ func TestServerInfo_List(t *testing.T) {
testCaseCheck(tc, t)
}
}

func TestServerInfo_Get_OmitEmptyValue(t *testing.T) {
// wait for apisix report
time.Sleep(2 * time.Second)
testCases := []HttpTestCase{
{
Desc: "get server info",
Object: ManagerApiExpect(t),
Path: "/apisix/admin/server_info/apisix-server1",
Method: http.MethodGet,
Headers: map[string]string{"Authorization": token},
ExpectStatus: http.StatusOK,
UnexpectedBody: "\"create_time\":",
},
{
Desc: "get server info",
Object: ManagerApiExpect(t),
Path: "/apisix/admin/server_info/apisix-server1",
Method: http.MethodGet,
Headers: map[string]string{"Authorization": token},
ExpectStatus: http.StatusOK,
UnexpectedBody: "\"update_time\":",
},
}

for _, tc := range testCases {
testCaseCheck(tc, t)
}
}

func TestServerInfo_List_OmitEmptyValue(t *testing.T) {
testCases := []HttpTestCase{
{
Desc: "list all server info",
Object: ManagerApiExpect(t),
Path: "/apisix/admin/server_info",
Method: http.MethodGet,
Headers: map[string]string{"Authorization": token},
ExpectStatus: http.StatusOK,
ExpectBody: "\"total_size\":2",
UnexpectedBody: "\"create_time\":",
},
{
Desc: "list server info with hostname",
Object: ManagerApiExpect(t),
Path: "/apisix/admin/server_info",
Query: "hostname=apisix_",
Method: http.MethodGet,
Headers: map[string]string{"Authorization": token},
ExpectStatus: http.StatusOK,
ExpectBody: "\"total_size\":2",
UnexpectedBody: "\"update_time\":",
},
}

for _, tc := range testCases {
testCaseCheck(tc, t)
}
}

0 comments on commit 24952c3

Please sign in to comment.