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

ci: display more meaningful information when running E2E test cases failed #1012

Merged
merged 9 commits into from
Dec 24, 2020
Merged
Show file tree
Hide file tree
Changes from 7 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
2 changes: 1 addition & 1 deletion .github/workflows/backend-e2e-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ jobs:

- name: run test
working-directory: ./api/test/e2e
run: go test
run: go test -v
56 changes: 28 additions & 28 deletions api/test/e2e/balancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ import (
func TestBalancer_roundrobin_with_weight(t *testing.T) {
tests := []HttpTestCase{
{
caseDesc: "create upstream (roundrobin with same weight)",
Object: ManagerApiExpect(t),
Method: http.MethodPut,
Path: "/apisix/admin/upstreams/1",
Desc: "create upstream (roundrobin with same weight)",
Object: ManagerApiExpect(t),
Method: http.MethodPut,
Path: "/apisix/admin/upstreams/1",
Body: `{
"nodes": [{
"host": "172.16.238.20",
Expand All @@ -54,10 +54,10 @@ func TestBalancer_roundrobin_with_weight(t *testing.T) {
ExpectStatus: http.StatusOK,
},
{
caseDesc: "create route using the upstream just created",
Object: ManagerApiExpect(t),
Method: http.MethodPut,
Path: "/apisix/admin/routes/1",
Desc: "create route using the upstream just created",
Object: ManagerApiExpect(t),
Method: http.MethodPut,
Path: "/apisix/admin/routes/1",
Body: `{
"uri": "/server_port",
"upstream_id": "1"
Expand All @@ -69,7 +69,7 @@ func TestBalancer_roundrobin_with_weight(t *testing.T) {
}

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

// hit routes
Expand Down Expand Up @@ -98,10 +98,10 @@ func TestBalancer_roundrobin_with_weight(t *testing.T) {

tests = []HttpTestCase{
{
caseDesc: "create upstream (roundrobin with different weight)",
Object: ManagerApiExpect(t),
Method: http.MethodPut,
Path: "/apisix/admin/upstreams/1",
Desc: "create upstream (roundrobin with different weight)",
Object: ManagerApiExpect(t),
Method: http.MethodPut,
Path: "/apisix/admin/upstreams/1",
Body: `{
"nodes": [{
"host": "172.16.238.20",
Expand All @@ -125,7 +125,7 @@ func TestBalancer_roundrobin_with_weight(t *testing.T) {
},
}
for _, tc := range tests {
testCaseCheck(tc)
testCaseCheck(tc, t)
}

// hit routes
Expand All @@ -149,10 +149,10 @@ func TestBalancer_roundrobin_with_weight(t *testing.T) {

tests = []HttpTestCase{
{
caseDesc: "create upstream (roundrobin with weight 1 and 0) ",
Object: ManagerApiExpect(t),
Method: http.MethodPut,
Path: "/apisix/admin/upstreams/1",
Desc: "create upstream (roundrobin with weight 1 and 0) ",
Object: ManagerApiExpect(t),
Method: http.MethodPut,
Path: "/apisix/admin/upstreams/1",
Body: `{
"nodes": [{
"host": "172.16.238.20",
Expand All @@ -171,7 +171,7 @@ func TestBalancer_roundrobin_with_weight(t *testing.T) {
},
}
for _, tc := range tests {
testCaseCheck(tc)
testCaseCheck(tc, t)
}

// hit routes
Expand All @@ -193,10 +193,10 @@ func TestBalancer_roundrobin_with_weight(t *testing.T) {

tests = []HttpTestCase{
{
caseDesc: "create upstream (roundrobin with weight only 1 ) ",
Object: ManagerApiExpect(t),
Method: http.MethodPut,
Path: "/apisix/admin/upstreams/1",
Desc: "create upstream (roundrobin with weight only 1 ) ",
Object: ManagerApiExpect(t),
Method: http.MethodPut,
Path: "/apisix/admin/upstreams/1",
Body: `{
"nodes": [{
"host": "172.16.238.20",
Expand All @@ -210,7 +210,7 @@ func TestBalancer_roundrobin_with_weight(t *testing.T) {
},
}
for _, tc := range tests {
testCaseCheck(tc)
testCaseCheck(tc, t)
}

// hit routes
Expand All @@ -234,23 +234,23 @@ func TestBalancer_roundrobin_with_weight(t *testing.T) {
func TestBalancer_Delete(t *testing.T) {
tests := []HttpTestCase{
{
caseDesc: "delete route",
Desc: "delete route",
Object: ManagerApiExpect(t),
Method: http.MethodDelete,
Path: "/apisix/admin/routes/1",
Headers: map[string]string{"Authorization": token},
ExpectStatus: http.StatusOK,
},
{
caseDesc: "delete upstream",
Desc: "delete upstream",
Object: ManagerApiExpect(t),
Method: http.MethodDelete,
Path: "/apisix/admin/upstreams/1",
Headers: map[string]string{"Authorization": token},
ExpectStatus: http.StatusOK,
},
{
caseDesc: "hit the route just deleted",
Desc: "hit the route just deleted",
Object: APISIXExpect(t),
Method: http.MethodGet,
Path: "/server_port",
Expand All @@ -261,6 +261,6 @@ func TestBalancer_Delete(t *testing.T) {
}

for _, tc := range tests {
testCaseCheck(tc)
testCaseCheck(tc, t)
}
}
106 changes: 54 additions & 52 deletions api/test/e2e/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func APISIXHTTPSExpect(t *testing.T) *httpexpect.Expect {
var sleepTime = time.Duration(300) * time.Millisecond

type HttpTestCase struct {
caseDesc string
Desc string
Object *httpexpect.Expect
Method string
Path string
Expand All @@ -135,66 +135,68 @@ type HttpTestCase struct {
Sleep time.Duration //ms
}

func testCaseCheck(tc HttpTestCase) {
//init
expectObj := tc.Object
var req *httpexpect.Request
switch tc.Method {
case http.MethodGet:
req = expectObj.GET(tc.Path)
case http.MethodPut:
req = expectObj.PUT(tc.Path)
case http.MethodPost:
req = expectObj.POST(tc.Path)
case http.MethodDelete:
req = expectObj.DELETE(tc.Path)
case http.MethodPatch:
req = expectObj.PATCH(tc.Path)
case http.MethodOptions:
req = expectObj.OPTIONS(tc.Path)
default:
}
func testCaseCheck(tc HttpTestCase, t *testing.T) {
t.Run(tc.Desc, func(t *testing.T) {
//init
expectObj := tc.Object
var req *httpexpect.Request
switch tc.Method {
case http.MethodGet:
req = expectObj.GET(tc.Path)
case http.MethodPut:
req = expectObj.PUT(tc.Path)
case http.MethodPost:
req = expectObj.POST(tc.Path)
case http.MethodDelete:
req = expectObj.DELETE(tc.Path)
case http.MethodPatch:
req = expectObj.PATCH(tc.Path)
case http.MethodOptions:
req = expectObj.OPTIONS(tc.Path)
default:
}

if req == nil {
panic("fail to init request")
}
if req == nil {
panic("fail to init request")
}

if tc.Sleep != 0 {
time.Sleep(tc.Sleep)
}
if tc.Sleep != 0 {
time.Sleep(tc.Sleep)
}

if tc.Query != "" {
req.WithQueryString(tc.Query)
}
if tc.Query != "" {
req.WithQueryString(tc.Query)
}

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

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

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

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

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

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

}
Loading