Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Set create_time/update_time as omitempty #1203

Merged
merged 1 commit into from
Jan 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}