mirror of
https://github.com/kataras/iris.git
synced 2026-02-03 17:26:00 +00:00
fix #2158 and more
This commit is contained in:
@@ -17,11 +17,11 @@ func TestBasicAuth(t *testing.T) {
|
||||
|
||||
// with valid basic auth
|
||||
e.GET("/admin").WithBasicAuth("myusername", "mypassword").Expect().
|
||||
Status(httptest.StatusOK).Body().Equal("/admin myusername:mypassword")
|
||||
Status(httptest.StatusOK).Body().IsEqual("/admin myusername:mypassword")
|
||||
e.GET("/admin/profile").WithBasicAuth("myusername", "mypassword").Expect().
|
||||
Status(httptest.StatusOK).Body().Equal("/admin/profile myusername:mypassword")
|
||||
Status(httptest.StatusOK).Body().IsEqual("/admin/profile myusername:mypassword")
|
||||
e.GET("/admin/settings").WithBasicAuth("myusername", "mypassword").Expect().
|
||||
Status(httptest.StatusOK).Body().Equal("/admin/settings myusername:mypassword")
|
||||
Status(httptest.StatusOK).Body().IsEqual("/admin/settings myusername:mypassword")
|
||||
|
||||
// with invalid basic auth
|
||||
e.GET("/admin/settings").WithBasicAuth("invalidusername", "invalidpassword").
|
||||
|
||||
@@ -14,11 +14,11 @@ func TestApp(t *testing.T) {
|
||||
// test our routes
|
||||
e.GET("/").Expect().Status(httptest.StatusOK)
|
||||
e.GET("/follower/42").Expect().Status(httptest.StatusOK).
|
||||
Body().Equal("from /follower/{id:int64} with ID: 42")
|
||||
Body().IsEqual("from /follower/{id:int64} with ID: 42")
|
||||
e.GET("/following/52").Expect().Status(httptest.StatusOK).
|
||||
Body().Equal("from /following/{id:int64} with ID: 52")
|
||||
Body().IsEqual("from /following/{id:int64} with ID: 52")
|
||||
e.GET("/like/64").Expect().Status(httptest.StatusOK).
|
||||
Body().Equal("from /like/{id:int64} with ID: 64")
|
||||
Body().IsEqual("from /like/{id:int64} with ID: 64")
|
||||
|
||||
// test not found
|
||||
e.GET("/notfound").Expect().Status(httptest.StatusNotFound)
|
||||
@@ -28,5 +28,5 @@ func TestApp(t *testing.T) {
|
||||
"message": "",
|
||||
}
|
||||
e.GET("/anotfoundwithjson").WithQuery("json", nil).
|
||||
Expect().Status(httptest.StatusNotFound).JSON().Equal(expectedErr)
|
||||
Expect().Status(httptest.StatusNotFound).JSON().IsEqual(expectedErr)
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ func TestCookiesBasic(t *testing.T) {
|
||||
|
||||
// Test retrieve a Cookie.
|
||||
t2 := e.GET(fmt.Sprintf("/cookies/%s", cookieName)).Expect().Status(httptest.StatusOK)
|
||||
t2.Body().Equal(cookieValue)
|
||||
t2.Body().IsEqual(cookieValue)
|
||||
|
||||
// Test remove a Cookie.
|
||||
t3 := e.DELETE(fmt.Sprintf("/cookies/%s", cookieName)).Expect().Status(httptest.StatusOK)
|
||||
@@ -28,5 +28,5 @@ func TestCookiesBasic(t *testing.T) {
|
||||
|
||||
t4 := e.GET(fmt.Sprintf("/cookies/%s", cookieName)).Expect().Status(httptest.StatusOK)
|
||||
t4.Cookies().Empty()
|
||||
t4.Body().Empty()
|
||||
t4.Body().IsEmpty()
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ func TestCookieOptions(t *testing.T) {
|
||||
|
||||
// Test retrieve a Cookie.
|
||||
t2 := e.GET(fmt.Sprintf("/get/%s", cookieName)).Expect().Status(httptest.StatusOK)
|
||||
t2.Body().Equal(cookieValue)
|
||||
t2.Body().IsEqual(cookieValue)
|
||||
|
||||
// Test remove a Cookie.
|
||||
t3 := e.GET(fmt.Sprintf("/remove/%s", cookieName)).Expect().Status(httptest.StatusOK)
|
||||
@@ -28,5 +28,5 @@ func TestCookieOptions(t *testing.T) {
|
||||
|
||||
t4 := e.GET(fmt.Sprintf("/get/%s", cookieName)).Expect().Status(httptest.StatusOK)
|
||||
t4.Cookies().Empty()
|
||||
t4.Body().Empty()
|
||||
t4.Body().IsEmpty()
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ func TestSecureCookie(t *testing.T) {
|
||||
|
||||
// Test retrieve a Cookie.
|
||||
t2 := e.GET(fmt.Sprintf("/cookies/%s", cookieName)).Expect().Status(httptest.StatusOK)
|
||||
t2.Body().Equal(cookieValue)
|
||||
t2.Body().IsEqual(cookieValue)
|
||||
|
||||
// Test remove a Cookie.
|
||||
t3 := e.GET(fmt.Sprintf("/cookies/remove/%s", cookieName)).Expect().Status(httptest.StatusOK)
|
||||
@@ -30,5 +30,5 @@ func TestSecureCookie(t *testing.T) {
|
||||
|
||||
t4 := e.GET(fmt.Sprintf("/cookies/%s", cookieName)).Expect().Status(httptest.StatusOK)
|
||||
t4.Cookies().Empty()
|
||||
t4.Body().Empty()
|
||||
t4.Body().IsEmpty()
|
||||
}
|
||||
|
||||
@@ -12,14 +12,14 @@ func TestDependencyInjectionBasic_Middleware(t *testing.T) {
|
||||
e := httptest.New(t, app)
|
||||
e.POST("/42").WithJSON(testInput{Email: "my_email"}).Expect().
|
||||
Status(httptest.StatusOK).
|
||||
JSON().Equal(testOutput{ID: 42, Name: "my_email"})
|
||||
JSON().IsEqual(testOutput{ID: 42, Name: "my_email"})
|
||||
|
||||
// it should stop the execution at the middleware and return the middleware's status code,
|
||||
// because the error is `ErrStopExecution`.
|
||||
e.POST("/42").WithJSON(testInput{Email: "invalid"}).Expect().
|
||||
Status(httptest.StatusAccepted).Body().Empty()
|
||||
Status(httptest.StatusAccepted).Body().IsEmpty()
|
||||
|
||||
// it should stop the execution at the middleware and return the error's text.
|
||||
e.POST("/42").WithJSON(testInput{Email: "error"}).Expect().
|
||||
Status(httptest.StatusConflict).Body().Equal("my_error")
|
||||
Status(httptest.StatusConflict).Body().IsEqual("my_error")
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ func TestFileServerBasic(t *testing.T) {
|
||||
e.GET(url).Expect().
|
||||
Status(httptest.StatusOK).
|
||||
ContentType(u.contentType(), app.ConfigurationReadOnly().GetCharset()).
|
||||
Body().Equal(contents)
|
||||
Body().IsEqual(contents)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,6 +109,6 @@ func TestHandleDirDot(t *testing.T) {
|
||||
e.GET(url).Expect().
|
||||
Status(httptest.StatusOK).
|
||||
ContentType(u.contentType(), app.ConfigurationReadOnly().GetCharset()).
|
||||
Body().Equal(contents)
|
||||
Body().IsEqual(contents)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,6 +89,6 @@ func TestEmbeddingFilesIntoApp(t *testing.T) {
|
||||
e.GET(url).Expect().
|
||||
Status(httptest.StatusOK).
|
||||
ContentType(u.contentType()).
|
||||
Body().Equal(contents)
|
||||
Body().IsEqual(contents)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,6 +84,6 @@ func TestEmbeddingFilesIntoApp(t *testing.T) {
|
||||
e.GET(url).Expect().
|
||||
Status(httptest.StatusOK).
|
||||
ContentType(u.contentType()).
|
||||
Body().Equal(contents)
|
||||
Body().IsEqual(contents)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ func TestSPAEmbedded(t *testing.T) {
|
||||
e.GET(url).Expect().
|
||||
Status(httptest.StatusOK).
|
||||
ContentType(u.contentType(), app.ConfigurationReadOnly().GetCharset()).
|
||||
Body().Equal(contents)
|
||||
Body().IsEqual(contents)
|
||||
}
|
||||
|
||||
e.GET("/index.html").Expect().Status(httptest.StatusNotFound) // only root is served.
|
||||
|
||||
@@ -76,6 +76,6 @@ func TestFileServerSubdomainBasic(t *testing.T) {
|
||||
e.GET(url).WithURL(host).Expect().
|
||||
Status(httptest.StatusOK).
|
||||
ContentType(u.contentType(), app.ConfigurationReadOnly().GetCharset()).
|
||||
Body().Equal(contents)
|
||||
Body().IsEqual(contents)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,49 +40,49 @@ func TestI18n(t *testing.T) {
|
||||
|
||||
e := httptest.New(t, app)
|
||||
// default should be en-US.
|
||||
e.GET("/").Expect().Status(httptest.StatusOK).Body().Equal(tests["en-US"])
|
||||
e.GET("/").Expect().Status(httptest.StatusOK).Body().IsEqual(tests["en-US"])
|
||||
|
||||
for lang, body := range tests {
|
||||
e.GET("/").WithQueryString("lang=" + lang).Expect().Status(httptest.StatusOK).
|
||||
Body().Equal(body)
|
||||
Body().IsEqual(body)
|
||||
|
||||
// test lowercase.
|
||||
e.GET("/").WithQueryString("lang=" + strings.ToLower(lang)).Expect().Status(httptest.StatusOK).
|
||||
Body().Equal(body)
|
||||
Body().IsEqual(body)
|
||||
|
||||
// test first part (e.g. en instead of en-US).
|
||||
langFirstPart := strings.Split(lang, "-")[0]
|
||||
e.GET("/").WithQueryString("lang=" + langFirstPart).Expect().Status(httptest.StatusOK).
|
||||
Body().Equal(body)
|
||||
Body().IsEqual(body)
|
||||
|
||||
// test accept-language header prefix (i18n wrapper).
|
||||
e.GET("/"+lang).WithHeader("Accept-Language", lang).Expect().Status(httptest.StatusOK).
|
||||
Body().Equal(body)
|
||||
Body().IsEqual(body)
|
||||
|
||||
// test path prefix (i18n router wrapper).
|
||||
e.GET("/" + lang).Expect().Status(httptest.StatusOK).
|
||||
Body().Equal(body)
|
||||
Body().IsEqual(body)
|
||||
|
||||
// test path prefix with first part.
|
||||
e.GET("/" + langFirstPart).Expect().Status(httptest.StatusOK).
|
||||
Body().Equal(body)
|
||||
Body().IsEqual(body)
|
||||
}
|
||||
|
||||
e.GET("/other").WithQueryString("lang=el-GR").Expect().Status(httptest.StatusOK).
|
||||
Body().Equal(elgrMulti)
|
||||
Body().IsEqual(elgrMulti)
|
||||
e.GET("/other").WithQueryString("lang=en-US").Expect().Status(httptest.StatusOK).
|
||||
Body().Equal(enusMulti)
|
||||
Body().IsEqual(enusMulti)
|
||||
|
||||
// test path prefix (i18n router wrapper).
|
||||
e.GET("/el-gr/other").Expect().Status(httptest.StatusOK).
|
||||
Body().Equal(elgrMulti)
|
||||
Body().IsEqual(elgrMulti)
|
||||
e.GET("/en/other").Expect().Status(httptest.StatusOK).
|
||||
Body().Equal(enusMulti)
|
||||
Body().IsEqual(enusMulti)
|
||||
|
||||
e.GET("/el-GRtemplates").Expect().Status(httptest.StatusNotFound)
|
||||
e.GET("/el-templates").Expect().Status(httptest.StatusNotFound)
|
||||
|
||||
e.GET("/el/templates").Expect().Status(httptest.StatusOK).Body().Contains(elGR).Contains(zhCN)
|
||||
|
||||
e.GET("/not-matched").WithQuery("lang", "en-gb").Expect().Status(httptest.StatusOK).Body().Equal("user language input: en-gb: matched as: en-US: not found key: not_found_key: args: [some values 42]")
|
||||
e.GET("/not-matched").WithQuery("lang", "en-gb").Expect().Status(httptest.StatusOK).Body().IsEqual("user language input: en-gb: matched as: en-US: not found key: not_found_key: args: [some values 42]")
|
||||
}
|
||||
|
||||
@@ -11,11 +11,11 @@ func TestI18nLoaderFuncMap(t *testing.T) {
|
||||
|
||||
e := httptest.New(t, app)
|
||||
e.GET("/").Expect().Status(httptest.StatusOK).
|
||||
Body().Equal("Become a MEMBER")
|
||||
Body().IsEqual("Become a MEMBER")
|
||||
e.GET("/title").Expect().Status(httptest.StatusOK).
|
||||
Body().Equal("Account Connections")
|
||||
Body().IsEqual("Account Connections")
|
||||
e.GET("/").WithHeader("Accept-Language", "el").Expect().Status(httptest.StatusOK).
|
||||
Body().Equal("Γίνε ΜΈΛΟΣ")
|
||||
Body().IsEqual("Γίνε ΜΈΛΟΣ")
|
||||
e.GET("/title").WithHeader("Accept-Language", "el").Expect().Status(httptest.StatusOK).
|
||||
Body().Equal("Λογαριασμός Συνδέσεις")
|
||||
Body().IsEqual("Λογαριασμός Συνδέσεις")
|
||||
}
|
||||
|
||||
@@ -11,11 +11,11 @@ func TestI18nLoaderFuncMap(t *testing.T) {
|
||||
|
||||
e := httptest.New(t, app)
|
||||
e.GET("/").Expect().Status(httptest.StatusOK).
|
||||
Body().Equal("Become a MEMBER")
|
||||
Body().IsEqual("Become a MEMBER")
|
||||
e.GET("/title").Expect().Status(httptest.StatusOK).
|
||||
Body().Equal("Account Connections")
|
||||
Body().IsEqual("Account Connections")
|
||||
e.GET("/").WithHeader("Accept-Language", "el").Expect().Status(httptest.StatusOK).
|
||||
Body().Equal("Γίνε ΜΈΛΟΣ")
|
||||
Body().IsEqual("Γίνε ΜΈΛΟΣ")
|
||||
e.GET("/title").WithHeader("Accept-Language", "el").Expect().Status(httptest.StatusOK).
|
||||
Body().Equal("Λογαριασμός Συνδέσεις")
|
||||
Body().IsEqual("Λογαριασμός Συνδέσεις")
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ func TestJSONLogger(t *testing.T) {
|
||||
wg.Add(iters)
|
||||
for i := 0; i < iters; i++ {
|
||||
go func() {
|
||||
e.GET("/ping").Expect().Status(httptest.StatusOK).Body().Equal("pong")
|
||||
e.GET("/ping").Expect().Status(httptest.StatusOK).Body().IsEqual("pong")
|
||||
wg.Done()
|
||||
}()
|
||||
}
|
||||
|
||||
@@ -11,14 +11,14 @@ func TestMVCOverlapping(t *testing.T) {
|
||||
|
||||
e := httptest.New(t, app, httptest.URL("http://example.com"))
|
||||
// unauthenticated.
|
||||
e.GET("/user").Expect().Status(httptest.StatusOK).Body().Equal("custom action to redirect on authentication page")
|
||||
e.GET("/user").Expect().Status(httptest.StatusOK).Body().IsEqual("custom action to redirect on authentication page")
|
||||
// login.
|
||||
e.POST("/user/login").Expect().Status(httptest.StatusOK)
|
||||
// authenticated.
|
||||
e.GET("/user").Expect().Status(httptest.StatusOK).Body().Equal(`UserController.Get: The Authenticated type
|
||||
e.GET("/user").Expect().Status(httptest.StatusOK).Body().IsEqual(`UserController.Get: The Authenticated type
|
||||
can be used to secure a controller's method too.`)
|
||||
// logout.
|
||||
e.POST("/user/logout").Expect().Status(httptest.StatusOK)
|
||||
// unauthenticated.
|
||||
e.GET("/user").Expect().Status(httptest.StatusOK).Body().Equal("custom action to redirect on authentication page")
|
||||
e.GET("/user").Expect().Status(httptest.StatusOK).Body().IsEqual("custom action to redirect on authentication page")
|
||||
}
|
||||
|
||||
@@ -15,6 +15,6 @@ func TestControllerHandleHTTPError(t *testing.T) {
|
||||
app := newApp()
|
||||
|
||||
e := httptest.New(t, app)
|
||||
e.GET("/").Expect().Status(httptest.StatusOK).Body().Equal(expectedIndex)
|
||||
e.GET("/a_notefound").Expect().Status(httptest.StatusNotFound).ContentType("text/html").Body().Equal(expectedNotFound)
|
||||
e.GET("/").Expect().Status(httptest.StatusOK).Body().IsEqual(expectedIndex)
|
||||
e.GET("/a_notefound").Expect().Status(httptest.StatusNotFound).ContentType("text/html").Body().IsEqual(expectedNotFound)
|
||||
}
|
||||
|
||||
@@ -12,5 +12,5 @@ func TestGRPCCompatible(t *testing.T) {
|
||||
e := httptest.New(t, app)
|
||||
e.POST("/helloworld.Greeter/SayHello").WithJSON(map[string]string{"name": "makis"}).Expect().
|
||||
Status(httptest.StatusOK).
|
||||
JSON().Equal(map[string]string{"message": "Hello makis"})
|
||||
JSON().IsEqual(map[string]string{"message": "Hello makis"})
|
||||
}
|
||||
|
||||
@@ -10,14 +10,14 @@ func TestMVCHelloWorld(t *testing.T) {
|
||||
e := httptest.New(t, newApp())
|
||||
|
||||
e.GET("/").Expect().Status(httptest.StatusOK).
|
||||
ContentType("text/html", "utf-8").Body().Equal("<h1>Welcome</h1>")
|
||||
ContentType("text/html", "utf-8").Body().IsEqual("<h1>Welcome</h1>")
|
||||
|
||||
e.GET("/ping").Expect().Status(httptest.StatusOK).
|
||||
Body().Equal("pong")
|
||||
Body().IsEqual("pong")
|
||||
|
||||
e.GET("/hello").Expect().Status(httptest.StatusOK).
|
||||
JSON().Object().Value("message").Equal("Hello Iris!")
|
||||
|
||||
e.GET("/custom_path").Expect().Status(httptest.StatusOK).
|
||||
Body().Equal("hello from the custom handler without following the naming guide")
|
||||
Body().IsEqual("hello from the custom handler without following the naming guide")
|
||||
}
|
||||
|
||||
@@ -13,21 +13,21 @@ func TestVersionedController(t *testing.T) {
|
||||
|
||||
e := httptest.New(t, app)
|
||||
e.GET("/data").WithHeader(versioning.AcceptVersionHeaderKey, "1.0.0").Expect().
|
||||
Status(iris.StatusOK).Body().Equal("data (v1.x)")
|
||||
Status(iris.StatusOK).Body().IsEqual("data (v1.x)")
|
||||
e.GET("/data").WithHeader(versioning.AcceptVersionHeaderKey, "2.3.0").Expect().
|
||||
Status(iris.StatusOK).Body().Equal("data (v2.x)")
|
||||
Status(iris.StatusOK).Body().IsEqual("data (v2.x)")
|
||||
e.GET("/data").WithHeader(versioning.AcceptVersionHeaderKey, "3.1.0").Expect().
|
||||
Status(iris.StatusOK).Body().Equal("data (v3.x)")
|
||||
Status(iris.StatusOK).Body().IsEqual("data (v3.x)")
|
||||
|
||||
// Test invalid version or no version at all.
|
||||
e.GET("/data").WithHeader(versioning.AcceptVersionHeaderKey, "4.0.0").Expect().
|
||||
Status(iris.StatusOK).Body().Equal("data")
|
||||
Status(iris.StatusOK).Body().IsEqual("data")
|
||||
e.GET("/data").Expect().
|
||||
Status(iris.StatusOK).Body().Equal("data")
|
||||
Status(iris.StatusOK).Body().IsEqual("data")
|
||||
|
||||
// Test Deprecated (v1)
|
||||
ex := e.GET("/data").WithHeader(versioning.AcceptVersionHeaderKey, "1.0.0").Expect()
|
||||
ex.Status(iris.StatusOK).Body().Equal("data (v1.x)")
|
||||
ex.Status(iris.StatusOK).Body().IsEqual("data (v1.x)")
|
||||
ex.Header("X-API-Warn").Equal(opts.WarnMessage)
|
||||
expectedDateStr := opts.DeprecationDate.Format(app.ConfigurationReadOnly().GetTimeFormat())
|
||||
ex.Header("X-API-Deprecation-Date").Equal(expectedDateStr)
|
||||
|
||||
@@ -20,31 +20,31 @@ func TestReadBodyAndNegotiate(t *testing.T) {
|
||||
|
||||
// Test send JSON and receive JSON.
|
||||
e.POST("/").WithJSON(expectedPayload).Expect().Status(httptest.StatusOK).
|
||||
JSON().Equal(expectedPayload)
|
||||
JSON().IsEqual(expectedPayload)
|
||||
|
||||
// Test send Form and receive XML.
|
||||
e.POST("/").WithForm(expectedPayload).
|
||||
WithHeader("Accept", "application/xml").
|
||||
Expect().Status(httptest.StatusOK).
|
||||
Body().Equal(expectedXMLPayload)
|
||||
Body().IsEqual(expectedXMLPayload)
|
||||
|
||||
// Test send URL Query and receive MessagePack.
|
||||
e.POST("/").WithQuery("message", expectedPayload.Message).
|
||||
WithHeader("Accept", "application/msgpack").
|
||||
Expect().Status(httptest.StatusOK).ContentType("application/msgpack").
|
||||
Body().Equal(expectedMsgPackPayload)
|
||||
Body().IsEqual(expectedMsgPackPayload)
|
||||
|
||||
// Test send MessagePack and receive MessagePack.
|
||||
e.POST("/").WithBytes([]byte(expectedMsgPackPayload)).
|
||||
WithHeader("Content-Type", "application/msgpack").
|
||||
WithHeader("Accept", "application/msgpack").
|
||||
Expect().Status(httptest.StatusOK).
|
||||
ContentType("application/msgpack").Body().Equal(expectedMsgPackPayload)
|
||||
ContentType("application/msgpack").Body().IsEqual(expectedMsgPackPayload)
|
||||
|
||||
// Test send YAML and receive YAML.
|
||||
e.POST("/").WithBytes([]byte(expectedYAMLPayload)).
|
||||
WithHeader("Content-Type", "application/x-yaml").
|
||||
WithHeader("Accept", "application/x-yaml").
|
||||
Expect().Status(httptest.StatusOK).
|
||||
ContentType("application/x-yaml").Body().Equal(expectedYAMLPayload)
|
||||
ContentType("application/x-yaml").Body().IsEqual(expectedYAMLPayload)
|
||||
}
|
||||
|
||||
@@ -13,5 +13,5 @@ func TestReadCustomPerType(t *testing.T) {
|
||||
expectedResponse := `Received: main.config{Addr:"localhost:8080", ServerName:"Iris"}`
|
||||
|
||||
e.POST("/").WithText("addr: localhost:8080\nserverName: Iris").Expect().
|
||||
Status(httptest.StatusOK).Body().Equal(expectedResponse)
|
||||
Status(httptest.StatusOK).Body().IsEqual(expectedResponse)
|
||||
}
|
||||
|
||||
@@ -13,5 +13,5 @@ func TestReadCustomViaUnmarshaler(t *testing.T) {
|
||||
expectedResponse := `Received: main.config{Addr:"localhost:8080", ServerName:"Iris"}`
|
||||
|
||||
e.POST("/").WithText("addr: localhost:8080\nserverName: Iris").Expect().
|
||||
Status(httptest.StatusOK).Body().Equal(expectedResponse)
|
||||
Status(httptest.StatusOK).Body().IsEqual(expectedResponse)
|
||||
}
|
||||
|
||||
@@ -12,5 +12,5 @@ func TestReadParams(t *testing.T) {
|
||||
e := httptest.New(t, app)
|
||||
|
||||
expectedBody := `myParams: main.myParams{Name:"kataras", Age:27, Tail:[]string{"iris", "web", "framework"}}`
|
||||
e.GET("/kataras/27/iris/web/framework").Expect().Status(httptest.StatusOK).Body().Equal(expectedBody)
|
||||
e.GET("/kataras/27/iris/web/framework").Expect().Status(httptest.StatusOK).Body().IsEqual(expectedBody)
|
||||
}
|
||||
|
||||
@@ -12,5 +12,5 @@ func TestReadURL(t *testing.T) {
|
||||
e := httptest.New(t, app)
|
||||
|
||||
expectedBody := `myURL: main.myURL{Name:"kataras", Age:27, Tail:[]string{"iris", "web", "framework"}}`
|
||||
e.GET("/iris/web/framework").WithQuery("name", "kataras").WithQuery("age", 27).Expect().Status(httptest.StatusOK).Body().Equal(expectedBody)
|
||||
e.GET("/iris/web/framework").WithQuery("name", "kataras").WithQuery("age", 27).Expect().Status(httptest.StatusOK).Body().IsEqual(expectedBody)
|
||||
}
|
||||
|
||||
@@ -14,5 +14,5 @@ func TestReadXML(t *testing.T) {
|
||||
send := `<person name="Winston Churchill" age="90"><description>Description of this person, the body of this inner element.</description></person>`
|
||||
|
||||
e.POST("/").WithText(send).Expect().
|
||||
Status(httptest.StatusOK).Body().Equal(expectedResponse)
|
||||
Status(httptest.StatusOK).Body().IsEqual(expectedResponse)
|
||||
}
|
||||
|
||||
@@ -20,5 +20,5 @@ comments: >
|
||||
Billsmer @ 338-4338.`
|
||||
|
||||
e.POST("/").WithHeader("Content-Type", "application/x-yaml").WithBytes([]byte(send)).Expect().
|
||||
Status(httptest.StatusOK).Body().Equal(expectedResponse)
|
||||
Status(httptest.StatusOK).Body().IsEqual(expectedResponse)
|
||||
}
|
||||
|
||||
@@ -28,33 +28,33 @@ func TestContentNegotiation(t *testing.T) {
|
||||
e.GET("/resource").WithHeader("Accept", "application/json").
|
||||
Expect().Status(httptest.StatusOK).
|
||||
ContentType("application/json", "utf-8").
|
||||
JSON().Equal(expectedJSONResponse)
|
||||
JSON().IsEqual(expectedJSONResponse)
|
||||
e.GET("/resource").WithHeader("Accept", "application/xml").WithHeader("Accept-Charset", "iso-8859-7").
|
||||
Expect().Status(httptest.StatusOK).
|
||||
ContentType("application/xml", "iso-8859-7").
|
||||
Body().Equal(string(expectedXMLResponse))
|
||||
Body().IsEqual(string(expectedXMLResponse))
|
||||
|
||||
e.GET("/resource2").WithHeader("Accept", "application/json").
|
||||
Expect().Status(httptest.StatusOK).
|
||||
ContentType("application/json", "utf-8").
|
||||
JSON().Equal(expectedJSONResponse)
|
||||
JSON().IsEqual(expectedJSONResponse)
|
||||
e.GET("/resource2").WithHeader("Accept", "application/xml").
|
||||
Expect().Status(httptest.StatusOK).
|
||||
ContentType("application/xml", "utf-8").
|
||||
Body().Equal(string(expectedXMLResponse))
|
||||
Body().IsEqual(string(expectedXMLResponse))
|
||||
e.GET("/resource2").WithHeader("Accept", "text/html").
|
||||
Expect().Status(httptest.StatusOK).
|
||||
ContentType("text/html", "utf-8").
|
||||
Body().Equal(expectedHTMLResponse)
|
||||
Body().IsEqual(expectedHTMLResponse)
|
||||
|
||||
e.GET("/resource3").WithHeader("Accept", "application/json").
|
||||
Expect().Status(httptest.StatusOK).
|
||||
ContentType("application/json", "utf-8").
|
||||
JSON().Equal(expectedJSONResponse)
|
||||
JSON().IsEqual(expectedJSONResponse)
|
||||
e.GET("/resource3").WithHeader("Accept", "application/xml").
|
||||
Expect().Status(httptest.StatusOK).
|
||||
ContentType("application/xml", "utf-8").
|
||||
Body().Equal(string(expectedXMLResponse))
|
||||
Body().IsEqual(string(expectedXMLResponse))
|
||||
|
||||
// test html with "gzip" encoding algorithm.
|
||||
rawGzipResponse := e.GET("/resource3").WithHeader("Accept", "text/html").
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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>")
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -52,6 +52,6 @@ func TestSubdomainWWW(t *testing.T) {
|
||||
|
||||
req.Expect().
|
||||
Status(httptest.StatusOK).
|
||||
Body().Equal(test.response())
|
||||
Body().IsEqual(test.response())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.")
|
||||
}
|
||||
|
||||
@@ -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!")
|
||||
}
|
||||
|
||||
@@ -14,14 +14,14 @@ func TestSessionsEncodeDecode(t *testing.T) {
|
||||
es := e.GET("/set").Expect()
|
||||
es.Status(iris.StatusOK)
|
||||
es.Cookies().NotEmpty()
|
||||
es.Body().Equal("All ok session set to: iris [isNew=true]")
|
||||
es.Body().IsEqual("All ok session set to: iris [isNew=true]")
|
||||
|
||||
e.GET("/get").Expect().Status(iris.StatusOK).Body().Equal("The username on the /set was: iris")
|
||||
e.GET("/get").Expect().Status(iris.StatusOK).Body().IsEqual("The username on the /set was: iris")
|
||||
// delete and re-get
|
||||
e.GET("/delete").Expect().Status(iris.StatusOK)
|
||||
e.GET("/get").Expect().Status(iris.StatusOK).Body().Equal("The username on the /set was: ")
|
||||
e.GET("/get").Expect().Status(iris.StatusOK).Body().IsEqual("The username on the /set was: ")
|
||||
// set, clear and re-get
|
||||
e.GET("/set").Expect().Body().Equal("All ok session set to: iris [isNew=false]")
|
||||
e.GET("/set").Expect().Body().IsEqual("All ok session set to: iris [isNew=false]")
|
||||
e.GET("/clear").Expect().Status(iris.StatusOK)
|
||||
e.GET("/get").Expect().Status(iris.StatusOK).Body().Equal("The username on the /set was: ")
|
||||
e.GET("/get").Expect().Status(iris.StatusOK).Body().IsEqual("The username on the /set was: ")
|
||||
}
|
||||
|
||||
@@ -19,11 +19,11 @@ func TestNewApp(t *testing.T) {
|
||||
|
||||
// with valid basic auth
|
||||
e.GET("/admin").WithBasicAuth("myusername", "mypassword").Expect().
|
||||
Status(httptest.StatusOK).Body().Equal("/admin myusername:mypassword")
|
||||
Status(httptest.StatusOK).Body().IsEqual("/admin myusername:mypassword")
|
||||
e.GET("/admin/profile").WithBasicAuth("myusername", "mypassword").Expect().
|
||||
Status(httptest.StatusOK).Body().Equal("/admin/profile myusername:mypassword")
|
||||
Status(httptest.StatusOK).Body().IsEqual("/admin/profile myusername:mypassword")
|
||||
e.GET("/admin/settings").WithBasicAuth("myusername", "mypassword").Expect().
|
||||
Status(httptest.StatusOK).Body().Equal("/admin/settings myusername:mypassword")
|
||||
Status(httptest.StatusOK).Body().IsEqual("/admin/settings myusername:mypassword")
|
||||
|
||||
// with invalid basic auth
|
||||
e.GET("/admin/settings").WithBasicAuth("invalidusername", "invalidpassword").
|
||||
|
||||
@@ -42,6 +42,6 @@ func TestResponseWriterQuicktemplate(t *testing.T) {
|
||||
|
||||
e := httptest.New(t, app)
|
||||
|
||||
e.GET("/").Expect().Status(httptest.StatusOK).Body().Equal(expectedIndexRawBody)
|
||||
e.GET("/" + name).Expect().Status(httptest.StatusOK).Body().Equal(expectedHelloRawBody)
|
||||
e.GET("/").Expect().Status(httptest.StatusOK).Body().IsEqual(expectedIndexRawBody)
|
||||
e.GET("/" + name).Expect().Status(httptest.StatusOK).Body().IsEqual(expectedHelloRawBody)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user