1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-18 10:27:06 +00:00

fix #2158 and more

This commit is contained in:
Gerasimos (Makis) Maropoulos
2023-07-08 02:08:18 +03:00
parent 757e7fe61b
commit 6add1ba49b
79 changed files with 551 additions and 467 deletions

View File

@@ -50,39 +50,39 @@ func TestRoutingBasic(t *testing.T) {
e := httptest.New(t, app)
e.GET("/anotfound").Expect().Status(httptest.StatusNotFound).
Body().Equal(expectedNotFoundResponse)
Body().IsEqual(expectedNotFoundResponse)
e.GET("/").Expect().Status(httptest.StatusOK).
Body().Equal(expectedIndexResponse)
Body().IsEqual(expectedIndexResponse)
e.GET("/home").Expect().Status(httptest.StatusOK).
Body().Equal(expectedHomeResponse)
Body().IsEqual(expectedHomeResponse)
e.GET("/u/some/path/here").Expect().Status(httptest.StatusOK).
Body().Equal(expectedUpathResponse)
Body().IsEqual(expectedUpathResponse)
e.GET("/u/abcd123").Expect().Status(httptest.StatusOK).
Body().Equal(expectedUStringResponse)
Body().IsEqual(expectedUStringResponse)
e.GET("/u/-1").Expect().Status(httptest.StatusOK).
Body().Equal(expectedUIntResponse)
Body().IsEqual(expectedUIntResponse)
e.GET("/u/42").Expect().Status(httptest.StatusOK).
Body().Equal(expectedUUintResponse)
Body().IsEqual(expectedUUintResponse)
e.GET("/u/abcd").Expect().Status(httptest.StatusOK).
Body().Equal(expectedUAlphabeticalResponse)
Body().IsEqual(expectedUAlphabeticalResponse)
e.GET("/api/users/42").Expect().Status(httptest.StatusOK).
JSON().Equal(expectedAPIUsersIndexResponse)
JSON().IsEqual(expectedAPIUsersIndexResponse)
e.GET("/admin").Expect().Status(httptest.StatusOK).
Body().Equal(expectedAdminIndexResponse)
Body().IsEqual(expectedAdminIndexResponse)
e.Request("GET", "/").WithURL("http://v1.example.com").Expect().Status(httptest.StatusOK).
Body().Equal(expectedSubdomainV1IndexResponse)
Body().IsEqual(expectedSubdomainV1IndexResponse)
e.Request("GET", "/api/users").WithURL("http://v1.example.com").Expect().Status(httptest.StatusOK).
Body().Equal(expectedSubdomainV1APIUsersIndexResponse)
Body().IsEqual(expectedSubdomainV1APIUsersIndexResponse)
e.Request("GET", "/api/users/42").WithURL("http://v1.example.com").Expect().Status(httptest.StatusOK).
Body().Equal(expectedSubdomainV1APIUsersIndexWithParamResponse)
Body().IsEqual(expectedSubdomainV1APIUsersIndexWithParamResponse)
e.Request("GET", "/").WithURL("http://any-subdomain-here.example.com").Expect().Status(httptest.StatusOK).
Body().Equal(expectedSubdomainWildcardIndexResponse)
Body().IsEqual(expectedSubdomainWildcardIndexResponse)
}

View File

@@ -11,7 +11,7 @@ func TestNewConditionalHandler(t *testing.T) {
e := httptest.New(t, app)
e.GET("/api/v1/users").Expect().Status(httptest.StatusOK).
Body().Equal("requested: <b>/api/v1/users</b>")
Body().IsEqual("requested: <b>/api/v1/users</b>")
e.GET("/api/v1/users").WithQuery("admin", "true").Expect().Status(httptest.StatusOK).
Body().Equal("<title>Admin</title>\n<h1>Hello Admin</h1><br>requested: <b>/api/v1/users</b>")
Body().IsEqual("<title>Admin</title>\n<h1>Hello Admin</h1><br>requested: <b>/api/v1/users</b>")
}

View File

@@ -54,7 +54,7 @@ func TestCustomWrapper(t *testing.T) {
e.GET(url).Expect().
Status(httptest.StatusOK).
Body().Equal(contents)
Body().IsEqual(contents)
}
e.GET("/other/something").Expect().Status(httptest.StatusOK)

View File

@@ -35,7 +35,7 @@ func TestSameParameterTypeDifferentMacroFunctions(t *testing.T) {
}
)
e.GET("/").Expect().Status(httptest.StatusOK).JSON().Equal(expectedIndex)
e.GET("/api/random.html").Expect().Status(httptest.StatusOK).JSON().Equal(expectedHTMLPage)
e.GET("/api/random.zip").Expect().Status(httptest.StatusOK).JSON().Equal(expectedZipName)
e.GET("/").Expect().Status(httptest.StatusOK).JSON().IsEqual(expectedIndex)
e.GET("/api/random.html").Expect().Status(httptest.StatusOK).JSON().IsEqual(expectedHTMLPage)
e.GET("/api/random.zip").Expect().Status(httptest.StatusOK).JSON().IsEqual(expectedZipName)
}

View File

@@ -20,6 +20,6 @@ func TestSamePatternDifferentFuncUseGlobal(t *testing.T) {
for path, mainBody := range tests {
result := fmt.Sprintf(expectedResultFmt, mainBody, path[1:])
e.GET(path).Expect().Status(httptest.StatusOK).Body().Equal(result)
e.GET(path).Expect().Status(httptest.StatusOK).Body().IsEqual(result)
}
}

View File

@@ -10,5 +10,5 @@ func TestResetCompressionAndFireError(t *testing.T) { // #1569
app := newApp()
e := httptest.New(t, app)
e.GET("/").Expect().Status(httptest.StatusBadRequest).Body().Equal("custom error")
e.GET("/").Expect().Status(httptest.StatusBadRequest).Body().IsEqual("custom error")
}

View File

@@ -116,26 +116,26 @@ func TestRouting(t *testing.T) {
if tt.subdomain != "" {
et.WithURL("http://" + tt.subdomain + ".localhost:8080")
}
et.Expect().Status(tt.status).Body().Equal(tt.expectedBody)
et.Expect().Status(tt.status).Body().IsEqual(tt.expectedBody)
}
// test POST "/" limit data and post data return
// test with small body
e.POST("/").WithBytes([]byte("ok")).Expect().Status(httptest.StatusOK).Body().Equal("ok")
e.POST("/").WithBytes([]byte("ok")).Expect().Status(httptest.StatusOK).Body().IsEqual("ok")
// test with equal to max body size limit
bsent := make([]byte, maxBodySize, maxBodySize)
e.POST("/").WithBytes(bsent).Expect().Status(httptest.StatusOK).Body().Length().Equal(len(bsent))
// test with larger body sent and wait for the custom response
largerBSent := make([]byte, maxBodySize+1, maxBodySize+1)
e.POST("/").WithBytes(largerBSent).Expect().Status(httptest.StatusBadRequest).Body().Equal("http: request body too large")
e.POST("/").WithBytes(largerBSent).Expect().Status(httptest.StatusBadRequest).Body().IsEqual("http: request body too large")
// test the post value (both post and put) and headers.
e.PUT("/postvalue").WithFormField("name", "test_put").
WithHeader("headername", "headervalue_put").Expect().
Status(httptest.StatusOK).Body().Equal("Hello test_put | headervalue_put")
Status(httptest.StatusOK).Body().IsEqual("Hello test_put | headervalue_put")
e.POST("/postvalue").WithFormField("name", "test_post").
WithHeader("headername", "headervalue_post").Expect().
Status(httptest.StatusOK).Body().Equal("Hello test_post | headervalue_post")
Status(httptest.StatusOK).Body().IsEqual("Hello test_post | headervalue_post")
}

View File

@@ -10,5 +10,5 @@ func TestSimpleRouteRemoveHandler(t *testing.T) {
app := newApp()
e := httptest.New(t, app)
e.GET("/api/users").Expect().Status(httptest.StatusOK).Body().Equal("OK")
e.GET("/api/users").Expect().Status(httptest.StatusOK).Body().IsEqual("OK")
}

View File

@@ -14,5 +14,5 @@ func TestSitemap(t *testing.T) {
app.Configure(iris.WithSitemap(startURL))
e := httptest.New(t, app)
e.GET("/sitemap.xml").Expect().Status(httptest.StatusOK).Body().Equal(expectedFullSitemapXML)
e.GET("/sitemap.xml").Expect().Status(httptest.StatusOK).Body().IsEqual(expectedFullSitemapXML)
}

View File

@@ -52,6 +52,6 @@ func TestSubdomainWWW(t *testing.T) {
req.Expect().
Status(httptest.StatusOK).
Body().Equal(test.response())
Body().IsEqual(test.response())
}
}

View File

@@ -10,7 +10,7 @@ func TestShareFuncs(t *testing.T) {
app := newApp()
e := httptest.New(t, app)
e.GET("/").Expect().Status(httptest.StatusOK).Body().Equal("Hello, Gophers!")
e.GET("/2").Expect().Status(httptest.StatusOK).Body().Equal("Hello, Gophers [2]!")
e.GET("/3").Expect().Status(httptest.StatusOK).Body().Equal("OK, job was executed.\nSee the command prompt.")
e.GET("/").Expect().Status(httptest.StatusOK).Body().IsEqual("Hello, Gophers!")
e.GET("/2").Expect().Status(httptest.StatusOK).Body().IsEqual("Hello, Gophers [2]!")
e.GET("/3").Expect().Status(httptest.StatusOK).Body().IsEqual("OK, job was executed.\nSee the command prompt.")
}

View File

@@ -10,5 +10,5 @@ func TestShareServices(t *testing.T) {
app := newApp()
e := httptest.New(t, app)
e.GET("/").Expect().Status(httptest.StatusOK).Body().Equal("Hello, Gophers!")
e.GET("/").Expect().Status(httptest.StatusOK).Body().IsEqual("Hello, Gophers!")
}