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

chore: use gomega match assertion #1678

Merged
merged 6 commits into from
Apr 1, 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
8 changes: 3 additions & 5 deletions api/test/e2enew/route/route_with_script_luacode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
17 changes: 6 additions & 11 deletions api/test/e2enew/route/route_with_vars_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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",
Expand All @@ -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,
Expand Down Expand Up @@ -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",
Expand All @@ -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,
Expand Down Expand Up @@ -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",
Expand All @@ -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,
Expand Down Expand Up @@ -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",
Expand All @@ -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,
Expand Down Expand Up @@ -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",
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
51 changes: 20 additions & 31 deletions api/test/e2enew/route_online_debug/route_online_debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand All @@ -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,
Expand Down Expand Up @@ -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",
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -285,15 +282,14 @@ 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",
"methods": []string{"POST"},
"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,
Expand Down Expand Up @@ -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",
Expand All @@ -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,
Expand Down Expand Up @@ -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",
Expand All @@ -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,
Expand Down Expand Up @@ -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",
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -745,15 +737,14 @@ 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_",
"methods": []string{"POST"},
"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,
Expand All @@ -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},
}
Expand All @@ -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")
Expand All @@ -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{})
Expand Down
2 changes: 2 additions & 0 deletions api/test/e2enew/service/service_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
Loading