diff --git a/api/test/e2enew/route/route_with_script_luacode_test.go b/api/test/e2enew/route/route_with_script_luacode_test.go index a9d01cb6cd..29e070d89f 100644 --- a/api/test/e2enew/route/route_with_script_luacode_test.go +++ b/api/test/e2enew/route/route_with_script_luacode_test.go @@ -22,13 +22,11 @@ import ( "github.com/onsi/ginkgo" "github.com/onsi/ginkgo/extensions/table" - "github.com/stretchr/testify/assert" + "github.com/onsi/gomega" "github.com/apisix/manager-api/test/e2enew/base" ) -var t = ginkgo.GinkgoT() - var _ = ginkgo.Describe("route with script lucacode", func() { ginkgo.It("clean APISIX error log", func() { base.CleanAPISIXErrorLog() @@ -150,7 +148,7 @@ var _ = ginkgo.Describe("route with script lucacode", func() { //verify the log generated by script set in Step-3 above logContent := base.ReadAPISIXErrorLog() - assert.Contains(t, logContent, "hit access phase") + gomega.Expect(logContent).Should(gomega.ContainSubstring(`\"hit access phase\"`)) //clean log base.CleanAPISIXErrorLog() @@ -340,7 +338,7 @@ var _ = ginkgo.Describe("route with script id", func() { //verify the log generated by script set in Step-4 above logContent := base.ReadAPISIXErrorLog() - assert.Contains(t, logContent, "hit access phase") + gomega.Expect(logContent).Should(gomega.ContainSubstring(`\"hit access phase\"`)) //clean log base.CleanAPISIXErrorLog() diff --git a/api/test/e2enew/route/route_with_vars_test.go b/api/test/e2enew/route/route_with_vars_test.go index 56f28cc550..5a7152c013 100644 --- a/api/test/e2enew/route/route_with_vars_test.go +++ b/api/test/e2enew/route/route_with_vars_test.go @@ -21,7 +21,7 @@ import ( "net/http" "github.com/onsi/ginkgo" - "github.com/stretchr/testify/assert" + "github.com/onsi/gomega" "github.com/apisix/manager-api/test/e2enew/base" ) @@ -39,7 +39,6 @@ var upstream map[string]interface{} = map[string]interface{}{ var _ = ginkgo.Describe("test route with vars (args)", func() { ginkgo.It("add route with vars (args)", func() { - t := ginkgo.GinkgoT() var createRouteBody map[string]interface{} = map[string]interface{}{ "name": "route1", "uri": "/hello", @@ -49,7 +48,7 @@ var _ = ginkgo.Describe("test route with vars (args)", func() { "upstream": upstream, } _createRouteBody, err := json.Marshal(createRouteBody) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) base.RunTestCase(base.HttpTestCase{ Object: base.ManagerApiExpect(), Method: http.MethodPut, @@ -92,7 +91,6 @@ var _ = ginkgo.Describe("test route with vars (args)", func() { }) }) ginkgo.It("update route with vars (header)", func() { - t := ginkgo.GinkgoT() var createRouteBody map[string]interface{} = map[string]interface{}{ "name": "route1", "uri": "/hello", @@ -102,7 +100,7 @@ var _ = ginkgo.Describe("test route with vars (args)", func() { "upstream": upstream, } _createRouteBody, err := json.Marshal(createRouteBody) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) base.RunTestCase(base.HttpTestCase{ Object: base.ManagerApiExpect(), Method: http.MethodPut, @@ -145,7 +143,6 @@ var _ = ginkgo.Describe("test route with vars (args)", func() { }) }) ginkgo.It("update route with vars (cookie)", func() { - t := ginkgo.GinkgoT() var createRouteBody map[string]interface{} = map[string]interface{}{ "name": "route1", "uri": "/hello", @@ -155,7 +152,7 @@ var _ = ginkgo.Describe("test route with vars (args)", func() { "upstream": upstream, } _createRouteBody, err := json.Marshal(createRouteBody) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) base.RunTestCase(base.HttpTestCase{ Object: base.ManagerApiExpect(), Method: http.MethodPut, @@ -222,7 +219,6 @@ var _ = ginkgo.Describe("test route with vars (args)", func() { var _ = ginkgo.Describe("test route with multiple vars (args, cookie and header)", func() { ginkgo.It("add route with multiple vars (args, cookie and header)", func() { - t := ginkgo.GinkgoT() var createRouteBody map[string]interface{} = map[string]interface{}{ "name": "route1", "uri": "/hello", @@ -234,7 +230,7 @@ var _ = ginkgo.Describe("test route with multiple vars (args, cookie and header) "upstream": upstream, } _createRouteBody, err := json.Marshal(createRouteBody) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) base.RunTestCase(base.HttpTestCase{ Object: base.ManagerApiExpect(), Method: http.MethodPut, @@ -318,7 +314,6 @@ var _ = ginkgo.Describe("test route with multiple vars (args, cookie and header) var _ = ginkgo.Describe("test route with vars (args is digital)", func() { ginkgo.It("add route with vars (args is digital)", func() { - t := ginkgo.GinkgoT() var createRouteBody map[string]interface{} = map[string]interface{}{ "name": "route1", "uri": "/hello", @@ -328,7 +323,7 @@ var _ = ginkgo.Describe("test route with vars (args is digital)", func() { "upstream": upstream, } _createRouteBody, err := json.Marshal(createRouteBody) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) base.RunTestCase(base.HttpTestCase{ Object: base.ManagerApiExpect(), Method: http.MethodPut, diff --git a/api/test/e2enew/route_online_debug/route_online_debug_suite_test.go b/api/test/e2enew/route_online_debug/route_online_debug_suite_test.go index 8dbfa22ad5..06b97a0061 100644 --- a/api/test/e2enew/route_online_debug/route_online_debug_suite_test.go +++ b/api/test/e2enew/route_online_debug/route_online_debug_suite_test.go @@ -21,11 +21,13 @@ import ( "time" "github.com/onsi/ginkgo" + "github.com/onsi/gomega" "github.com/apisix/manager-api/test/e2enew/base" ) func TestRoute(t *testing.T) { + gomega.RegisterFailHandler(ginkgo.Fail) ginkgo.RunSpecs(t, "route online debug suite") } diff --git a/api/test/e2enew/route_online_debug/route_online_debug_test.go b/api/test/e2enew/route_online_debug/route_online_debug_test.go index 2f6897cce3..166862f53e 100644 --- a/api/test/e2enew/route_online_debug/route_online_debug_test.go +++ b/api/test/e2enew/route_online_debug/route_online_debug_test.go @@ -25,7 +25,7 @@ import ( "github.com/onsi/ginkgo" "github.com/onsi/ginkgo/extensions/table" - "github.com/stretchr/testify/assert" + "github.com/onsi/gomega" "github.com/tidwall/gjson" "github.com/apisix/manager-api/test/e2enew/base" @@ -84,7 +84,6 @@ var _ = ginkgo.Describe("Route_Online_Debug_Route_With_Query_Params", func() { }) }) ginkgo.It("create route with query params", func() { - t := ginkgo.GinkgoT() var routeBody map[string]interface{} = map[string]interface{}{ "name": "route1", "uri": "/hello", @@ -95,7 +94,7 @@ var _ = ginkgo.Describe("Route_Online_Debug_Route_With_Query_Params", func() { "upstream": upstream, } _routeBody, err := json.Marshal(routeBody) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) base.RunTestCase(base.HttpTestCase{ Object: base.ManagerApiExpect(), Method: http.MethodPut, @@ -155,7 +154,6 @@ var _ = ginkgo.Describe("Route_Online_Debug_Route_With_Header_Params", func() { }) }) ginkgo.It("create route with header params", func() { - t := ginkgo.GinkgoT() var routeBody map[string]interface{} = map[string]interface{}{ "name": "route1", "uri": "/hello", @@ -166,7 +164,7 @@ var _ = ginkgo.Describe("Route_Online_Debug_Route_With_Header_Params", func() { "upstream": upstream, } _reqRouteBody, err := json.Marshal(routeBody) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) base.RunTestCase(base.HttpTestCase{ Object: base.ManagerApiExpect(), Method: http.MethodPut, @@ -196,7 +194,6 @@ var _ = ginkgo.Describe("Route_Online_Debug_Route_With_Header_Params", func() { }) }) ginkgo.It("online debug route with header params(add Content-type to header params to create route)", func() { - t := ginkgo.GinkgoT() var routeBody map[string]interface{} = map[string]interface{}{ "name": "route2", "status": 1, @@ -205,7 +202,7 @@ var _ = ginkgo.Describe("Route_Online_Debug_Route_With_Header_Params", func() { "upstream": upstream, } _reqRouteBody, err := json.Marshal(routeBody) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) base.RunTestCase(base.HttpTestCase{ Object: base.ManagerApiExpect(), Method: http.MethodPost, @@ -285,7 +282,6 @@ var _ = ginkgo.Describe("Route_Online_Debug_Route_With_Body_Params", func() { }) }) ginkgo.It("create route with method POST", func() { - t := ginkgo.GinkgoT() var routeBody map[string]interface{} = map[string]interface{}{ "name": "route1", "uri": "/hello", @@ -293,7 +289,7 @@ var _ = ginkgo.Describe("Route_Online_Debug_Route_With_Body_Params", func() { "upstream": upstream, } _reqRouteBody, err := json.Marshal(routeBody) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) base.RunTestCase(base.HttpTestCase{ Object: base.ManagerApiExpect(), Method: http.MethodPut, @@ -357,7 +353,6 @@ var _ = ginkgo.Describe("Route_Online_Debug_Route_With_Basic_Auth", func() { }) }) ginkgo.It("create route enable basic-auth plugin", func() { - t := ginkgo.GinkgoT() var routeBody map[string]interface{} = map[string]interface{}{ "name": "route1", "uri": "/hello", @@ -368,7 +363,7 @@ var _ = ginkgo.Describe("Route_Online_Debug_Route_With_Basic_Auth", func() { "upstream": upstream, } _reqRouteBody, err := json.Marshal(routeBody) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) base.RunTestCase(base.HttpTestCase{ Object: base.ManagerApiExpect(), Method: http.MethodPut, @@ -485,7 +480,6 @@ var _ = ginkgo.Describe("Route_Online_Debug_Route_With_Key_Auth", func() { }) }) ginkgo.It("create route enable key-auth plugin", func() { - t := ginkgo.GinkgoT() var routeBody map[string]interface{} = map[string]interface{}{ "name": "route1", "uri": "/hello", @@ -496,7 +490,7 @@ var _ = ginkgo.Describe("Route_Online_Debug_Route_With_Key_Auth", func() { "upstream": upstream, } _reqRouteBody, err := json.Marshal(routeBody) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) base.RunTestCase(base.HttpTestCase{ Object: base.ManagerApiExpect(), Method: http.MethodPut, @@ -609,7 +603,6 @@ var _ = ginkgo.Describe("Route_Online_Debug_Route_With_JWT_Auth", func() { }) }) ginkgo.It("create route enable jwt-auth plugin", func() { - t := ginkgo.GinkgoT() var routeBody map[string]interface{} = map[string]interface{}{ "name": "route1", "uri": "/hello", @@ -620,7 +613,7 @@ var _ = ginkgo.Describe("Route_Online_Debug_Route_With_JWT_Auth", func() { "upstream": upstream, } _reqRouteBody, err := json.Marshal(routeBody) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) base.RunTestCase(base.HttpTestCase{ Object: base.ManagerApiExpect(), Method: http.MethodPut, @@ -661,16 +654,15 @@ var _ = ginkgo.Describe("Route_Online_Debug_Route_With_JWT_Auth", func() { }) }) ginkgo.It("online debug with JWT-auth", func() { - t := ginkgo.GinkgoT() jsonStr := `{"test":["test1"]}` var _headerParams map[string]interface{} err := json.Unmarshal([]byte(jsonStr), &_headerParams) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) jwtToken := base.GetJwtToken("user-key") l := []string{jwtToken} _headerParams["Authorization"] = l headerParams, err := json.Marshal(_headerParams) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) base.RunTestCase(base.HttpTestCase{ Object: base.ManagerApiExpect(), Method: http.MethodPost, @@ -745,7 +737,6 @@ var _ = ginkgo.Describe("Route_Online_Debug_Route_With_Files", func() { }) }) ginkgo.It("create route enable basic-auth plugin", func() { - t := ginkgo.GinkgoT() var routeBody map[string]interface{} = map[string]interface{}{ "name": "route1", "uri": "/hello_", @@ -753,7 +744,7 @@ var _ = ginkgo.Describe("Route_Online_Debug_Route_With_Files", func() { "upstream": upstream, } _reqRouteBody, err := json.Marshal(routeBody) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) base.RunTestCase(base.HttpTestCase{ Object: base.ManagerApiExpect(), Method: http.MethodPut, @@ -765,9 +756,8 @@ var _ = ginkgo.Describe("Route_Online_Debug_Route_With_Files", func() { }) }) ginkgo.It("online debug with file", func() { - t := ginkgo.GinkgoT() path, err := filepath.Abs("../../testdata/import/default.yaml") - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) files := []base.UploadFile{ {Name: "file", Filepath: path}, } @@ -777,17 +767,17 @@ var _ = ginkgo.Describe("Route_Online_Debug_Route_With_Files", func() { jsonStr := `{"test":["test1"]}` var _headerParams map[string]interface{} err = json.Unmarshal([]byte(jsonStr), &_headerParams) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) l := []string{base.GetToken()} _headerParams["Authorization"] = l headerParams, err := json.Marshal(_headerParams) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) basePath := base.ManagerAPIHost + "/apisix/admin/debug-request-forwarding" requestBody, requestContentType, err := base.GetReader(headers, "multipart/form-data", files) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) httpRequest, err := http.NewRequest(http.MethodPost, basePath, requestBody) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) httpRequest.Header.Add("Content-Type", requestContentType) httpRequest.Header.Add("Authorization", base.GetToken()) httpRequest.Header.Add("online_debug_request_protocol", "http") @@ -796,24 +786,23 @@ var _ = ginkgo.Describe("Route_Online_Debug_Route_With_Files", func() { httpRequest.Header.Add("online_debug_header_params", string(headerParams)) client := &http.Client{} resp, err := client.Do(httpRequest) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) defer resp.Body.Close() respBody, err := ioutil.ReadAll(resp.Body) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) realBody := gjson.Get(string(respBody), "data") // todo get successful result and compare - assert.Contains(t, realBody.String(), `"data":{"paths":1,"routes":1}`) + gomega.Expect(realBody.String()).Should(gomega.ContainSubstring(`"data":{"paths":1,"routes":1}`)) }) ginkgo.It("verify the route just imported and delete data", func() { - t := ginkgo.GinkgoT() time.Sleep(time.Duration(500) * time.Millisecond) request, _ := http.NewRequest("GET", base.ManagerAPIHost+"/apisix/admin/routes", nil) request.Header.Add("Authorization", base.GetToken()) resp, err := http.DefaultClient.Do(request) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) defer resp.Body.Close() respBody, _ := ioutil.ReadAll(resp.Body) list := gjson.Get(string(respBody), "data.rows").Value().([]interface{}) diff --git a/api/test/e2enew/service/service_suite_test.go b/api/test/e2enew/service/service_suite_test.go index 6d74b97b4f..c4c8f5f001 100644 --- a/api/test/e2enew/service/service_suite_test.go +++ b/api/test/e2enew/service/service_suite_test.go @@ -21,11 +21,13 @@ import ( "time" "github.com/onsi/ginkgo" + "github.com/onsi/gomega" "github.com/apisix/manager-api/test/e2enew/base" ) func TestRoute(t *testing.T) { + gomega.RegisterFailHandler(ginkgo.Fail) ginkgo.RunSpecs(t, "service suite") } diff --git a/api/test/e2enew/service/service_test.go b/api/test/e2enew/service/service_test.go index b1a78f5664..f2c3cb35fe 100644 --- a/api/test/e2enew/service/service_test.go +++ b/api/test/e2enew/service/service_test.go @@ -22,7 +22,7 @@ import ( "time" "github.com/onsi/ginkgo" - "github.com/stretchr/testify/assert" + "github.com/onsi/gomega" "github.com/apisix/manager-api/test/e2enew/base" "github.com/onsi/ginkgo/extensions/table" @@ -53,9 +53,8 @@ var _ = ginkgo.Describe("create service without plugin", func() { }, } ginkgo.It("create service without plugin", func() { - t := ginkgo.GinkgoT() _createServiceBody, err := json.Marshal(createServiceBody) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) base.RunTestCase(base.HttpTestCase{ Object: base.ManagerApiExpect(), Method: http.MethodPut, @@ -67,10 +66,9 @@ var _ = ginkgo.Describe("create service without plugin", func() { }) }) ginkgo.It("create service2 success", func() { - t := ginkgo.GinkgoT() createServiceBody["name"] = "testservice2" _createServiceBody, err := json.Marshal(createServiceBody) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) base.RunTestCase(base.HttpTestCase{ Object: base.ManagerApiExpect(), Method: http.MethodPut, @@ -82,10 +80,9 @@ var _ = ginkgo.Describe("create service without plugin", func() { }) }) ginkgo.It("create service failed, name existed", func() { - t := ginkgo.GinkgoT() createServiceBody["name"] = "testservice2" _createServiceBody, err := json.Marshal(createServiceBody) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) base.RunTestCase(base.HttpTestCase{ Object: base.ManagerApiExpect(), Method: http.MethodPost, @@ -98,10 +95,9 @@ var _ = ginkgo.Describe("create service without plugin", func() { }) }) ginkgo.It("update service failed, name existed", func() { - t := ginkgo.GinkgoT() createServiceBody["name"] = "testservice2" _createServiceBody, err := json.Marshal(createServiceBody) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) base.RunTestCase(base.HttpTestCase{ Object: base.ManagerApiExpect(), Method: http.MethodPut, @@ -139,12 +135,11 @@ var _ = ginkgo.Describe("create service without plugin", func() { }) }) ginkgo.It("batch test /server_port api", func() { - t := ginkgo.GinkgoT() time.Sleep(time.Duration(500) * time.Millisecond) res := base.BatchTestServerPort(18) - assert.True(t, res["1980"] == 3) - assert.True(t, res["1981"] == 6) - assert.True(t, res["1982"] == 9) + gomega.Expect(res["1980"]).Should(gomega.Equal(3)) + gomega.Expect(res["1981"]).Should(gomega.Equal(6)) + gomega.Expect(res["1982"]).Should(gomega.Equal(9)) }) ginkgo.It("delete route", func() { base.RunTestCase(base.HttpTestCase{ @@ -189,7 +184,6 @@ var _ = ginkgo.Describe("create service without plugin", func() { var _ = ginkgo.Describe("create service with plugin", func() { ginkgo.It("create service without plugin", func() { - t := ginkgo.GinkgoT() var createServiceBody map[string]interface{} = map[string]interface{}{ "name": "testservice", "plugins": map[string]interface{}{ @@ -212,7 +206,7 @@ var _ = ginkgo.Describe("create service with plugin", func() { }, } _createServiceBody, err := json.Marshal(createServiceBody) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) base.RunTestCase(base.HttpTestCase{ Object: base.ManagerApiExpect(), Method: http.MethodPut, @@ -250,18 +244,17 @@ var _ = ginkgo.Describe("create service with plugin", func() { }) }) ginkgo.It(" hit routes and check the response header", func() { - t := ginkgo.GinkgoT() time.Sleep(time.Duration(500) * time.Millisecond) basepath := base.APISIXHost request, err := http.NewRequest("GET", basepath+"/server_port", nil) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) request.Header.Add("Authorization", base.GetToken()) resp, err := http.DefaultClient.Do(request) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) defer resp.Body.Close() - assert.Equal(t, 200, resp.StatusCode) - assert.Equal(t, "100", resp.Header["X-Ratelimit-Limit"][0]) - assert.Equal(t, "99", resp.Header["X-Ratelimit-Remaining"][0]) + gomega.Expect(resp.StatusCode).Should(gomega.Equal(200)) + gomega.Expect(resp.Header["X-Ratelimit-Limit"][0]).Should(gomega.Equal("100")) + gomega.Expect(resp.Header["X-Ratelimit-Remaining"][0]).Should(gomega.Equal("99")) }) ginkgo.It("delete route", func() { base.RunTestCase(base.HttpTestCase{ @@ -296,7 +289,6 @@ var _ = ginkgo.Describe("create service with plugin", func() { var _ = ginkgo.Describe("create service with all options via POST method", func() { ginkgo.It("create service with all options via POST method", func() { - t := ginkgo.GinkgoT() var createServiceBody map[string]interface{} = map[string]interface{}{ "id": "s2", "name": "testservice22", @@ -329,7 +321,7 @@ var _ = ginkgo.Describe("create service with all options via POST method", func( }, } _createServiceBody, err := json.Marshal(createServiceBody) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) base.RunTestCase(base.HttpTestCase{ Desc: "create service with all options via POST method", Object: base.ManagerApiExpect(), @@ -410,7 +402,6 @@ var _ = ginkgo.Describe("create service with all options via POST method", func( var _ = ginkgo.Describe("service update use patch method", func() { ginkgo.It("create service without plugin", func() { - t := ginkgo.GinkgoT() var createServiceBody map[string]interface{} = map[string]interface{}{ "name": "testservice", "upstream": map[string]interface{}{ @@ -425,7 +416,7 @@ var _ = ginkgo.Describe("service update use patch method", func() { }, } _createServiceBody, err := json.Marshal(createServiceBody) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) base.RunTestCase(base.HttpTestCase{ Desc: "create service without plugin", Object: base.ManagerApiExpect(), @@ -438,7 +429,6 @@ var _ = ginkgo.Describe("service update use patch method", func() { }) }) ginkgo.It("update service use patch method", func() { - t := ginkgo.GinkgoT() var createServiceBody map[string]interface{} = map[string]interface{}{ "name": "testpatch", "upstream": map[string]interface{}{ @@ -453,7 +443,7 @@ var _ = ginkgo.Describe("service update use patch method", func() { }, } _createServiceBody, err := json.Marshal(createServiceBody) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) base.RunTestCase(base.HttpTestCase{ Object: base.ManagerApiExpect(), Method: http.MethodPatch, @@ -476,7 +466,6 @@ var _ = ginkgo.Describe("service update use patch method", func() { }) }) ginkgo.It("Update service using path parameter patch method", func() { - t := ginkgo.GinkgoT() var createUpstreamBody map[string]interface{} = map[string]interface{}{ "type": "roundrobin", "nodes": []map[string]interface{}{ @@ -488,7 +477,7 @@ var _ = ginkgo.Describe("service update use patch method", func() { }, } _createUpstreamBody, err := json.Marshal(createUpstreamBody) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) base.RunTestCase(base.HttpTestCase{ Object: base.ManagerApiExpect(), Method: http.MethodPatch, @@ -524,7 +513,6 @@ var _ = ginkgo.Describe("service update use patch method", func() { }) var _ = ginkgo.Describe("test service delete", func() { - t := ginkgo.GinkgoT() var createServiceBody map[string]interface{} = map[string]interface{}{ "name": "testservice", "upstream": map[string]interface{}{ @@ -539,7 +527,7 @@ var _ = ginkgo.Describe("test service delete", func() { }, } _createServiceBody, err := json.Marshal(createServiceBody) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) table.DescribeTable("test service delete", func(tc base.HttpTestCase) { diff --git a/api/test/e2enew/ssl/ssl_suite_test.go b/api/test/e2enew/ssl/ssl_suite_test.go index e396bd7eb0..a7723e1173 100644 --- a/api/test/e2enew/ssl/ssl_suite_test.go +++ b/api/test/e2enew/ssl/ssl_suite_test.go @@ -21,11 +21,13 @@ import ( "time" "github.com/onsi/ginkgo" + "github.com/onsi/gomega" "github.com/apisix/manager-api/test/e2enew/base" ) func TestSSL(t *testing.T) { + gomega.RegisterFailHandler(ginkgo.Fail) ginkgo.RunSpecs(t, "ssl suite") } diff --git a/api/test/e2enew/ssl/ssl_test.go b/api/test/e2enew/ssl/ssl_test.go index 1fb8669689..bd1fa43d5a 100644 --- a/api/test/e2enew/ssl/ssl_test.go +++ b/api/test/e2enew/ssl/ssl_test.go @@ -20,6 +20,7 @@ import ( "context" "crypto/tls" "encoding/json" + "fmt" "io/ioutil" "net" "net/http" @@ -27,13 +28,12 @@ import ( "github.com/onsi/ginkgo" "github.com/onsi/ginkgo/extensions/table" - "github.com/stretchr/testify/assert" + "github.com/onsi/gomega" "github.com/apisix/manager-api/test/e2enew/base" ) var _ = ginkgo.Describe("SSL Basic", func() { - t := ginkgo.GinkgoT() var ( testCert []byte testKey []byte @@ -46,11 +46,11 @@ var _ = ginkgo.Describe("SSL Basic", func() { var err error testCert, err = ioutil.ReadFile("../../certs/test2.crt") - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) testKey, err = ioutil.ReadFile("../../certs/test2.key") - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) apisixKey, err = ioutil.ReadFile("../../certs/apisix.key") - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) validBody, err = json.Marshal(map[string]interface{}{ "id": "1", @@ -62,7 +62,7 @@ var _ = ginkgo.Describe("SSL Basic", func() { "version": "v3", }, }) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) validBody2, err = json.Marshal(map[string]interface{}{ "id": "1", "cert": string(testCert), @@ -73,14 +73,14 @@ var _ = ginkgo.Describe("SSL Basic", func() { "version": "v2", }, }) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) invalidBody, err = json.Marshal(map[string]string{ "id": "1", "cert": string(testCert), "key": string(apisixKey), }) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) tempBody := map[string]interface{}{ "name": "route1", @@ -98,7 +98,7 @@ var _ = ginkgo.Describe("SSL Basic", func() { }, } createRouteBody, err = json.Marshal(tempBody) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) ginkgo.It("without certificate", func() { // Before configuring SSL, make a HTTPS request @@ -112,8 +112,7 @@ var _ = ginkgo.Describe("SSL Basic", func() { } _, err := http.Get("https://www.test2.com:9443") - assert.NotNil(t, err) - assert.EqualError(t, err, "Get https://www.test2.com:9443: remote error: tls: internal error") + gomega.Expect(fmt.Sprintf("%s", err)).Should(gomega.Equal("Get https://www.test2.com:9443: remote error: tls: internal error")) }) table.DescribeTable("test ssl basic", func(testCase base.HttpTestCase) { @@ -241,8 +240,7 @@ var _ = ginkgo.Describe("SSL Basic", func() { // try again after disable SSL, make a HTTPS request time.Sleep(time.Duration(500) * time.Millisecond) _, err := http.Get("https://www.test2.com:9443") - assert.NotNil(t, err) - assert.EqualError(t, err, "Get https://www.test2.com:9443: remote error: tls: internal error") + gomega.Expect(fmt.Sprintf("%s", err)).Should(gomega.Equal("Get https://www.test2.com:9443: remote error: tls: internal error")) }) table.DescribeTable("test ssl basic", func(testCase base.HttpTestCase) { diff --git a/api/test/e2enew/upstream/upstream_chash_hash_on_test.go b/api/test/e2enew/upstream/upstream_chash_hash_on_test.go index a749e402ec..59d212bf4d 100644 --- a/api/test/e2enew/upstream/upstream_chash_hash_on_test.go +++ b/api/test/e2enew/upstream/upstream_chash_hash_on_test.go @@ -24,7 +24,7 @@ import ( "time" "github.com/onsi/ginkgo" - "github.com/stretchr/testify/assert" + "github.com/onsi/gomega" "github.com/apisix/manager-api/test/e2enew/base" ) @@ -44,14 +44,13 @@ var nodes []map[string]interface{} = []map[string]interface{}{ var _ = ginkgo.Describe("Upstream chash hash on custom header", func() { ginkgo.It("create chash upstream with hash_on (custom_header)", func() { - t := ginkgo.GinkgoT() createUpstreamBody := make(map[string]interface{}) createUpstreamBody["nodes"] = nodes createUpstreamBody["type"] = "chash" createUpstreamBody["key"] = "custom_header" createUpstreamBody["hash_on"] = "header" _createUpstreamBody, err := json.Marshal(createUpstreamBody) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) base.RunTestCase(base.HttpTestCase{ Object: base.ManagerApiExpect(), Method: http.MethodPut, @@ -77,20 +76,19 @@ var _ = ginkgo.Describe("Upstream chash hash on custom header", func() { }) }) ginkgo.It("hit routes(upstream hash_on (custom_header))", func() { - t := ginkgo.GinkgoT() time.Sleep(time.Duration(500) * time.Millisecond) basepath := base.APISIXHost res := map[string]int{} for i := 0; i <= 3; i++ { url := basepath + "/server_port?var=2&var2=" + strconv.Itoa(i) req, err := http.NewRequest("GET", url, nil) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) req.Header.Add("custom_header", `custom-one`) resp, err := http.DefaultClient.Do(req) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) defer resp.Body.Close() respBody, err := ioutil.ReadAll(resp.Body) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) body := string(respBody) if _, ok := res[body]; !ok { res[body] = 1 @@ -99,7 +97,7 @@ var _ = ginkgo.Describe("Upstream chash hash on custom header", func() { } } // it is possible to hit any one of upstreams, and only one will be hit - assert.Equal(t, true, res["1980"] == 4 || res["1981"] == 4) + gomega.Expect(res["1980"] == 4 || res["1981"] == 4).Should(gomega.BeTrue()) }) ginkgo.It("delete route", func() { base.RunTestCase(base.HttpTestCase{ @@ -133,14 +131,13 @@ var _ = ginkgo.Describe("Upstream chash hash on custom header", func() { var _ = ginkgo.Describe("Upstream chash hash on cookie", func() { ginkgo.It("create chash upstream with hash_on (cookie)", func() { - t := ginkgo.GinkgoT() createUpstreamBody := make(map[string]interface{}) createUpstreamBody["nodes"] = nodes createUpstreamBody["type"] = "chash" createUpstreamBody["key"] = "custom_cookie" createUpstreamBody["hash_on"] = "cookie" _createUpstreamBody, err := json.Marshal(createUpstreamBody) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) base.RunTestCase(base.HttpTestCase{ Object: base.ManagerApiExpect(), Method: http.MethodPut, @@ -166,20 +163,19 @@ var _ = ginkgo.Describe("Upstream chash hash on cookie", func() { }) }) ginkgo.It("hit routes(upstream hash_on (custom_cookie))", func() { - t := ginkgo.GinkgoT() time.Sleep(time.Duration(500) * time.Millisecond) basepath := base.APISIXHost res := map[string]int{} for i := 0; i <= 3; i++ { url := basepath + "/server_port" req, err := http.NewRequest("GET", url, nil) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) req.Header.Add("Cookie", `custom-cookie=cuscookie`) resp, err := http.DefaultClient.Do(req) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) defer resp.Body.Close() respBody, err := ioutil.ReadAll(resp.Body) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) body := string(respBody) if _, ok := res[body]; !ok { res[body] = 1 @@ -188,23 +184,22 @@ var _ = ginkgo.Describe("Upstream chash hash on cookie", func() { } } // it is possible to hit any one of upstreams, and only one will be hit - assert.Equal(t, true, res["1980"] == 4 || res["1981"] == 4) + gomega.Expect(res["1980"] == 4 || res["1981"] == 4).Should(gomega.BeTrue()) }) ginkgo.It("hit routes(upstream hash_on (miss_custom_cookie))", func() { - t := ginkgo.GinkgoT() time.Sleep(time.Duration(500) * time.Millisecond) basepath := base.APISIXHost res := map[string]int{} for i := 0; i <= 3; i++ { url := basepath + "/server_port" req, err := http.NewRequest("GET", url, nil) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) req.Header.Add("Cookie", `miss-custom-cookie=cuscookie`) resp, err := http.DefaultClient.Do(req) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) defer resp.Body.Close() respBody, err := ioutil.ReadAll(resp.Body) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) body := string(respBody) if _, ok := res[body]; !ok { res[body] = 1 @@ -213,7 +208,7 @@ var _ = ginkgo.Describe("Upstream chash hash on cookie", func() { } } // it is possible to hit any one of upstreams, and only one will be hit - assert.Equal(t, true, res["1980"] == 4 || res["1981"] == 4) + gomega.Expect(res["1980"] == 4 || res["1981"] == 4).Should(gomega.BeTrue()) }) ginkgo.It("delete route", func() { base.RunTestCase(base.HttpTestCase{ @@ -247,14 +242,13 @@ var _ = ginkgo.Describe("Upstream chash hash on cookie", func() { var _ = ginkgo.Describe("Upstream key contains uppercase letters and hyphen", func() { ginkgo.It("create chash upstream with key contains uppercase letters and hyphen", func() { - t := ginkgo.GinkgoT() createUpstreamBody := make(map[string]interface{}) createUpstreamBody["nodes"] = nodes createUpstreamBody["type"] = "chash" createUpstreamBody["key"] = "X-Sessionid" createUpstreamBody["hash_on"] = "header" _createUpstreamBody, err := json.Marshal(createUpstreamBody) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) base.RunTestCase(base.HttpTestCase{ Object: base.ManagerApiExpect(), Method: http.MethodPut, @@ -280,7 +274,6 @@ var _ = ginkgo.Describe("Upstream key contains uppercase letters and hyphen", fu }) }) ginkgo.It("hit routes(upstream hash_on (X-Sessionid)", func() { - t := ginkgo.GinkgoT() time.Sleep(time.Duration(500) * time.Millisecond) basepath := base.APISIXHost res := map[string]int{} @@ -289,7 +282,7 @@ var _ = ginkgo.Describe("Upstream key contains uppercase letters and hyphen", fu req, err := http.NewRequest("GET", url, nil) req.Header.Add("X-Sessionid", `chash_val_`+strconv.Itoa(i)) resp, err := http.DefaultClient.Do(req) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) defer resp.Body.Close() respBody, err := ioutil.ReadAll(resp.Body) body := string(respBody) @@ -300,8 +293,7 @@ var _ = ginkgo.Describe("Upstream key contains uppercase letters and hyphen", fu } } // the X-Sessionid of each request is different, the weight of upstreams are the same, so these requests will be sent to each upstream equally - assert.Equal(t, true, res["1980"] == 8 && res["1981"] == 8) - + gomega.Expect(res["1980"] == 8 && res["1981"] == 8).Should(gomega.BeTrue()) }) ginkgo.It("delete route", func() { base.RunTestCase(base.HttpTestCase{ @@ -352,13 +344,12 @@ var _ = ginkgo.Describe("Upstream chash hash on consumer", func() { }) }) ginkgo.It("create chash upstream with hash_on (consumer)", func() { - t := ginkgo.GinkgoT() createUpstreamBody := make(map[string]interface{}) createUpstreamBody["nodes"] = nodes createUpstreamBody["type"] = "chash" createUpstreamBody["hash_on"] = "consumer" _createUpstreamBody, err := json.Marshal(createUpstreamBody) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) base.RunTestCase(base.HttpTestCase{ Object: base.ManagerApiExpect(), Method: http.MethodPut, @@ -387,20 +378,19 @@ var _ = ginkgo.Describe("Upstream chash hash on consumer", func() { }) }) ginkgo.It("hit routes(upstream hash_on (consumer))", func() { - t := ginkgo.GinkgoT() time.Sleep(time.Duration(500) * time.Millisecond) basepath := base.APISIXHost res := map[string]int{} for i := 0; i <= 3; i++ { url := basepath + "/server_port" req, err := http.NewRequest("GET", url, nil) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) req.Header.Add("apikey", `auth-jack`) resp, err := http.DefaultClient.Do(req) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) defer resp.Body.Close() respBody, err := ioutil.ReadAll(resp.Body) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) body := string(respBody) if _, ok := res[body]; !ok { res[body] = 1 @@ -409,7 +399,7 @@ var _ = ginkgo.Describe("Upstream chash hash on consumer", func() { } } // it is possible to hit any one of upstreams, and only one will be hit - assert.Equal(t, true, res["1980"] == 4 || res["1981"] == 4) + gomega.Expect(res["1980"] == 4 || res["1981"] == 4).Should(gomega.BeTrue()) }) ginkgo.It("delete consumer", func() { base.RunTestCase(base.HttpTestCase{ @@ -452,13 +442,12 @@ var _ = ginkgo.Describe("Upstream chash hash on consumer", func() { var _ = ginkgo.Describe("Upstream chash hash on wrong key", func() { ginkgo.It("verify upstream with wrong key", func() { - t := ginkgo.GinkgoT() createUpstreamBody := make(map[string]interface{}) createUpstreamBody["nodes"] = nodes createUpstreamBody["type"] = "chash" createUpstreamBody["key"] = "not_support" _createUpstreamBody, err := json.Marshal(createUpstreamBody) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) base.RunTestCase(base.HttpTestCase{ Object: base.ManagerApiExpect(), Method: http.MethodPut, @@ -483,14 +472,13 @@ var _ = ginkgo.Describe("Upstream chash hash on wrong key", func() { var _ = ginkgo.Describe("Upstream chash hash on vars", func() { ginkgo.It("create chash upstream hash_on (vars)", func() { - t := ginkgo.GinkgoT() createUpstreamBody := make(map[string]interface{}) createUpstreamBody["nodes"] = nodes createUpstreamBody["type"] = "chash" createUpstreamBody["hash_on"] = "vars" createUpstreamBody["key"] = "arg_device_id" _createUpstreamBody, err := json.Marshal(createUpstreamBody) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) base.RunTestCase(base.HttpTestCase{ Object: base.ManagerApiExpect(), Method: http.MethodPut, @@ -539,7 +527,6 @@ var _ = ginkgo.Describe("Upstream chash hash on vars", func() { }) }) ginkgo.It("hit routes(upstream hash_on (var))", func() { - t := ginkgo.GinkgoT() time.Sleep(time.Duration(500) * time.Millisecond) basepath := base.APISIXHost res := map[string]int{} @@ -547,7 +534,7 @@ var _ = ginkgo.Describe("Upstream chash hash on vars", func() { url := basepath + "/server_port?device_id=" + strconv.Itoa(i) req, err := http.NewRequest("GET", url, nil) resp, err := http.DefaultClient.Do(req) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) defer resp.Body.Close() respBody, err := ioutil.ReadAll(resp.Body) body := string(respBody) @@ -557,7 +544,7 @@ var _ = ginkgo.Describe("Upstream chash hash on vars", func() { res[body]++ } } - assert.True(t, res["1980"] == 9 && res["1981"] == 9) + gomega.Expect(res["1980"] == 9 && res["1981"] == 9).Should(gomega.BeTrue()) }) ginkgo.It("delete route", func() { base.RunTestCase(base.HttpTestCase{ diff --git a/api/test/e2enew/upstream/upstream_chash_query_string_arg_xxx_test.go b/api/test/e2enew/upstream/upstream_chash_query_string_arg_xxx_test.go index 46af425cc5..0ffcb26d17 100644 --- a/api/test/e2enew/upstream/upstream_chash_query_string_arg_xxx_test.go +++ b/api/test/e2enew/upstream/upstream_chash_query_string_arg_xxx_test.go @@ -25,7 +25,7 @@ import ( "time" "github.com/onsi/ginkgo" - "github.com/stretchr/testify/assert" + "github.com/onsi/gomega" "github.com/apisix/manager-api/test/e2enew/base" ) @@ -53,10 +53,9 @@ var createUpstreamBody map[string]interface{} = map[string]interface{}{ var _ = ginkgo.Describe("Upstream chash query string", func() { ginkgo.It("create chash upstream with key (query_string)", func() { - t := ginkgo.GinkgoT() createUpstreamBody["key"] = "query_string" _createUpstreamBody, err := json.Marshal(createUpstreamBody) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) base.RunTestCase(base.HttpTestCase{ Object: base.ManagerApiExpect(), Method: http.MethodPut, @@ -83,19 +82,18 @@ var _ = ginkgo.Describe("Upstream chash query string", func() { }) }) ginkgo.It("hit routes(upstream query_string)", func() { - t := ginkgo.GinkgoT() time.Sleep(time.Duration(500) * time.Millisecond) basepath := base.APISIXHost res := map[string]int{} for i := 0; i < 180; i++ { url := basepath + "/server_port?var=2&var2=" + strconv.Itoa(i) req, err := http.NewRequest("GET", url, nil) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) resp, err := http.DefaultClient.Do(req) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) defer resp.Body.Close() respBody, err := ioutil.ReadAll(resp.Body) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) body := string(respBody) if _, ok := res[body]; !ok { res[body] = 1 @@ -108,7 +106,7 @@ var _ = ginkgo.Describe("Upstream chash query string", func() { counts = append(counts, value) } sort.Ints(counts) - assert.True(t, float64(counts[2]-counts[0])/float64(counts[1]) < 0.4) + gomega.Expect(float64(counts[2]-counts[0]) / float64(counts[1])).Should(gomega.BeNumerically("<", 0.4)) }) ginkgo.It("delete route", func() { base.RunTestCase(base.HttpTestCase{ @@ -142,10 +140,9 @@ var _ = ginkgo.Describe("Upstream chash query string", func() { var _ = ginkgo.Describe("Upstream chash query string", func() { ginkgo.It("create chash upstream with key (arg_xxx)", func() { - t := ginkgo.GinkgoT() createUpstreamBody["key"] = "arg_device_id" _createUpstreamBody, err := json.Marshal(createUpstreamBody) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) base.RunTestCase(base.HttpTestCase{ Object: base.ManagerApiExpect(), Method: http.MethodPut, @@ -172,19 +169,18 @@ var _ = ginkgo.Describe("Upstream chash query string", func() { }) }) ginkgo.It("hit routes(upstream arg_device_id)", func() { - t := ginkgo.GinkgoT() time.Sleep(time.Duration(500) * time.Millisecond) basepath := base.APISIXHost res := map[string]int{} for i := 0; i <= 17; i++ { url := basepath + "/server_port?device_id=" + strconv.Itoa(i) req, err := http.NewRequest("GET", url, nil) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) resp, err := http.DefaultClient.Do(req) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) defer resp.Body.Close() respBody, err := ioutil.ReadAll(resp.Body) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) body := string(respBody) if _, ok := res[body]; !ok { res[body] = 1 @@ -197,7 +193,7 @@ var _ = ginkgo.Describe("Upstream chash query string", func() { counts = append(counts, value) } sort.Ints(counts) - assert.True(t, float64(counts[2]-counts[0])/float64(counts[1]) < 0.4) + gomega.Expect(float64(counts[2]-counts[0]) / float64(counts[1])).Should(gomega.BeNumerically("<", 0.4)) }) ginkgo.It("delete route", func() { base.RunTestCase(base.HttpTestCase{ diff --git a/api/test/e2enew/upstream/upstream_suite_test.go b/api/test/e2enew/upstream/upstream_suite_test.go index c67a8c7da3..4106d76091 100644 --- a/api/test/e2enew/upstream/upstream_suite_test.go +++ b/api/test/e2enew/upstream/upstream_suite_test.go @@ -21,11 +21,13 @@ import ( "time" "github.com/onsi/ginkgo" + "github.com/onsi/gomega" "github.com/apisix/manager-api/test/e2enew/base" ) func TestRoute(t *testing.T) { + gomega.RegisterFailHandler(ginkgo.Fail) ginkgo.RunSpecs(t, "upstream suite") } diff --git a/api/test/e2enew/upstream/upstream_test.go b/api/test/e2enew/upstream/upstream_test.go index 7071742547..224791f982 100644 --- a/api/test/e2enew/upstream/upstream_test.go +++ b/api/test/e2enew/upstream/upstream_test.go @@ -24,7 +24,7 @@ import ( "github.com/onsi/ginkgo" "github.com/onsi/ginkgo/extensions/table" - "github.com/stretchr/testify/assert" + "github.com/onsi/gomega" "github.com/apisix/manager-api/test/e2enew/base" ) @@ -45,7 +45,6 @@ var _ = ginkgo.Describe("Upstream", func() { }) }) ginkgo.It("create upstream success", func() { - t := ginkgo.GinkgoT() createUpstreamBody := make(map[string]interface{}) createUpstreamBody["name"] = "upstream1" createUpstreamBody["nodes"] = []map[string]interface{}{ @@ -57,7 +56,7 @@ var _ = ginkgo.Describe("Upstream", func() { } createUpstreamBody["type"] = "roundrobin" _createUpstreamBody, err := json.Marshal(createUpstreamBody) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) base.RunTestCase(base.HttpTestCase{ Object: base.ManagerApiExpect(), Method: http.MethodPut, @@ -68,7 +67,6 @@ var _ = ginkgo.Describe("Upstream", func() { }) }) ginkgo.It("create upstream2 success", func() { - t := ginkgo.GinkgoT() createUpstreamBody := make(map[string]interface{}) createUpstreamBody["name"] = "upstream2" createUpstreamBody["nodes"] = []map[string]interface{}{ @@ -80,7 +78,7 @@ var _ = ginkgo.Describe("Upstream", func() { } createUpstreamBody["type"] = "roundrobin" _createUpstreamBody, err := json.Marshal(createUpstreamBody) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) base.RunTestCase(base.HttpTestCase{ Object: base.ManagerApiExpect(), Method: http.MethodPut, @@ -91,7 +89,6 @@ var _ = ginkgo.Describe("Upstream", func() { }) }) ginkgo.It("create upstream failed, name existed", func() { - t := ginkgo.GinkgoT() createUpstreamBody := make(map[string]interface{}) createUpstreamBody["name"] = "upstream2" createUpstreamBody["nodes"] = []map[string]interface{}{ @@ -103,7 +100,7 @@ var _ = ginkgo.Describe("Upstream", func() { } createUpstreamBody["type"] = "roundrobin" _createUpstreamBody, err := json.Marshal(createUpstreamBody) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) base.RunTestCase(base.HttpTestCase{ Object: base.ManagerApiExpect(), Method: http.MethodPost, @@ -116,7 +113,6 @@ var _ = ginkgo.Describe("Upstream", func() { }) }) ginkgo.It("update upstream failed, name existed", func() { - t := ginkgo.GinkgoT() createUpstreamBody := make(map[string]interface{}) createUpstreamBody["name"] = "upstream1" createUpstreamBody["nodes"] = []map[string]interface{}{ @@ -128,7 +124,7 @@ var _ = ginkgo.Describe("Upstream", func() { } createUpstreamBody["type"] = "roundrobin" _createUpstreamBody, err := json.Marshal(createUpstreamBody) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) base.RunTestCase(base.HttpTestCase{ Object: base.ManagerApiExpect(), Method: http.MethodPut, @@ -140,7 +136,6 @@ var _ = ginkgo.Describe("Upstream", func() { }) }) ginkgo.It("update upstream success", func() { - t := ginkgo.GinkgoT() createUpstreamBody := make(map[string]interface{}) createUpstreamBody["name"] = "upstream22" createUpstreamBody["nodes"] = []map[string]interface{}{ @@ -152,7 +147,7 @@ var _ = ginkgo.Describe("Upstream", func() { } createUpstreamBody["type"] = "roundrobin" _createUpstreamBody, err := json.Marshal(createUpstreamBody) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) base.RunTestCase(base.HttpTestCase{ Object: base.ManagerApiExpect(), Method: http.MethodPut, @@ -271,7 +266,6 @@ var _ = ginkgo.Describe("Upstream", func() { var _ = ginkgo.Describe("Upstream update with domain", func() { ginkgo.It("create upstream success", func() { - t := ginkgo.GinkgoT() createUpstreamBody := make(map[string]interface{}) createUpstreamBody["name"] = "upstream1" createUpstreamBody["nodes"] = []map[string]interface{}{ @@ -283,7 +277,7 @@ var _ = ginkgo.Describe("Upstream update with domain", func() { } createUpstreamBody["type"] = "roundrobin" _createUpstreamBody, err := json.Marshal(createUpstreamBody) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) base.RunTestCase(base.HttpTestCase{ Object: base.ManagerApiExpect(), Method: http.MethodPut, @@ -315,7 +309,6 @@ var _ = ginkgo.Describe("Upstream update with domain", func() { }) }) ginkgo.It("update upstream with domain", func() { - t := ginkgo.GinkgoT() createUpstreamBody := make(map[string]interface{}) createUpstreamBody["nodes"] = []map[string]interface{}{ { @@ -326,7 +319,7 @@ var _ = ginkgo.Describe("Upstream update with domain", func() { } createUpstreamBody["type"] = "roundrobin" _createUpstreamBody, err := json.Marshal(createUpstreamBody) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) base.RunTestCase(base.HttpTestCase{ Object: base.ManagerApiExpect(), Method: http.MethodPut, @@ -378,7 +371,6 @@ var _ = ginkgo.Describe("Upstream update with domain", func() { var _ = ginkgo.Describe("Upstream chash remote addr", func() { ginkgo.It("create chash upstream with key (remote_addr)", func() { - t := ginkgo.GinkgoT() createUpstreamBody := make(map[string]interface{}) createUpstreamBody["nodes"] = []map[string]interface{}{ { @@ -401,7 +393,7 @@ var _ = ginkgo.Describe("Upstream chash remote addr", func() { createUpstreamBody["hash_on"] = "header" createUpstreamBody["key"] = "remote_addr" _createUpstreamBody, err := json.Marshal(createUpstreamBody) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) base.RunTestCase(base.HttpTestCase{ Object: base.ManagerApiExpect(), Method: http.MethodPut, @@ -429,19 +421,18 @@ var _ = ginkgo.Describe("Upstream chash remote addr", func() { }) ginkgo.It("hit routes(upstream weight 1)", func() { - t := ginkgo.GinkgoT() time.Sleep(time.Duration(500) * time.Millisecond) basepath := base.APISIXHost request, err := http.NewRequest("GET", basepath+"/server_port", nil) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) request.Header.Add("Authorization", base.GetToken()) res := map[string]int{} for i := 0; i < 18; i++ { resp, err := http.DefaultClient.Do(request) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) defer resp.Body.Close() respBody, err := ioutil.ReadAll(resp.Body) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) body := string(respBody) if _, ok := res[body]; !ok { res[body] = 1 @@ -449,11 +440,10 @@ var _ = ginkgo.Describe("Upstream chash remote addr", func() { res[body]++ } } - assert.Equal(t, 18, res["1982"]) + gomega.Expect(res["1982"]).Should(gomega.Equal(18)) }) ginkgo.It("create chash upstream with key (remote_addr, weight equal 0 or 1)", func() { - t := ginkgo.GinkgoT() createUpstreamBody := make(map[string]interface{}) createUpstreamBody["nodes"] = []map[string]interface{}{ { @@ -476,7 +466,7 @@ var _ = ginkgo.Describe("Upstream chash remote addr", func() { createUpstreamBody["hash_on"] = "header" createUpstreamBody["key"] = "remote_addr" _createUpstreamBody, err := json.Marshal(createUpstreamBody) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) base.RunTestCase(base.HttpTestCase{ Object: base.ManagerApiExpect(), Method: http.MethodPut, @@ -502,27 +492,25 @@ var _ = ginkgo.Describe("Upstream chash remote addr", func() { }) }) ginkgo.It("hit routes(remote_addr, weight equal 0 or 1)", func() { - t := ginkgo.GinkgoT() time.Sleep(time.Duration(500) * time.Millisecond) basepath := base.APISIXHost request, err := http.NewRequest("GET", basepath+"/server_port", nil) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) request.Header.Add("Authorization", base.GetToken()) count := 0 for i := 0; i <= 17; i++ { resp, err := http.DefaultClient.Do(request) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) defer resp.Body.Close() respBody, err := ioutil.ReadAll(resp.Body) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) if string(respBody) == "1980" { count++ } } - assert.Equal(t, 18, count) + gomega.Expect(count).Should(gomega.Equal(18)) }) ginkgo.It("create chash upstream with key (remote_addr, all weight equal 0)", func() { - t := ginkgo.GinkgoT() createUpstreamBody := make(map[string]interface{}) createUpstreamBody["nodes"] = []map[string]interface{}{ { @@ -540,7 +528,7 @@ var _ = ginkgo.Describe("Upstream chash remote addr", func() { createUpstreamBody["hash_on"] = "header" createUpstreamBody["key"] = "remote_addr" _createUpstreamBody, err := json.Marshal(createUpstreamBody) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) base.RunTestCase(base.HttpTestCase{ Object: base.ManagerApiExpect(), @@ -599,7 +587,6 @@ var _ = ginkgo.Describe("Upstream chash remote addr", func() { ExpectStatus: http.StatusOK, }) }) - ginkgo.It("get the upstream to verify config", func() { base.RunTestCase(base.HttpTestCase{ Object: base.ManagerApiExpect(), @@ -652,7 +639,6 @@ var _ = ginkgo.Describe("Upstream chash remote addr", func() { var _ = ginkgo.Describe("Upstream create via post", func() { ginkgo.It("create upstream via POST", func() { - t := ginkgo.GinkgoT() createUpstreamBody := make(map[string]interface{}) createUpstreamBody["id"] = "u1" createUpstreamBody["nodes"] = []map[string]interface{}{ @@ -664,7 +650,7 @@ var _ = ginkgo.Describe("Upstream create via post", func() { } createUpstreamBody["type"] = "roundrobin" _createUpstreamBody, err := json.Marshal(createUpstreamBody) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) base.RunTestCase(base.HttpTestCase{ Object: base.ManagerApiExpect(), Method: http.MethodPost, @@ -733,7 +719,6 @@ var _ = ginkgo.Describe("Upstream create via post", func() { var _ = ginkgo.Describe("Upstream update use patch method", func() { ginkgo.It("create upstream via POST", func() { - t := ginkgo.GinkgoT() createUpstreamBody := make(map[string]interface{}) createUpstreamBody["id"] = "u1" createUpstreamBody["nodes"] = []map[string]interface{}{ @@ -745,7 +730,7 @@ var _ = ginkgo.Describe("Upstream update use patch method", func() { } createUpstreamBody["type"] = "roundrobin" _createUpstreamBody, err := json.Marshal(createUpstreamBody) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) base.RunTestCase(base.HttpTestCase{ Object: base.ManagerApiExpect(), Method: http.MethodPost, @@ -758,7 +743,6 @@ var _ = ginkgo.Describe("Upstream update use patch method", func() { }) }) ginkgo.It("update upstream use patch method", func() { - t := ginkgo.GinkgoT() createUpstreamBody := make(map[string]interface{}) createUpstreamBody["nodes"] = []map[string]interface{}{ { @@ -769,7 +753,7 @@ var _ = ginkgo.Describe("Upstream update use patch method", func() { } createUpstreamBody["type"] = "roundrobin" _createUpstreamBody, err := json.Marshal(createUpstreamBody) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) base.RunTestCase(base.HttpTestCase{ Object: base.ManagerApiExpect(), Method: http.MethodPatch, @@ -780,7 +764,6 @@ var _ = ginkgo.Describe("Upstream update use patch method", func() { }) }) ginkgo.It("get upstream data", func() { - base.RunTestCase(base.HttpTestCase{ Object: base.ManagerApiExpect(), Method: http.MethodGet, @@ -791,7 +774,6 @@ var _ = ginkgo.Describe("Upstream update use patch method", func() { }) }) ginkgo.It("Upstream update use patch method", func() { - t := ginkgo.GinkgoT() var nodes []map[string]interface{} = []map[string]interface{}{ { "host": base.UpstreamIp, @@ -800,7 +782,7 @@ var _ = ginkgo.Describe("Upstream update use patch method", func() { }, } _nodes, err := json.Marshal(nodes) - assert.Nil(t, err) + gomega.Expect(err).To(gomega.BeNil()) base.RunTestCase(base.HttpTestCase{ Object: base.ManagerApiExpect(), Method: http.MethodPatch,