mirror of
https://github.com/kataras/iris.git
synced 2025-01-22 18:21:03 +01:00
fix #2158 and more
This commit is contained in:
parent
757e7fe61b
commit
6add1ba49b
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -108,7 +108,7 @@ func TestSwitchHosts(t *testing.T) {
|
|||
body = "Switcher: Bad Gateway"
|
||||
}
|
||||
|
||||
e.GET(requestPath).WithURL(URL).Expect().Status(statusCode).Body().Equal(body)
|
||||
e.GET(requestPath).WithURL(URL).Expect().Status(statusCode).Body().IsEqual(body)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -204,7 +204,7 @@ func TestSwitchHostsRedirect(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
e.GET(requestPath).WithURL(requestURL).Expect().Status(statusCode).Body().Equal(body)
|
||||
e.GET(requestPath).WithURL(requestURL).Expect().Status(statusCode).Body().IsEqual(body)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,6 +33,6 @@ func TestSetHost(t *testing.T) {
|
|||
for _, tt := range tests {
|
||||
ex := tt.Expect().Status(iris.StatusOK)
|
||||
ex.Header("Server").Equal(rootApp.String())
|
||||
ex.Body().Equal(forceHost)
|
||||
ex.Body().IsEqual(forceHost)
|
||||
}
|
||||
}
|
||||
|
|
16
cache/browser_test.go
vendored
16
cache/browser_test.go
vendored
|
@ -22,7 +22,7 @@ func TestNoCache(t *testing.T) {
|
|||
e := httptest.New(t, app)
|
||||
|
||||
r := e.GET("/").Expect().Status(httptest.StatusOK)
|
||||
r.Body().Equal("no_cache")
|
||||
r.Body().IsEqual("no_cache")
|
||||
r.Header(context.CacheControlHeaderKey).Equal(cache.CacheControlHeaderValue)
|
||||
r.Header(cache.PragmaHeaderKey).Equal(cache.PragmaNoCacheHeaderValue)
|
||||
r.Header(cache.ExpiresHeaderKey).Equal(cache.ExpiresNeverHeaderValue)
|
||||
|
@ -42,7 +42,7 @@ func TestStaticCache(t *testing.T) {
|
|||
// tests
|
||||
e := httptest.New(t, app)
|
||||
r := e.GET("/").Expect().Status(httptest.StatusOK)
|
||||
r.Body().Equal("static_cache")
|
||||
r.Body().IsEqual("static_cache")
|
||||
|
||||
r.Header(cache.ExpiresHeaderKey).Equal(expectedTime.Add(cacheDur).Format(app.ConfigurationReadOnly().GetTimeFormat()))
|
||||
cacheControlHeaderValue := "public, max-age=" + strconv.Itoa(int(cacheDur.Seconds()))
|
||||
|
@ -64,15 +64,15 @@ func TestCache304(t *testing.T) {
|
|||
insideCacheTimef := time.Now().Add(-expiresEvery).UTC().Format(app.ConfigurationReadOnly().GetTimeFormat())
|
||||
r := e.GET("/").WithHeader(context.IfModifiedSinceHeaderKey, insideCacheTimef).Expect().Status(httptest.StatusNotModified)
|
||||
r.Headers().NotContainsKey(context.ContentTypeHeaderKey).NotContainsKey(context.ContentLengthHeaderKey).NotContainsKey("ETag")
|
||||
r.Body().Equal("")
|
||||
r.Body().IsEqual("")
|
||||
|
||||
// continue to the handler itself.
|
||||
cacheInvalidatedTimef := time.Now().Add(expiresEvery).UTC().Format(app.ConfigurationReadOnly().GetTimeFormat()) // after ~5seconds.
|
||||
r = e.GET("/").WithHeader(context.LastModifiedHeaderKey, cacheInvalidatedTimef).Expect().Status(httptest.StatusOK)
|
||||
r.Body().Equal("send")
|
||||
r.Body().IsEqual("send")
|
||||
// now without header, it should continue to the handler itself as well.
|
||||
r = e.GET("/").Expect().Status(httptest.StatusOK)
|
||||
r.Body().Equal("send")
|
||||
r.Body().IsEqual("send")
|
||||
}
|
||||
|
||||
func TestETag(t *testing.T) {
|
||||
|
@ -91,12 +91,12 @@ func TestETag(t *testing.T) {
|
|||
|
||||
r := e.GET("/").Expect().Status(httptest.StatusOK)
|
||||
r.Header("ETag").Equal("/") // test if header set.
|
||||
r.Body().Equal("_")
|
||||
r.Body().IsEqual("_")
|
||||
|
||||
e.GET("/").WithHeader("ETag", "/").WithHeader("If-None-Match", "/").Expect().
|
||||
Status(httptest.StatusNotModified).Body().Equal("") // browser is responsible, no the test engine.
|
||||
Status(httptest.StatusNotModified).Body().IsEqual("") // browser is responsible, no the test engine.
|
||||
|
||||
r = e.GET("/").Expect().Status(httptest.StatusOK)
|
||||
r.Header("ETag").Equal("/") // test if header set.
|
||||
r.Body().Equal("__")
|
||||
r.Body().IsEqual("__")
|
||||
}
|
||||
|
|
26
cache/cache_test.go
vendored
26
cache/cache_test.go
vendored
|
@ -33,9 +33,9 @@ func (h *testError) Error() string {
|
|||
}
|
||||
|
||||
func runTest(e *httpexpect.Expect, path string, counterPtr *uint32, expectedBodyStr string, nocache string) error {
|
||||
e.GET(path).Expect().Status(http.StatusOK).Body().Equal(expectedBodyStr)
|
||||
e.GET(path).Expect().Status(http.StatusOK).Body().IsEqual(expectedBodyStr)
|
||||
time.Sleep(cacheDuration / 5) // lets wait for a while, cache should be saved and ready
|
||||
e.GET(path).Expect().Status(http.StatusOK).Body().Equal(expectedBodyStr)
|
||||
e.GET(path).Expect().Status(http.StatusOK).Body().IsEqual(expectedBodyStr)
|
||||
counter := atomic.LoadUint32(counterPtr)
|
||||
if counter > 1 {
|
||||
// n should be 1 because it doesn't changed after the first call
|
||||
|
@ -44,10 +44,10 @@ func runTest(e *httpexpect.Expect, path string, counterPtr *uint32, expectedBody
|
|||
time.Sleep(cacheDuration)
|
||||
|
||||
// cache should be cleared now
|
||||
e.GET(path).Expect().Status(http.StatusOK).Body().Equal(expectedBodyStr)
|
||||
e.GET(path).Expect().Status(http.StatusOK).Body().IsEqual(expectedBodyStr)
|
||||
time.Sleep(cacheDuration / 5)
|
||||
// let's call again , the cache should be saved
|
||||
e.GET(path).Expect().Status(http.StatusOK).Body().Equal(expectedBodyStr)
|
||||
e.GET(path).Expect().Status(http.StatusOK).Body().IsEqual(expectedBodyStr)
|
||||
counter = atomic.LoadUint32(counterPtr)
|
||||
if counter != 2 {
|
||||
return &testError{2, counter}
|
||||
|
@ -55,8 +55,8 @@ func runTest(e *httpexpect.Expect, path string, counterPtr *uint32, expectedBody
|
|||
|
||||
// we have cache response saved for the path, we have some time more here, but here
|
||||
// we will make the requestS with some of the deniers options
|
||||
e.GET(path).WithHeader("max-age", "0").Expect().Status(http.StatusOK).Body().Equal(expectedBodyStr)
|
||||
e.GET(path).WithHeader("Authorization", "basic or anything").Expect().Status(http.StatusOK).Body().Equal(expectedBodyStr)
|
||||
e.GET(path).WithHeader("max-age", "0").Expect().Status(http.StatusOK).Body().IsEqual(expectedBodyStr)
|
||||
e.GET(path).WithHeader("Authorization", "basic or anything").Expect().Status(http.StatusOK).Body().IsEqual(expectedBodyStr)
|
||||
counter = atomic.LoadUint32(counterPtr)
|
||||
if counter != 4 {
|
||||
return &testError{4, counter}
|
||||
|
@ -69,19 +69,19 @@ func runTest(e *httpexpect.Expect, path string, counterPtr *uint32, expectedBody
|
|||
time.Sleep(cacheDuration)
|
||||
|
||||
// cache should be cleared now, this should work because we are not in the "nocache" path
|
||||
e.GET("/").Expect().Status(http.StatusOK).Body().Equal(expectedBodyStr) // counter = 5
|
||||
e.GET("/").Expect().Status(http.StatusOK).Body().IsEqual(expectedBodyStr) // counter = 5
|
||||
time.Sleep(cacheDuration / 5)
|
||||
|
||||
// let's call the "nocache", the expiration is not passed so but the "nocache"
|
||||
// route's path has the cache.NoCache so it should be not cached and the counter should be ++
|
||||
e.GET(nocache).Expect().Status(http.StatusOK).Body().Equal(expectedBodyStr) // counter should be 6
|
||||
e.GET(nocache).Expect().Status(http.StatusOK).Body().IsEqual(expectedBodyStr) // counter should be 6
|
||||
counter = atomic.LoadUint32(counterPtr)
|
||||
if counter != 6 { // 4 before, 5 with the first call to store the cache, and six with the no cache, again original handler executation
|
||||
return &testError{6, counter}
|
||||
}
|
||||
|
||||
// let's call again the path the expiration is not passed so it should be cached
|
||||
e.GET(path).Expect().Status(http.StatusOK).Body().Equal(expectedBodyStr)
|
||||
e.GET(path).Expect().Status(http.StatusOK).Body().IsEqual(expectedBodyStr)
|
||||
counter = atomic.LoadUint32(counterPtr)
|
||||
if counter != 6 {
|
||||
return &testError{6, counter}
|
||||
|
@ -195,17 +195,17 @@ func TestCacheValidator(t *testing.T) {
|
|||
e := httptest.New(t, app)
|
||||
|
||||
// execute from cache the next time
|
||||
e.GET("/valid").Expect().Status(http.StatusOK).Body().Equal(expectedBodyStr)
|
||||
e.GET("/valid").Expect().Status(http.StatusOK).Body().IsEqual(expectedBodyStr)
|
||||
time.Sleep(cacheDuration / 5) // lets wait for a while, cache should be saved and ready
|
||||
e.GET("/valid").Expect().Status(http.StatusOK).Body().Equal(expectedBodyStr)
|
||||
e.GET("/valid").Expect().Status(http.StatusOK).Body().IsEqual(expectedBodyStr)
|
||||
counter := atomic.LoadUint32(&n)
|
||||
if counter > 1 {
|
||||
// n should be 1 because it doesn't changed after the first call
|
||||
t.Fatalf("%s: %v", t.Name(), &testError{1, counter})
|
||||
}
|
||||
// don't execute from cache, execute the original, counter should ++ here
|
||||
e.GET("/invalid").Expect().Status(http.StatusOK).Body().Equal(expectedBodyStr) // counter = 2
|
||||
e.GET("/invalid2").Expect().Status(http.StatusOK).Body().Equal(expectedBodyStr) // counter = 3
|
||||
e.GET("/invalid").Expect().Status(http.StatusOK).Body().IsEqual(expectedBodyStr) // counter = 2
|
||||
e.GET("/invalid2").Expect().Status(http.StatusOK).Body().IsEqual(expectedBodyStr) // counter = 3
|
||||
|
||||
counter = atomic.LoadUint32(&n)
|
||||
if counter != 3 {
|
||||
|
|
|
@ -32,10 +32,10 @@ func TestFromStd(t *testing.T) {
|
|||
e := httptest.New(t, app)
|
||||
|
||||
e.GET("/handler").
|
||||
Expect().Status(iris.StatusOK).Body().Equal(expected)
|
||||
Expect().Status(iris.StatusOK).Body().IsEqual(expected)
|
||||
|
||||
e.GET("/func").
|
||||
Expect().Status(iris.StatusOK).Body().Equal(expected)
|
||||
Expect().Status(iris.StatusOK).Body().IsEqual(expected)
|
||||
}
|
||||
|
||||
func TestFromStdWithNext(t *testing.T) {
|
||||
|
@ -67,5 +67,5 @@ func TestFromStdWithNext(t *testing.T) {
|
|||
Expect().Status(iris.StatusForbidden)
|
||||
|
||||
e.GET("/handlerwithnext").WithBasicAuth(basicauth, basicauth).
|
||||
Expect().Status(iris.StatusOK).Body().Equal(passed)
|
||||
Expect().Status(iris.StatusOK).Body().IsEqual(passed)
|
||||
}
|
||||
|
|
|
@ -68,7 +68,7 @@ func TestProxy(t *testing.T) {
|
|||
go app.Run(iris.Listener(httptest.NewLocalTLSListener(l)), iris.WithoutStartupLog) // nolint:errcheck
|
||||
|
||||
e := httptest.NewInsecure(t, httptest.URL("http://"+listener.Addr().String()))
|
||||
e.GET("/").Expect().Status(iris.StatusOK).Body().Equal(expectedIndex)
|
||||
e.GET("/about").Expect().Status(iris.StatusOK).Body().Equal(expectedAbout)
|
||||
e.GET("/notfound").Expect().Status(iris.StatusNotFound).Body().Equal(unexpectedRoute)
|
||||
e.GET("/").Expect().Status(iris.StatusOK).Body().IsEqual(expectedIndex)
|
||||
e.GET("/about").Expect().Status(iris.StatusOK).Body().IsEqual(expectedAbout)
|
||||
e.GET("/notfound").Expect().Status(iris.StatusNotFound).Body().IsEqual(unexpectedRoute)
|
||||
}
|
||||
|
|
|
@ -93,7 +93,7 @@ func testSupervisor(t *testing.T, creator func(*http.Server, []func(TaskHost)) *
|
|||
// http testsing and various calls
|
||||
// no need for time sleep because the following will take some time by theirselves
|
||||
tester := newTester(t, "http://"+addr, mux)
|
||||
tester.Request("GET", "/").Expect().Status(http.StatusOK).Body().Equal(expectedBody)
|
||||
tester.Request("GET", "/").Expect().Status(http.StatusOK).Body().IsEqual(expectedBody)
|
||||
|
||||
// WARNING: Data Race here because we try to read the logs
|
||||
// but it's "safe" here.
|
||||
|
|
|
@ -6,9 +6,7 @@ import (
|
|||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
@ -722,7 +720,7 @@ func (api *APIBuilder) createRoutes(errorCode int, methods []string, relativePat
|
|||
}
|
||||
}
|
||||
|
||||
filename, line := getCaller()
|
||||
filename, line := hero.GetCaller()
|
||||
|
||||
fullpath := api.relativePath + relativePath // for now, keep the last "/" if any, "/xyz/"
|
||||
if len(handlers) == 0 {
|
||||
|
@ -1706,50 +1704,3 @@ func (api *APIBuilder) Layout(tmplLayoutFile string) Party {
|
|||
|
||||
return api
|
||||
}
|
||||
|
||||
// https://golang.org/doc/go1.9#callersframes
|
||||
func getCaller() (string, int) {
|
||||
var pcs [32]uintptr
|
||||
n := runtime.Callers(1, pcs[:])
|
||||
frames := runtime.CallersFrames(pcs[:n])
|
||||
wd, _ := os.Getwd()
|
||||
|
||||
var (
|
||||
frame runtime.Frame
|
||||
more = true
|
||||
)
|
||||
|
||||
for {
|
||||
if !more {
|
||||
break
|
||||
}
|
||||
|
||||
frame, more = frames.Next()
|
||||
file := filepath.ToSlash(frame.File)
|
||||
// fmt.Printf("%s:%d | %s\n", file, frame.Line, frame.Function)
|
||||
|
||||
if strings.Contains(file, "go/src/runtime/") {
|
||||
continue
|
||||
}
|
||||
|
||||
if !strings.Contains(file, "_test.go") {
|
||||
if strings.Contains(file, "/kataras/iris") &&
|
||||
!strings.Contains(file, "kataras/iris/_examples") &&
|
||||
!strings.Contains(file, "kataras/iris/middleware") &&
|
||||
!strings.Contains(file, "iris-contrib/examples") {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if relFile, err := filepath.Rel(wd, file); err == nil {
|
||||
if !strings.HasPrefix(relFile, "..") {
|
||||
// Only if it's relative to this path, not parent.
|
||||
file = "./" + filepath.ToSlash(relFile)
|
||||
}
|
||||
}
|
||||
|
||||
return file, frame.Line
|
||||
}
|
||||
|
||||
return "???", 0
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ func genPaths(routesLength, minCharLength, maxCharLength int) []string {
|
|||
//
|
||||
// GOCACHE=off && go test -run=XXX -bench=BenchmarkAPIBuilder$ -benchtime=10s
|
||||
func BenchmarkAPIBuilder(b *testing.B) {
|
||||
rand.Seed(time.Now().Unix())
|
||||
rand.New(rand.NewSource(time.Now().Unix()))
|
||||
|
||||
noOpHandler := func(ctx *context.Context) {}
|
||||
handlersPerRoute := make(context.Handlers, 12)
|
||||
|
|
|
@ -14,7 +14,7 @@ var (
|
|||
|
||||
testExecutionResponse = func(t *testing.T, app *iris.Application, path string) {
|
||||
e := httptest.New(t, app)
|
||||
e.GET(path).Expect().Status(httptest.StatusOK).Body().Equal(finalExecutionRulesResponse)
|
||||
e.GET(path).Expect().Status(httptest.StatusOK).Body().IsEqual(finalExecutionRulesResponse)
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -87,5 +87,5 @@ func TestRouterExecutionRulesShouldNotModifyTheCallersHandlerAndChildrenCanReset
|
|||
testExecutionResponse(t, app, "/")
|
||||
|
||||
e := httptest.New(t, app)
|
||||
e.GET("/c").Expect().Status(httptest.StatusOK).Body().Equal("4") // the "should not" should not be written.
|
||||
e.GET("/c").Expect().Status(httptest.StatusOK).Body().IsEqual("4") // the "should not" should not be written.
|
||||
}
|
||||
|
|
|
@ -57,9 +57,9 @@ func testRegisterRule(e *httptest.Expect, expectedGetBody string) {
|
|||
for _, method := range router.AllMethods {
|
||||
tt := e.Request(method, "/v1").Expect().Status(httptest.StatusOK).Body()
|
||||
if method == iris.MethodGet {
|
||||
tt.Equal(expectedGetBody)
|
||||
tt.IsEqual(expectedGetBody)
|
||||
} else {
|
||||
tt.Equal("[any] " + method)
|
||||
tt.IsEqual("[any] " + method)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -111,8 +111,8 @@ func TestRegisterRuleOverlap(t *testing.T) {
|
|||
|
||||
e := httptest.New(t, app)
|
||||
|
||||
e.GET("/users").Expect().Status(httptest.StatusOK).Body().Equal("data")
|
||||
e.GET("/users/p1").Expect().Status(httptest.StatusUnauthorized).Body().Equal("Unauthorized")
|
||||
e.GET("/users/p2").Expect().Status(httptest.StatusUnauthorized).Body().Equal("no access")
|
||||
e.GET("/users/p3").Expect().Status(httptest.StatusOK).Body().Equal("p3 data")
|
||||
e.GET("/users").Expect().Status(httptest.StatusOK).Body().IsEqual("data")
|
||||
e.GET("/users/p1").Expect().Status(httptest.StatusUnauthorized).Body().IsEqual("Unauthorized")
|
||||
e.GET("/users/p2").Expect().Status(httptest.StatusUnauthorized).Body().IsEqual("no access")
|
||||
e.GET("/users/p3").Expect().Status(httptest.StatusOK).Body().IsEqual("p3 data")
|
||||
}
|
||||
|
|
|
@ -68,7 +68,7 @@ var (
|
|||
t.Helper()
|
||||
|
||||
e := httptest.New(t, app)
|
||||
e.GET(path).Expect().Status(httptest.StatusOK).Body().Equal(finalResponse)
|
||||
e.GET(path).Expect().Status(httptest.StatusOK).Body().IsEqual(finalResponse)
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -169,7 +169,7 @@ func TestUseRouterStopExecution(t *testing.T) {
|
|||
app.Get("/", writeHandler("index"))
|
||||
|
||||
e := httptest.New(t, app)
|
||||
e.GET("/").Expect().Status(iris.StatusOK).Body().Equal("stop")
|
||||
e.GET("/").Expect().Status(iris.StatusOK).Body().IsEqual("stop")
|
||||
|
||||
app = iris.New()
|
||||
app.OnErrorCode(iris.StatusForbidden, func(ctx iris.Context) {
|
||||
|
@ -183,7 +183,7 @@ func TestUseRouterStopExecution(t *testing.T) {
|
|||
app.Get("/", writeHandler("index"))
|
||||
|
||||
e = httptest.New(t, app)
|
||||
e.GET("/").Expect().Status(iris.StatusForbidden).Body().Equal("err: custom error")
|
||||
e.GET("/").Expect().Status(iris.StatusForbidden).Body().IsEqual("err: custom error")
|
||||
}
|
||||
|
||||
func TestUseRouterParentDisallow(t *testing.T) {
|
||||
|
@ -226,9 +226,9 @@ func TestUseRouterParentDisallow(t *testing.T) {
|
|||
})
|
||||
|
||||
e := httptest.New(t, app)
|
||||
e.GET("/index").Expect().Status(iris.StatusOK).Body().Equal(expectedResponse)
|
||||
e.GET("/").Expect().Status(iris.StatusOK).Body().Equal(expectedResponse)
|
||||
e.GET("/user").Expect().Status(iris.StatusOK).Body().Equal(expectedResponse)
|
||||
e.GET("/index").Expect().Status(iris.StatusOK).Body().IsEqual(expectedResponse)
|
||||
e.GET("/").Expect().Status(iris.StatusOK).Body().IsEqual(expectedResponse)
|
||||
e.GET("/user").Expect().Status(iris.StatusOK).Body().IsEqual(expectedResponse)
|
||||
}
|
||||
|
||||
func TestUseRouterSubdomains(t *testing.T) {
|
||||
|
@ -270,21 +270,21 @@ func TestUseRouterSubdomains(t *testing.T) {
|
|||
})
|
||||
|
||||
e := httptest.New(t, app, httptest.URL("http://example.com"))
|
||||
e.GET("/notfound").Expect().Status(iris.StatusOK).Body().Equal("always_")
|
||||
e.GET("/notfound").Expect().Status(iris.StatusOK).Body().IsEqual("always_")
|
||||
|
||||
e.GET("/").WithURL("http://admin.example.com").Expect().Status(iris.StatusOK).Body().
|
||||
Equal("always_admin always_admin")
|
||||
IsEqual("always_admin always_admin")
|
||||
|
||||
e.GET("/").WithURL("http://control.admin.example.com").Expect().Status(iris.StatusOK).Body().
|
||||
Equal("always_admin always_control admin always_control admin")
|
||||
IsEqual("always_admin always_control admin always_control admin")
|
||||
|
||||
// It has a route, and use router just proceeds to the router.
|
||||
e.GET("/").WithURL("http://old.example.com").Expect().Status(iris.StatusOK).Body().
|
||||
Equal("chat")
|
||||
IsEqual("chat")
|
||||
// this is not a registered path, should fire 404, the UseRouter does not write
|
||||
// anything to the response writer, so the router has control over it.
|
||||
e.GET("/notfound").WithURL("http://old.example.com").Expect().Status(iris.StatusNotFound).Body().
|
||||
Equal("Not Found")
|
||||
IsEqual("Not Found")
|
||||
}
|
||||
|
||||
func TestUseWrapOrder(t *testing.T) {
|
||||
|
@ -359,8 +359,8 @@ func TestUseWrapOrder(t *testing.T) {
|
|||
app.Get("/", handler)
|
||||
|
||||
e := httptest.New(t, app)
|
||||
e.GET("/NotFound").Expect().Status(iris.StatusNotFound).Body().Equal(expectedNotFoundBody)
|
||||
e.GET("/").Expect().Status(iris.StatusOK).Body().Equal(expectedBody)
|
||||
e.GET("/NotFound").Expect().Status(iris.StatusNotFound).Body().IsEqual(expectedNotFoundBody)
|
||||
e.GET("/").Expect().Status(iris.StatusOK).Body().IsEqual(expectedBody)
|
||||
}
|
||||
|
||||
func TestResumeExecution(t *testing.T) {
|
||||
|
@ -414,5 +414,5 @@ func TestResumeExecution(t *testing.T) {
|
|||
app.Get("/", before, handler, after)
|
||||
|
||||
e := httptest.New(t, app)
|
||||
e.GET("/").Expect().Status(iris.StatusOK).Body().Equal(expectedBody)
|
||||
e.GET("/").Expect().Status(iris.StatusOK).Body().IsEqual(expectedBody)
|
||||
}
|
||||
|
|
|
@ -69,9 +69,9 @@ func TestLowercaseRouting(t *testing.T) {
|
|||
e := httptest.New(t, app)
|
||||
for _, tt := range tests {
|
||||
s := strings.ToLower(tt)
|
||||
e.GET(tt).Expect().Status(httptest.StatusOK).Body().Equal(s)
|
||||
e.GET(s).Expect().Status(httptest.StatusOK).Body().Equal(s)
|
||||
e.GET(strings.ToUpper(tt)).Expect().Status(httptest.StatusOK).Body().Equal(s)
|
||||
e.GET(tt).Expect().Status(httptest.StatusOK).Body().IsEqual(s)
|
||||
e.GET(s).Expect().Status(httptest.StatusOK).Body().IsEqual(s)
|
||||
e.GET(strings.ToUpper(tt)).Expect().Status(httptest.StatusOK).Body().IsEqual(s)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -156,7 +156,7 @@ func TestRouterWrapperOrder(t *testing.T) {
|
|||
app.Get("/", func(ctx iris.Context) {}) // to not append the not found one.
|
||||
|
||||
e := httptest.New(t, app)
|
||||
e.GET("/").Expect().Status(iris.StatusOK).Body().Equal(expectedOrderStr)
|
||||
e.GET("/").Expect().Status(iris.StatusOK).Body().IsEqual(expectedOrderStr)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -190,9 +190,9 @@ func TestNewSubdomainPartyRedirectHandler(t *testing.T) {
|
|||
}
|
||||
|
||||
e := httptest.New(t, app)
|
||||
e.GET("/").WithURL("http://mydomain.com").Expect().Status(iris.StatusOK).Body().Equal("root index")
|
||||
e.GET("/").WithURL("http://test.mydomain.com").Expect().Status(iris.StatusOK).Body().Equal("test index")
|
||||
e.GET("/").WithURL("http://testold.mydomain.com").Expect().Status(iris.StatusOK).Body().Equal("test index")
|
||||
e.GET("/").WithURL("http://testold.mydomain.com/notfound").Expect().Status(iris.StatusNotFound).Body().Equal("test 404")
|
||||
e.GET("/").WithURL("http://leveled.testold.mydomain.com").Expect().Status(iris.StatusOK).Body().Equal("leveled.testold this can be fired")
|
||||
e.GET("/").WithURL("http://mydomain.com").Expect().Status(iris.StatusOK).Body().IsEqual("root index")
|
||||
e.GET("/").WithURL("http://test.mydomain.com").Expect().Status(iris.StatusOK).Body().IsEqual("test index")
|
||||
e.GET("/").WithURL("http://testold.mydomain.com").Expect().Status(iris.StatusOK).Body().IsEqual("test index")
|
||||
e.GET("/").WithURL("http://testold.mydomain.com/notfound").Expect().Status(iris.StatusNotFound).Body().IsEqual("test 404")
|
||||
e.GET("/").WithURL("http://leveled.testold.mydomain.com").Expect().Status(iris.StatusOK).Body().IsEqual("leveled.testold this can be fired")
|
||||
}
|
||||
|
|
|
@ -192,7 +192,7 @@ func testTheRoutes(t *testing.T, tests []testRoute, debug bool) {
|
|||
expectedBody = staticPathPrefixBody + req.path
|
||||
}
|
||||
|
||||
ex.Expect().Status(req.expectedStatusCode).Body().Equal(expectedBody)
|
||||
ex.Expect().Status(req.expectedStatusCode).Body().IsEqual(expectedBody)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,20 +45,20 @@ func TestOnAnyErrorCode(t *testing.T) {
|
|||
e := httptest.New(t, app)
|
||||
|
||||
e.GET("/found").Expect().Status(iris.StatusOK).
|
||||
Body().Equal(expectedFoundResponse)
|
||||
Body().IsEqual(expectedFoundResponse)
|
||||
|
||||
e.GET("/notfound").Expect().Status(iris.StatusNotFound).
|
||||
Body().Equal(http.StatusText(iris.StatusNotFound))
|
||||
Body().IsEqual(http.StatusText(iris.StatusNotFound))
|
||||
|
||||
checkAndClearBuf(t, buff, expectedPrintBeforeExecuteErr)
|
||||
|
||||
e.POST("/found").Expect().Status(iris.StatusMethodNotAllowed).
|
||||
Body().Equal(http.StatusText(iris.StatusMethodNotAllowed))
|
||||
Body().IsEqual(http.StatusText(iris.StatusMethodNotAllowed))
|
||||
|
||||
checkAndClearBuf(t, buff, expectedPrintBeforeExecuteErr)
|
||||
|
||||
e.GET("/407").Expect().Status(iris.StatusProxyAuthRequired).
|
||||
Body().Equal(expected407)
|
||||
Body().IsEqual(expected407)
|
||||
|
||||
// Test Configuration.ResetOnFireErrorCode.
|
||||
app2 := iris.New()
|
||||
|
@ -77,7 +77,7 @@ func TestOnAnyErrorCode(t *testing.T) {
|
|||
})
|
||||
|
||||
httptest.New(t, app2).GET("/406").Expect().Status(iris.StatusNotAcceptable).
|
||||
Body().Equal(http.StatusText(iris.StatusNotAcceptable))
|
||||
Body().IsEqual(http.StatusText(iris.StatusNotAcceptable))
|
||||
|
||||
checkAndClearBuf(t, buff, expectedPrintBeforeExecuteErr)
|
||||
}
|
||||
|
@ -135,26 +135,26 @@ func TestPartyOnErrorCode(t *testing.T) {
|
|||
|
||||
e := httptest.New(t, app)
|
||||
|
||||
e.GET("/notfound").Expect().Status(iris.StatusNotFound).Body().Equal(globalNotFoundResponse)
|
||||
e.POST("/path").Expect().Status(iris.StatusMethodNotAllowed).Body().Equal(globalMethodNotAllowedResponse)
|
||||
e.GET("/path").Expect().Status(iris.StatusOK).Body().Equal("/path")
|
||||
e.GET("/notfound").Expect().Status(iris.StatusNotFound).Body().IsEqual(globalNotFoundResponse)
|
||||
e.POST("/path").Expect().Status(iris.StatusMethodNotAllowed).Body().IsEqual(globalMethodNotAllowedResponse)
|
||||
e.GET("/path").Expect().Status(iris.StatusOK).Body().IsEqual("/path")
|
||||
|
||||
e.POST("/users").Expect().Status(iris.StatusMethodNotAllowed).
|
||||
Body().Equal(usersResponse)
|
||||
Body().IsEqual(usersResponse)
|
||||
|
||||
e.POST("/users/42").Expect().Status(iris.StatusMethodNotAllowed).
|
||||
Body().Equal(usersuserResponse)
|
||||
Body().IsEqual(usersuserResponse)
|
||||
|
||||
e.GET("/users/42").Expect().Status(iris.StatusOK).
|
||||
Body().Equal("/users/42")
|
||||
e.GET("/users/ab").Expect().Status(iris.StatusNotFound).Body().Equal(usersuserNotFoundResponse)
|
||||
Body().IsEqual("/users/42")
|
||||
e.GET("/users/ab").Expect().Status(iris.StatusNotFound).Body().IsEqual(usersuserNotFoundResponse)
|
||||
// inherit the parent.
|
||||
e.GET("/users/42/friends/dsa").Expect().Status(iris.StatusNotFound).Body().Equal(usersuserNotFoundResponse)
|
||||
e.GET("/users/42/friends/dsa").Expect().Status(iris.StatusNotFound).Body().IsEqual(usersuserNotFoundResponse)
|
||||
|
||||
// if not registered to the party, then the root is taking action.
|
||||
e.GET("/users/42/ab/badrequest").Expect().Status(iris.StatusBadRequest).Body().Equal(http.StatusText(iris.StatusBadRequest))
|
||||
e.GET("/users/42/ab/badrequest").Expect().Status(iris.StatusBadRequest).Body().IsEqual(http.StatusText(iris.StatusBadRequest))
|
||||
|
||||
// if not registered to the party, and not in root, then just write the status text (fallback behavior)
|
||||
e.GET("/users/badrequest").Expect().Status(iris.StatusBadRequest).
|
||||
Body().Equal(http.StatusText(iris.StatusBadRequest))
|
||||
Body().IsEqual(http.StatusText(iris.StatusBadRequest))
|
||||
}
|
||||
|
|
|
@ -253,7 +253,7 @@ func isPayloadType(in reflect.Type) bool {
|
|||
func getBindingsForFunc(fn reflect.Value, dependencies []*Dependency, disablePayloadAutoBinding bool, paramsCount int) []*binding {
|
||||
fnTyp := fn.Type()
|
||||
if !isFunc(fnTyp) {
|
||||
panic("bindings: unresolved: not a func type")
|
||||
panic(fmt.Sprintf("bindings: unresolved: no a func type: %#+v", fn))
|
||||
}
|
||||
|
||||
n := fnTyp.NumIn()
|
||||
|
@ -294,7 +294,7 @@ func getBindingsForFunc(fn reflect.Value, dependencies []*Dependency, disablePay
|
|||
func getBindingsForStruct(v reflect.Value, dependencies []*Dependency, markExportedFieldsAsRequired bool, disablePayloadAutoBinding bool, matchDependency DependencyMatcher, paramsCount int, sorter Sorter) (bindings []*binding) {
|
||||
typ := indirectType(v.Type())
|
||||
if typ.Kind() != reflect.Struct {
|
||||
panic("bindings: unresolved: no struct type")
|
||||
panic(fmt.Sprintf("bindings: unresolved: not a struct type: %#+v", v))
|
||||
}
|
||||
|
||||
// get bindings from any struct's non zero values first, including unexported.
|
||||
|
|
|
@ -55,7 +55,7 @@ func TestContainerHandler(t *testing.T) {
|
|||
|
||||
e := httptest.New(t, app)
|
||||
path := fmt.Sprintf("/%d", expectedOutput.ID)
|
||||
e.POST(path).WithJSON(input).Expect().Status(httptest.StatusOK).JSON().Equal(expectedOutput)
|
||||
e.POST(path).WithJSON(input).Expect().Status(httptest.StatusOK).JSON().IsEqual(expectedOutput)
|
||||
}
|
||||
|
||||
func TestContainerInject(t *testing.T) {
|
||||
|
@ -127,5 +127,5 @@ func TestContainerUseResultHandler(t *testing.T) {
|
|||
app.Get("/{id:int}", handler)
|
||||
|
||||
e := httptest.New(t, app)
|
||||
e.GET("/42").Expect().Status(httptest.StatusOK).JSON().Equal(expectedResponse)
|
||||
e.GET("/42").Expect().Status(httptest.StatusOK).JSON().IsEqual(expectedResponse)
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package hero
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"reflect"
|
||||
|
||||
|
@ -71,7 +72,7 @@ func newDependency(dependency interface{}, disablePayloadAutoBinding bool, match
|
|||
}
|
||||
|
||||
if d, ok := dependency.(*Dependency); ok {
|
||||
// already a *Dependency.
|
||||
// already a *Dependency, do not continue (and most importatly do not call resolveDependency) .
|
||||
return d
|
||||
}
|
||||
|
||||
|
@ -100,11 +101,12 @@ func newDependency(dependency interface{}, disablePayloadAutoBinding bool, match
|
|||
// DependencyResolver func(v reflect.Value, dest *Dependency) bool
|
||||
// Resolver DependencyResolver
|
||||
|
||||
func resolveDependency(v reflect.Value, disablePayloadAutoBinding bool, dest *Dependency, funcDependencies ...*Dependency) bool {
|
||||
func resolveDependency(v reflect.Value, disablePayloadAutoBinding bool, dest *Dependency, prevDependencies ...*Dependency) bool {
|
||||
return fromDependencyHandler(v, dest) ||
|
||||
fromStructValue(v, dest) ||
|
||||
fromBuiltinValue(v, dest) ||
|
||||
fromStructValueOrDependentStructValue(v, disablePayloadAutoBinding, dest, prevDependencies) ||
|
||||
fromFunc(v, dest) ||
|
||||
len(funcDependencies) > 0 && fromDependentFunc(v, disablePayloadAutoBinding, dest, funcDependencies)
|
||||
len(prevDependencies) > 0 && fromDependentFunc(v, disablePayloadAutoBinding, dest, prevDependencies)
|
||||
}
|
||||
|
||||
func fromDependencyHandler(_ reflect.Value, dest *Dependency) bool {
|
||||
|
@ -131,20 +133,114 @@ func fromDependencyHandler(_ reflect.Value, dest *Dependency) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
func fromStructValue(v reflect.Value, dest *Dependency) bool {
|
||||
if !isFunc(v) {
|
||||
// It's just a static value.
|
||||
handler := func(*context.Context, *Input) (reflect.Value, error) {
|
||||
return v, nil
|
||||
}
|
||||
|
||||
dest.DestType = v.Type()
|
||||
dest.Static = true
|
||||
dest.Handle = handler
|
||||
return true
|
||||
func fromBuiltinValue(v reflect.Value, dest *Dependency) bool {
|
||||
if !isBuiltinValue(v) {
|
||||
return false
|
||||
}
|
||||
|
||||
return false
|
||||
// It's just a static builtin value.
|
||||
handler := func(*context.Context, *Input) (reflect.Value, error) {
|
||||
return v, nil
|
||||
}
|
||||
|
||||
dest.DestType = v.Type()
|
||||
dest.Static = true
|
||||
dest.Handle = handler
|
||||
return true
|
||||
}
|
||||
|
||||
func fromStructValue(v reflect.Value, dest *Dependency) bool {
|
||||
if !isStructValue(v) {
|
||||
return false
|
||||
}
|
||||
|
||||
// It's just a static struct value.
|
||||
handler := func(*context.Context, *Input) (reflect.Value, error) {
|
||||
return v, nil
|
||||
}
|
||||
|
||||
dest.DestType = v.Type()
|
||||
dest.Static = true
|
||||
dest.Handle = handler
|
||||
return true
|
||||
}
|
||||
|
||||
func fromStructValueOrDependentStructValue(v reflect.Value, disablePayloadAutoBinding bool, dest *Dependency, prevDependencies []*Dependency) bool {
|
||||
if !isStructValue(v) {
|
||||
// It's not just a static struct value.
|
||||
return false
|
||||
}
|
||||
|
||||
if len(prevDependencies) == 0 { // As a non depedent struct.
|
||||
// We must make this check so we can avoid the auto-filling of
|
||||
// the dependencies from Iris builtin dependencies.
|
||||
return fromStructValue(v, dest)
|
||||
}
|
||||
|
||||
// Check if it's a builtin dependency (e.g an MVC Application (see mvc.go#newApp)),
|
||||
// if it's and registered without a Dependency wrapper, like the rest builtin dependencies,
|
||||
// then do NOT try to resolve its fields.
|
||||
if strings.HasPrefix(indirectType(v.Type()).PkgPath(), "github.com/kataras/iris/v12") {
|
||||
return fromStructValue(v, dest)
|
||||
}
|
||||
|
||||
bindings := getBindingsForStruct(v, prevDependencies, false, disablePayloadAutoBinding, DefaultDependencyMatcher, -1, nil)
|
||||
if len(bindings) == 0 {
|
||||
return fromStructValue(v, dest) // same as above.
|
||||
}
|
||||
|
||||
// As a depedent struct, however we may need to resolve its dependencies first
|
||||
// so we can decide if it's really a depedent struct or not.
|
||||
var (
|
||||
handler = func(*context.Context, *Input) (reflect.Value, error) {
|
||||
return v, nil
|
||||
}
|
||||
isStatic = true
|
||||
)
|
||||
|
||||
for _, binding := range bindings {
|
||||
if !binding.Dependency.Static {
|
||||
isStatic = false
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
handler = func(ctx *context.Context, _ *Input) (reflect.Value, error) { // Called once per dependency on build-time if the dependency is static.
|
||||
elem := v
|
||||
if elem.Kind() == reflect.Ptr {
|
||||
elem = elem.Elem()
|
||||
}
|
||||
|
||||
for _, binding := range bindings {
|
||||
field := elem.FieldByIndex(binding.Input.StructFieldIndex)
|
||||
if !field.CanSet() || !field.IsZero() {
|
||||
continue // already set.
|
||||
}
|
||||
// if !binding.Dependency.Match(field.Type()) { A check already happen in getBindingsForStruct.
|
||||
// continue
|
||||
// }
|
||||
|
||||
input, err := binding.Dependency.Handle(ctx, binding.Input)
|
||||
if err != nil {
|
||||
if err == ErrSeeOther {
|
||||
continue
|
||||
}
|
||||
|
||||
return emptyValue, err
|
||||
}
|
||||
|
||||
// fmt.Printf("binding %s to %#+v\n", field.String(), input)
|
||||
|
||||
field.Set(input)
|
||||
}
|
||||
|
||||
return v, nil
|
||||
}
|
||||
|
||||
dest.DestType = v.Type()
|
||||
dest.Static = isStatic
|
||||
dest.Handle = handler
|
||||
return true
|
||||
}
|
||||
|
||||
func fromFunc(v reflect.Value, dest *Dependency) bool {
|
||||
|
|
|
@ -35,7 +35,7 @@ func newSource(fn reflect.Value) Source {
|
|||
fallthrough
|
||||
default:
|
||||
if callerFileName == "" {
|
||||
callerFileName, callerLineNumber = getCaller()
|
||||
callerFileName, callerLineNumber = GetCaller()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -55,7 +55,7 @@ func newSource(fn reflect.Value) Source {
|
|||
}
|
||||
|
||||
func getSource() Source {
|
||||
filename, line := getCaller()
|
||||
filename, line := GetCaller()
|
||||
return Source{
|
||||
File: filename,
|
||||
Line: line,
|
||||
|
@ -67,7 +67,7 @@ func (s Source) String() string {
|
|||
}
|
||||
|
||||
// https://golang.org/doc/go1.9#callersframes
|
||||
func getCaller() (string, int) {
|
||||
func GetCaller() (string, int) {
|
||||
var pcs [32]uintptr
|
||||
n := runtime.Callers(4, pcs[:])
|
||||
frames := runtime.CallersFrames(pcs[:n])
|
||||
|
@ -76,11 +76,13 @@ func getCaller() (string, int) {
|
|||
frame, more := frames.Next()
|
||||
file := frame.File
|
||||
|
||||
if strings.HasSuffix(file, "_test.go") {
|
||||
return file, frame.Line
|
||||
if strings.Contains(file, "go/src/runtime/") {
|
||||
continue
|
||||
}
|
||||
|
||||
if !strings.Contains(file, "/kataras/iris") || strings.Contains(file, "/kataras/iris/_examples") || strings.Contains(file, "iris-contrib/examples") {
|
||||
// funcName is something like "github.com/kataras/iris.SomeFunc"
|
||||
funcName := frame.Function
|
||||
if !strings.HasPrefix(funcName, "github.com/kataras/iris/v12") {
|
||||
return file, frame.Line
|
||||
}
|
||||
|
||||
|
|
|
@ -146,65 +146,65 @@ func TestFuncResult(t *testing.T) {
|
|||
e := httptest.New(t, app)
|
||||
|
||||
e.GET("/text").Expect().Status(iris.StatusOK).
|
||||
Body().Equal("text")
|
||||
Body().IsEqual("text")
|
||||
|
||||
e.GET("/status").Expect().Status(iris.StatusBadGateway)
|
||||
|
||||
e.GET("/text/with/status/ok").Expect().Status(iris.StatusOK).
|
||||
Body().Equal("OK")
|
||||
Body().IsEqual("OK")
|
||||
|
||||
e.GET("/status/with/text/not/ok/first/second").Expect().Status(iris.StatusForbidden).
|
||||
Body().Equal("NOT_OK_firstsecond")
|
||||
Body().IsEqual("NOT_OK_firstsecond")
|
||||
// Author's note: <-- if that fails means that the last binder called for both input args,
|
||||
// see path_param_binder.go
|
||||
|
||||
e.GET("/text/and/content/type").Expect().Status(iris.StatusOK).
|
||||
ContentType("text/html", "utf-8").
|
||||
Body().Equal("<b>text</b>")
|
||||
Body().IsEqual("<b>text</b>")
|
||||
|
||||
e.GET("/custom/response").Expect().Status(iris.StatusOK).
|
||||
ContentType("text/html", "utf-8").
|
||||
Body().Equal("<b>text</b>")
|
||||
Body().IsEqual("<b>text</b>")
|
||||
e.GET("/custom/response/with/status/ok").Expect().Status(iris.StatusOK).
|
||||
ContentType("text/html", "utf-8").
|
||||
Body().Equal("<b>OK</b>")
|
||||
Body().IsEqual("<b>OK</b>")
|
||||
e.GET("/custom/response/with/status/not/ok").Expect().Status(iris.StatusInternalServerError).
|
||||
ContentType("text/html", "utf-8").
|
||||
Body().Equal("<b>internal server error</b>")
|
||||
Body().IsEqual("<b>internal server error</b>")
|
||||
|
||||
expectedResultFromCustomStruct := map[string]interface{}{
|
||||
"name": "Iris",
|
||||
"age": 2,
|
||||
}
|
||||
e.GET("/custom/struct").Expect().Status(iris.StatusOK).
|
||||
JSON().Equal(expectedResultFromCustomStruct)
|
||||
JSON().IsEqual(expectedResultFromCustomStruct)
|
||||
e.GET("/custom/struct/with/status/not/ok").Expect().Status(iris.StatusInternalServerError).
|
||||
JSON().Equal(expectedResultFromCustomStruct)
|
||||
JSON().IsEqual(expectedResultFromCustomStruct)
|
||||
e.GET("/custom/struct/with/content/type").Expect().Status(iris.StatusOK).
|
||||
ContentType("text/xml", "utf-8")
|
||||
e.GET("/custom/struct/with/error").Expect().Status(iris.StatusOK).
|
||||
JSON().Equal(expectedResultFromCustomStruct)
|
||||
JSON().IsEqual(expectedResultFromCustomStruct)
|
||||
e.GET("/custom/struct/with/error").WithQuery("err", true).Expect().
|
||||
Status(iris.StatusBadRequest). // the default status code if error is not nil
|
||||
// the content should be not JSON it should be the status code's text
|
||||
// it will fire the error's text
|
||||
Body().Equal("omit return of testCustomStruct and fire error")
|
||||
Body().IsEqual("omit return of testCustomStruct and fire error")
|
||||
|
||||
e.GET("/custom/error/as/dispatcher").Expect().
|
||||
Status(iris.StatusBadRequest). // the default status code if error is not nil
|
||||
// the content should be not JSON it should be the status code's text
|
||||
// it will fire the error's text
|
||||
JSON().Equal(err{iris.StatusBadRequest, "this is my error as json"})
|
||||
JSON().IsEqual(err{iris.StatusBadRequest, "this is my error as json"})
|
||||
|
||||
// its result is nil should give an empty response but content-type is set correctly.
|
||||
e.GET("/custom/nil/typed").Expect().
|
||||
Status(iris.StatusOK).ContentType(context.ContentJSONHeaderValue).Body().Empty()
|
||||
Status(iris.StatusOK).ContentType(context.ContentJSONHeaderValue).Body().IsEmpty()
|
||||
e.GET("/custom/nil/typed/ptr").Expect().
|
||||
Status(iris.StatusOK).ContentType(context.ContentJSONHeaderValue).Body().Empty()
|
||||
Status(iris.StatusOK).ContentType(context.ContentJSONHeaderValue).Body().IsEmpty()
|
||||
e.GET("/custom/nil/map").Expect().
|
||||
Status(iris.StatusOK).ContentType(context.ContentJSONHeaderValue).Body().Empty()
|
||||
Status(iris.StatusOK).ContentType(context.ContentJSONHeaderValue).Body().IsEmpty()
|
||||
e.GET("/custom/nil/struct").Expect().
|
||||
Status(iris.StatusOK).ContentType(context.ContentJSONHeaderValue).Body().Empty()
|
||||
Status(iris.StatusOK).ContentType(context.ContentJSONHeaderValue).Body().IsEmpty()
|
||||
}
|
||||
|
||||
type (
|
||||
|
@ -246,20 +246,20 @@ func TestPreflightResult(t *testing.T) {
|
|||
|
||||
expected1 := testPreflightResponse{Code: httptest.StatusOK, Message: "OK"}
|
||||
e.POST("/").WithJSON(testPreflightRequest{FailCode: expected1.Code}).
|
||||
Expect().Status(httptest.StatusOK).JSON().Equal(expected1)
|
||||
Expect().Status(httptest.StatusOK).JSON().IsEqual(expected1)
|
||||
|
||||
expected2 := testPreflightResponse{Code: httptest.StatusBadRequest, Message: "Bad Request"}
|
||||
e.POST("/").WithJSON(testPreflightRequest{FailCode: expected2.Code}).
|
||||
Expect().Status(httptest.StatusBadRequest).JSON().Equal(expected2)
|
||||
Expect().Status(httptest.StatusBadRequest).JSON().IsEqual(expected2)
|
||||
|
||||
// Test error returned from Preflight.
|
||||
e.POST("/").WithJSON(testPreflightRequest{FailCode: httptest.StatusInternalServerError}).
|
||||
Expect().Status(httptest.StatusBadRequest).Body().Equal("custom error")
|
||||
Expect().Status(httptest.StatusBadRequest).Body().IsEqual("custom error")
|
||||
|
||||
// Can be done without Preflight as the second output argument can be a status code.
|
||||
expected4 := testOutput{Name: "my_name"}
|
||||
e.POST("/alternative").WithJSON(testInput{expected4.Name}).
|
||||
Expect().Status(httptest.StatusAccepted).JSON().Equal(expected4)
|
||||
Expect().Status(httptest.StatusAccepted).JSON().IsEqual(expected4)
|
||||
}
|
||||
|
||||
func TestResponseErr(t *testing.T) {
|
||||
|
@ -280,5 +280,5 @@ func TestResponseErr(t *testing.T) {
|
|||
})
|
||||
|
||||
e := httptest.New(t, app)
|
||||
e.GET("/").Expect().Status(iris.StatusBadGateway).Body().Equal("response error")
|
||||
e.GET("/").Expect().Status(iris.StatusBadGateway).Body().IsEqual("response error")
|
||||
}
|
||||
|
|
|
@ -93,13 +93,13 @@ func testAppWithHeroHandlers(t *testing.T, h1, h2, h3 iris.Handler) {
|
|||
e := httptest.New(t, app)
|
||||
// 1
|
||||
e.GET(fmt.Sprintf("/%d/%s", expectedUser.ID, expectedUser.Username)).Expect().Status(httptest.StatusOK).
|
||||
JSON().Equal(expectedUser)
|
||||
JSON().IsEqual(expectedUser)
|
||||
// 2
|
||||
e.GET("/service").Expect().Status(httptest.StatusOK).
|
||||
Body().Equal("say something")
|
||||
Body().IsEqual("say something")
|
||||
// 3
|
||||
e.GET("/param/the_param_value").Expect().Status(httptest.StatusOK).
|
||||
Body().Equal("param is: the_param_value")
|
||||
Body().IsEqual("param is: the_param_value")
|
||||
}
|
||||
|
||||
// TestBindFunctionAsFunctionInputArgument tests to bind
|
||||
|
@ -123,7 +123,7 @@ func TestBindFunctionAsFunctionInputArgument(t *testing.T) {
|
|||
|
||||
expectedUsername := "kataras"
|
||||
e.POST("/").WithFormField("username", expectedUsername).
|
||||
Expect().Status(iris.StatusOK).Body().Equal(expectedUsername)
|
||||
Expect().Status(iris.StatusOK).Body().IsEqual(expectedUsername)
|
||||
}
|
||||
|
||||
func TestPayloadBinding(t *testing.T) {
|
||||
|
@ -155,21 +155,21 @@ func TestPayloadBinding(t *testing.T) {
|
|||
e := httptest.New(t, app)
|
||||
|
||||
// JSON
|
||||
e.POST("/").WithJSON(iris.Map{"username": "makis"}).Expect().Status(httptest.StatusOK).Body().Equal("makis")
|
||||
e.POST("/2").WithJSON(iris.Map{"username": "kataras"}).Expect().Status(httptest.StatusOK).Body().Equal("kataras")
|
||||
e.POST("/").WithJSON(iris.Map{"username": "makis"}).Expect().Status(httptest.StatusOK).Body().IsEqual("makis")
|
||||
e.POST("/2").WithJSON(iris.Map{"username": "kataras"}).Expect().Status(httptest.StatusOK).Body().IsEqual("kataras")
|
||||
|
||||
// FORM (url-encoded)
|
||||
e.POST("/").WithFormField("username", "makis").Expect().Status(httptest.StatusOK).Body().Equal("makis")
|
||||
e.POST("/").WithFormField("username", "makis").Expect().Status(httptest.StatusOK).Body().IsEqual("makis")
|
||||
// FORM (multipart)
|
||||
e.POST("/").WithMultipart().WithFormField("username", "makis").Expect().Status(httptest.StatusOK).Body().Equal("makis")
|
||||
e.POST("/").WithMultipart().WithFormField("username", "makis").Expect().Status(httptest.StatusOK).Body().IsEqual("makis")
|
||||
// FORM: test ErrorHandler skip the ErrPath.
|
||||
e.POST("/").WithMultipart().WithFormField("username", "makis").WithFormField("unknown", "continue").
|
||||
Expect().Status(httptest.StatusOK).Body().Equal("makis")
|
||||
Expect().Status(httptest.StatusOK).Body().IsEqual("makis")
|
||||
|
||||
// POST URL query.
|
||||
e.POST("/").WithQuery("username", "makis").Expect().Status(httptest.StatusOK).Body().Equal("makis")
|
||||
e.POST("/").WithQuery("username", "makis").Expect().Status(httptest.StatusOK).Body().IsEqual("makis")
|
||||
// GET URL query.
|
||||
e.GET("/").WithQuery("username", "makis").Expect().Status(httptest.StatusOK).Body().Equal("makis")
|
||||
e.GET("/").WithQuery("username", "makis").Expect().Status(httptest.StatusOK).Body().IsEqual("makis")
|
||||
}
|
||||
|
||||
/* Author's notes:
|
||||
|
@ -231,9 +231,9 @@ func TestDependentDependencies(t *testing.T) {
|
|||
app.Get("/h3", h3)
|
||||
|
||||
e := httptest.New(t, app)
|
||||
e.GET("/h1").Expect().Status(httptest.StatusOK).Body().Equal("prefix: it is a deep dependency")
|
||||
e.GET("/h2").Expect().Status(httptest.StatusOK).Body().Equal("prefix: message")
|
||||
e.GET("/h3").Expect().Status(httptest.StatusOK).Body().Equal("value")
|
||||
e.GET("/h1").Expect().Status(httptest.StatusOK).Body().IsEqual("prefix: it is a deep dependency")
|
||||
e.GET("/h2").Expect().Status(httptest.StatusOK).Body().IsEqual("prefix: message")
|
||||
e.GET("/h3").Expect().Status(httptest.StatusOK).Body().IsEqual("value")
|
||||
}
|
||||
|
||||
func TestHandlerPathParams(t *testing.T) {
|
||||
|
@ -262,7 +262,7 @@ func TestHandlerPathParams(t *testing.T) {
|
|||
e.GET("/editors/42"),
|
||||
e.GET("/1/book/42"),
|
||||
} {
|
||||
testReq.Expect().Status(httptest.StatusOK).Body().Equal("42")
|
||||
testReq.Expect().Status(httptest.StatusOK).Body().IsEqual("42")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -301,8 +301,8 @@ func TestRegisterDependenciesFromContext(t *testing.T) {
|
|||
|
||||
e := httptest.New(t, app)
|
||||
|
||||
e.GET("/").Expect().Status(httptest.StatusOK).Body().Equal("kataras")
|
||||
e.GET("/service").Expect().Status(httptest.StatusOK).Body().Equal("say hello")
|
||||
e.GET("/both").Expect().Status(httptest.StatusOK).Body().Equal("say kataras")
|
||||
e.GET("/non").Expect().Status(httptest.StatusOK).Body().Equal("nothing")
|
||||
e.GET("/").Expect().Status(httptest.StatusOK).Body().IsEqual("kataras")
|
||||
e.GET("/service").Expect().Status(httptest.StatusOK).Body().IsEqual("say hello")
|
||||
e.GET("/both").Expect().Status(httptest.StatusOK).Body().IsEqual("say kataras")
|
||||
e.GET("/non").Expect().Status(httptest.StatusOK).Body().IsEqual("nothing")
|
||||
}
|
||||
|
|
|
@ -42,6 +42,39 @@ func isFunc(kindable interface{ Kind() reflect.Kind }) bool {
|
|||
return kindable.Kind() == reflect.Func
|
||||
}
|
||||
|
||||
func isStructValue(v reflect.Value) bool {
|
||||
return indirectType(v.Type()).Kind() == reflect.Struct
|
||||
}
|
||||
|
||||
// isBuiltin reports whether a reflect.Value is a builtin type
|
||||
func isBuiltinValue(v reflect.Value) bool {
|
||||
switch v.Type().Kind() {
|
||||
case reflect.Bool,
|
||||
reflect.Int,
|
||||
reflect.Int8,
|
||||
reflect.Int16,
|
||||
reflect.Int32,
|
||||
reflect.Int64,
|
||||
reflect.Uint,
|
||||
reflect.Uint8,
|
||||
reflect.Uint16,
|
||||
reflect.Uint32,
|
||||
reflect.Uint64,
|
||||
reflect.Float32,
|
||||
reflect.Float64,
|
||||
reflect.Complex64,
|
||||
reflect.Complex128,
|
||||
reflect.Array,
|
||||
reflect.Chan,
|
||||
reflect.Map,
|
||||
reflect.Slice,
|
||||
reflect.String:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
inputTyp = reflect.TypeOf((*Input)(nil))
|
||||
errTyp = reflect.TypeOf((*error)(nil)).Elem()
|
||||
|
|
|
@ -57,6 +57,8 @@ func makeStruct(structPtr interface{}, c *Container, partyParamsCount int) *Stru
|
|||
// If static then Struct.Acquire will return the same "value" instance, otherwise it will create a new one.
|
||||
singleton := true
|
||||
elem := v.Elem()
|
||||
|
||||
// fmt.Printf("makeStruct: bindings length = %d\n", len(bindings))
|
||||
for _, b := range bindings {
|
||||
if b.Dependency.Static {
|
||||
// Fill now.
|
||||
|
|
|
@ -46,11 +46,11 @@ func TestStruct(t *testing.T) {
|
|||
app.Get("/myHandler4", getHandler)
|
||||
|
||||
e := httptest.New(t, app)
|
||||
e.POST("/" + input.Name).Expect().Status(httptest.StatusOK).JSON().Equal(expectedOutput)
|
||||
e.POST("/" + input.Name).Expect().Status(httptest.StatusOK).JSON().IsEqual(expectedOutput)
|
||||
path := fmt.Sprintf("/%d", expectedOutput.ID)
|
||||
e.POST(path).WithJSON(input).Expect().Status(httptest.StatusOK).JSON().Equal(expectedOutput)
|
||||
e.POST("/myHandler3").WithJSON(input).Expect().Status(httptest.StatusOK).JSON().Equal(expectedOutput)
|
||||
e.GET("/myHandler4").Expect().Status(httptest.StatusOK).Body().Equal("MyHandler4")
|
||||
e.POST(path).WithJSON(input).Expect().Status(httptest.StatusOK).JSON().IsEqual(expectedOutput)
|
||||
e.POST("/myHandler3").WithJSON(input).Expect().Status(httptest.StatusOK).JSON().IsEqual(expectedOutput)
|
||||
e.GET("/myHandler4").Expect().Status(httptest.StatusOK).Body().IsEqual("MyHandler4")
|
||||
}
|
||||
|
||||
type testStructErrorHandler struct{}
|
||||
|
@ -72,7 +72,7 @@ func TestStructErrorHandler(t *testing.T) {
|
|||
|
||||
expectedErrText := "an error"
|
||||
e := httptest.New(t, app)
|
||||
e.GET("/" + expectedErrText).Expect().Status(httptest.StatusConflict).Body().Equal(expectedErrText)
|
||||
e.GET("/" + expectedErrText).Expect().Status(httptest.StatusConflict).Body().IsEqual(expectedErrText)
|
||||
}
|
||||
|
||||
type (
|
||||
|
@ -117,5 +117,5 @@ func TestStructFieldsSorter(t *testing.T) { // see https://github.com/kataras/ir
|
|||
e := httptest.New(t, app)
|
||||
|
||||
expectedBody := `&hero_test.testServiceImpl1{inner:"parser"} | &hero_test.testServiceImpl2{tf:24}`
|
||||
e.GET("/").Expect().Status(httptest.StatusOK).Body().Equal(expectedBody)
|
||||
e.GET("/").Expect().Status(httptest.StatusOK).Body().IsEqual(expectedBody)
|
||||
}
|
||||
|
|
|
@ -73,7 +73,7 @@ func TestBasicAuthUseRouter(t *testing.T) {
|
|||
for username, password := range users {
|
||||
// Test pass authentication and route found.
|
||||
e.GET("/").WithBasicAuth(username, password).Expect().
|
||||
Status(httptest.StatusOK).Body().Equal(fmt.Sprintf("Hello, %s!", username))
|
||||
Status(httptest.StatusOK).Body().IsEqual(fmt.Sprintf("Hello, %s!", username))
|
||||
e.GET("/user_json").WithBasicAuth(username, password).Expect().
|
||||
Status(httptest.StatusOK).JSON().Object().ContainsMap(iris.Map{
|
||||
"username": username,
|
||||
|
@ -83,7 +83,7 @@ func TestBasicAuthUseRouter(t *testing.T) {
|
|||
Equal(fmt.Sprintf("%s\n%s\n%s", "Basic Authentication", username, password))
|
||||
|
||||
// Test empty auth.
|
||||
e.GET("/").Expect().Status(httptest.StatusUnauthorized).Body().Equal("Unauthorized")
|
||||
e.GET("/").Expect().Status(httptest.StatusUnauthorized).Body().IsEqual("Unauthorized")
|
||||
// Test invalid auth.
|
||||
e.GET("/").WithBasicAuth(username, "invalid_password").Expect().
|
||||
Status(httptest.StatusForbidden)
|
||||
|
@ -93,14 +93,14 @@ func TestBasicAuthUseRouter(t *testing.T) {
|
|||
// Test different method, it should pass the authentication (no stop on 401)
|
||||
// but it doesn't fire the GET route, instead it gives 405.
|
||||
e.POST("/").WithBasicAuth(username, password).Expect().
|
||||
Status(httptest.StatusMethodNotAllowed).Body().Equal("Method Not Allowed")
|
||||
Status(httptest.StatusMethodNotAllowed).Body().IsEqual("Method Not Allowed")
|
||||
|
||||
// Test pass the authentication but route not found.
|
||||
e.GET("/notfound").WithBasicAuth(username, password).Expect().
|
||||
Status(httptest.StatusNotFound).Body().Equal("Not Found")
|
||||
Status(httptest.StatusNotFound).Body().IsEqual("Not Found")
|
||||
|
||||
// Test empty auth.
|
||||
e.GET("/notfound").Expect().Status(httptest.StatusUnauthorized).Body().Equal("Unauthorized")
|
||||
e.GET("/notfound").Expect().Status(httptest.StatusUnauthorized).Body().IsEqual("Unauthorized")
|
||||
// Test invalid auth.
|
||||
e.GET("/notfound").WithBasicAuth(username, "invalid_password").Expect().
|
||||
Status(httptest.StatusForbidden)
|
||||
|
@ -114,7 +114,7 @@ func TestBasicAuthUseRouter(t *testing.T) {
|
|||
|
||||
// Test pass and route found.
|
||||
sub.GET("/").WithBasicAuth(username, password).Expect().
|
||||
Status(httptest.StatusOK).Body().Equal(fmt.Sprintf("Static, %s", username))
|
||||
Status(httptest.StatusOK).Body().IsEqual(fmt.Sprintf("Static, %s", username))
|
||||
|
||||
// Test empty auth.
|
||||
sub.GET("/").Expect().Status(httptest.StatusUnauthorized)
|
||||
|
@ -126,10 +126,10 @@ func TestBasicAuthUseRouter(t *testing.T) {
|
|||
|
||||
// Test pass the authentication but route not found.
|
||||
sub.GET("/notfound").WithBasicAuth(username, password).Expect().
|
||||
Status(httptest.StatusNotFound).Body().Equal("Not Found")
|
||||
Status(httptest.StatusNotFound).Body().IsEqual("Not Found")
|
||||
|
||||
// Test empty auth.
|
||||
sub.GET("/notfound").Expect().Status(httptest.StatusUnauthorized).Body().Equal("Unauthorized")
|
||||
sub.GET("/notfound").Expect().Status(httptest.StatusUnauthorized).Body().IsEqual("Unauthorized")
|
||||
// Test invalid auth.
|
||||
sub.GET("/notfound").WithBasicAuth(username, "invalid_password").Expect().
|
||||
Status(httptest.StatusForbidden)
|
||||
|
@ -142,16 +142,16 @@ func TestBasicAuthUseRouter(t *testing.T) {
|
|||
sub = e.Builder(func(req *httptest.Request) {
|
||||
req.WithURL("http://reset_with_use_router.mydomain.com")
|
||||
})
|
||||
sub.GET("/").Expect().Status(httptest.StatusOK).Body().Equal("with use router\n")
|
||||
sub.POST("/").Expect().Status(httptest.StatusMethodNotAllowed).Body().Equal("Method Not Allowed")
|
||||
sub.GET("/notfound").Expect().Status(httptest.StatusNotFound).Body().Equal("Not Found")
|
||||
sub.GET("/").Expect().Status(httptest.StatusOK).Body().IsEqual("with use router\n")
|
||||
sub.POST("/").Expect().Status(httptest.StatusMethodNotAllowed).Body().IsEqual("Method Not Allowed")
|
||||
sub.GET("/notfound").Expect().Status(httptest.StatusNotFound).Body().IsEqual("Not Found")
|
||||
|
||||
// Test a reset-ed Party (all should pass without auth).
|
||||
sub = e.Builder(func(req *httptest.Request) {
|
||||
req.WithURL("http://reset.mydomain.com")
|
||||
})
|
||||
sub.GET("/").Expect().Status(httptest.StatusOK).Body().Empty()
|
||||
sub.POST("/").Expect().Status(httptest.StatusMethodNotAllowed).Body().Equal("Method Not Allowed")
|
||||
sub.GET("/notfound").Expect().Status(httptest.StatusNotFound).Body().Equal("Not Found")
|
||||
sub.GET("/").Expect().Status(httptest.StatusOK).Body().IsEmpty()
|
||||
sub.POST("/").Expect().Status(httptest.StatusMethodNotAllowed).Body().IsEqual("Method Not Allowed")
|
||||
sub.GET("/notfound").Expect().Status(httptest.StatusNotFound).Body().IsEqual("Not Found")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,10 +49,10 @@ func TestJWT(t *testing.T) {
|
|||
// Test Header.
|
||||
headerValue := fmt.Sprintf("Bearer %s", token)
|
||||
e.GET("/protected").WithHeader("Authorization", headerValue).Expect().
|
||||
Status(iris.StatusOK).Body().Equal("bar")
|
||||
Status(iris.StatusOK).Body().IsEqual("bar")
|
||||
// Test URL query.
|
||||
e.GET("/protected").WithQuery("token", token).Expect().
|
||||
Status(iris.StatusOK).Body().Equal("bar")
|
||||
Status(iris.StatusOK).Body().IsEqual("bar")
|
||||
|
||||
// Test unauthorized.
|
||||
e.GET("/protected").Expect().Status(iris.StatusUnauthorized)
|
||||
|
@ -61,5 +61,5 @@ func TestJWT(t *testing.T) {
|
|||
// Test expired (note checks happen based on second round).
|
||||
time.Sleep(5 * time.Second)
|
||||
e.GET("/protected").WithHeader("Authorization", headerValue).Expect().
|
||||
Status(iris.StatusUnauthorized).Body().Equal("jwt: token expired")
|
||||
Status(iris.StatusUnauthorized).Body().IsEqual("jwt: token expired")
|
||||
}
|
||||
|
|
|
@ -49,28 +49,28 @@ func TestMethodOverrideWrapper(t *testing.T) {
|
|||
|
||||
// Test headers.
|
||||
e.POST("/path").WithHeader("X-HTTP-Method", iris.MethodDelete).Expect().
|
||||
Status(iris.StatusOK).Body().Equal(expectedDelResponse)
|
||||
Status(iris.StatusOK).Body().IsEqual(expectedDelResponse)
|
||||
e.POST("/path").WithHeader("X-HTTP-Method-Override", iris.MethodDelete).Expect().
|
||||
Status(iris.StatusOK).Body().Equal(expectedDelResponse)
|
||||
Status(iris.StatusOK).Body().IsEqual(expectedDelResponse)
|
||||
e.POST("/path").WithHeader("X-Method-Override", iris.MethodDelete).Expect().
|
||||
Status(iris.StatusOK).Body().Equal(expectedDelResponse)
|
||||
Status(iris.StatusOK).Body().IsEqual(expectedDelResponse)
|
||||
|
||||
// Test form field value.
|
||||
e.POST("/path").WithFormField("_method", iris.MethodDelete).Expect().
|
||||
Status(iris.StatusOK).Body().Equal(expectedDelResponse)
|
||||
Status(iris.StatusOK).Body().IsEqual(expectedDelResponse)
|
||||
|
||||
// Test URL Query (although it's the same as form field in this case).
|
||||
e.POST("/path").WithQuery("_method", iris.MethodDelete).Expect().
|
||||
Status(iris.StatusOK).Body().Equal(expectedDelResponse)
|
||||
Status(iris.StatusOK).Body().IsEqual(expectedDelResponse)
|
||||
|
||||
// Test saved original method and
|
||||
// Test without registered "POST" route.
|
||||
e.POST("/path2").WithQuery("_method", iris.MethodDelete).Expect().
|
||||
Status(iris.StatusOK).Body().Equal(expectedDelResponse + iris.MethodPost)
|
||||
Status(iris.StatusOK).Body().IsEqual(expectedDelResponse + iris.MethodPost)
|
||||
|
||||
// Test simple POST request without method override fields.
|
||||
e.POST("/path").Expect().Status(iris.StatusOK).Body().Equal(expectedPostResponse)
|
||||
e.POST("/path").Expect().Status(iris.StatusOK).Body().IsEqual(expectedPostResponse)
|
||||
|
||||
// Test simple DELETE request.
|
||||
e.DELETE("/path").Expect().Status(iris.StatusOK).Body().Equal(expectedDelResponse)
|
||||
e.DELETE("/path").Expect().Status(iris.StatusOK).Body().IsEqual(expectedDelResponse)
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ func TestRequestID(t *testing.T) {
|
|||
|
||||
e := httptest.New(t, app)
|
||||
e.GET("/default").Expect().Status(httptest.StatusOK).Body().NotEmpty()
|
||||
e.GET("/custom").Expect().Status(httptest.StatusOK).Body().Equal(expectedCustomID)
|
||||
e.GET("/custom_err").Expect().Status(httptest.StatusUnauthorized).Body().Equal(expectedErrMsg)
|
||||
e.GET("/custom_change_id").Expect().Status(httptest.StatusOK).Body().Equal(expectedCustomIDFromOtherMiddleware)
|
||||
e.GET("/custom").Expect().Status(httptest.StatusOK).Body().IsEqual(expectedCustomID)
|
||||
e.GET("/custom_err").Expect().Status(httptest.StatusUnauthorized).Body().IsEqual(expectedErrMsg)
|
||||
e.GET("/custom_change_id").Expect().Status(httptest.StatusOK).Body().IsEqual(expectedCustomIDFromOtherMiddleware)
|
||||
}
|
||||
|
|
|
@ -124,7 +124,7 @@ func TestControllerHandle(t *testing.T) {
|
|||
e := httptest.New(t, app)
|
||||
|
||||
// test the index, is not part of the current package's implementation but do it.
|
||||
e.GET("/").Expect().Status(httptest.StatusOK).Body().Equal("index")
|
||||
e.GET("/").Expect().Status(httptest.StatusOK).Body().IsEqual("index")
|
||||
|
||||
// the important things now.
|
||||
|
||||
|
@ -133,30 +133,30 @@ func TestControllerHandle(t *testing.T) {
|
|||
// (which is the function's receiver, if any, in this case the *testController in go).
|
||||
expectedReqField := "this is a request field filled by this url param"
|
||||
e.GET("/histatic").WithQuery("reqfield", expectedReqField).Expect().Status(httptest.StatusOK).
|
||||
Body().Equal(expectedReqField)
|
||||
Body().IsEqual(expectedReqField)
|
||||
// this test makes sure that the binded values of the controller is handled correctly
|
||||
// and can be used in a user-defined, dynamic "mvc handler".
|
||||
e.GET("/hiservice").Expect().Status(httptest.StatusOK).
|
||||
Body().Equal("service: hi")
|
||||
Body().IsEqual("service: hi")
|
||||
e.GET("/hiservice/value").Expect().Status(httptest.StatusOK).
|
||||
Body().Equal("service: hi with param: value")
|
||||
Body().IsEqual("service: hi with param: value")
|
||||
// this worked with a temporary variadic on the resolvemethodfunc which is not
|
||||
// correct design, I should split the path and params with the rest of implementation
|
||||
// in order a simple template.Src can be given.
|
||||
e.GET("/hiparam/value").Expect().Status(httptest.StatusOK).
|
||||
Body().Equal("value")
|
||||
Body().IsEqual("value")
|
||||
e.GET("/hiparamempyinput/value").Expect().Status(httptest.StatusOK).
|
||||
Body().Equal("empty in but served with ctx.Params.Get('ps')=value")
|
||||
Body().IsEqual("empty in but served with ctx.Params.Get('ps')=value")
|
||||
e.GET("/custom/value1").Expect().Status(httptest.StatusOK).
|
||||
Body().Equal("value1")
|
||||
Body().IsEqual("value1")
|
||||
e.GET("/custom2/value2").Expect().Status(httptest.StatusOK).
|
||||
Body().Equal("value2")
|
||||
Body().IsEqual("value2")
|
||||
e.GET("/custom3/value1/value2").Expect().Status(httptest.StatusOK).
|
||||
Body().Equal("value1value2")
|
||||
Body().IsEqual("value1value2")
|
||||
e.GET("/custom3/value1").Expect().Status(httptest.StatusNotFound)
|
||||
|
||||
e.GET("/hi/param/empty/input/with/ctx/value").Expect().Status(httptest.StatusOK).
|
||||
Body().Equal("empty in but served with ctx.Params.Get('param2')= value == id == value")
|
||||
Body().IsEqual("empty in but served with ctx.Params.Get('param2')= value == id == value")
|
||||
}
|
||||
|
||||
type testControllerHandleWithDynamicPathPrefix struct {
|
||||
|
@ -173,7 +173,7 @@ func TestControllerHandleWithDynamicPathPrefix(t *testing.T) {
|
|||
New(app.Party("/api/data/{model:string}/{action:string}")).Handle(new(testControllerHandleWithDynamicPathPrefix))
|
||||
e := httptest.New(t, app)
|
||||
e.GET("/api/data/mymodel/myaction/myid").Expect().Status(httptest.StatusOK).
|
||||
Body().Equal("mymodelmyactionmyid")
|
||||
Body().IsEqual("mymodelmyactionmyid")
|
||||
}
|
||||
|
||||
type testControllerGetBy struct{}
|
||||
|
@ -195,7 +195,7 @@ func TestControllerGetByWithAllowMethods(t *testing.T) {
|
|||
|
||||
e := httptest.New(t, app)
|
||||
e.GET("/project/42").Expect().Status(httptest.StatusOK).
|
||||
JSON().Equal(&testCustomStruct{Age: 42, Name: "name"})
|
||||
JSON().IsEqual(&testCustomStruct{Age: 42, Name: "name"})
|
||||
e.POST("/project/42").Expect().Status(httptest.StatusOK)
|
||||
e.PUT("/project/42").Expect().Status(httptest.StatusMethodNotAllowed)
|
||||
}
|
||||
|
|
|
@ -74,32 +74,32 @@ func TestControllerMethodResult(t *testing.T) {
|
|||
e := httptest.New(t, app)
|
||||
|
||||
e.GET("/").Expect().Status(iris.StatusOK).
|
||||
Body().Equal("Hello World!")
|
||||
Body().IsEqual("Hello World!")
|
||||
|
||||
e.GET("/with/status").Expect().Status(iris.StatusNotFound).
|
||||
Body().Equal("This page doesn't exist")
|
||||
Body().IsEqual("This page doesn't exist")
|
||||
|
||||
e.GET("/json").Expect().Status(iris.StatusOK).
|
||||
JSON().Equal(iris.Map{
|
||||
JSON().IsEqual(iris.Map{
|
||||
"name": "Iris",
|
||||
"age": 2,
|
||||
})
|
||||
|
||||
e.GET("/json").WithQuery("err", true).Expect().
|
||||
Status(iris.StatusBadRequest).
|
||||
Body().Equal("error here")
|
||||
Body().IsEqual("error here")
|
||||
|
||||
e.GET("/thing/with/try/1").Expect().
|
||||
Status(iris.StatusOK).
|
||||
Body().Equal("thing 1")
|
||||
Body().IsEqual("thing 1")
|
||||
// failure because of index exceed the slice
|
||||
e.GET("/thing/with/try/3").Expect().
|
||||
Status(iris.StatusNotFound).
|
||||
Body().Equal("thing does not exist")
|
||||
Body().IsEqual("thing does not exist")
|
||||
|
||||
e.GET("/thing/with/try/default/3").Expect().
|
||||
Status(iris.StatusBadRequest).
|
||||
Body().Equal("Bad Request")
|
||||
Body().IsEqual("Bad Request")
|
||||
}
|
||||
|
||||
type testControllerMethodResultTypes struct {
|
||||
|
@ -178,49 +178,49 @@ func TestControllerMethodResultTypes(t *testing.T) {
|
|||
e := httptest.New(t, app)
|
||||
|
||||
e.GET("/text").Expect().Status(iris.StatusOK).
|
||||
Body().Equal("text")
|
||||
Body().IsEqual("text")
|
||||
|
||||
e.GET("/status").Expect().Status(iris.StatusBadGateway)
|
||||
|
||||
e.GET("/text/with/status/ok").Expect().Status(iris.StatusOK).
|
||||
Body().Equal("OK")
|
||||
Body().IsEqual("OK")
|
||||
|
||||
e.GET("/status/with/text/not/ok/first/second").Expect().Status(iris.StatusForbidden).
|
||||
Body().Equal("NOT_OK_firstsecond")
|
||||
Body().IsEqual("NOT_OK_firstsecond")
|
||||
// Author's note: <-- if that fails means that the last binder called for both input args,
|
||||
// see path_param_binder.go
|
||||
|
||||
e.GET("/text/and/content/type").Expect().Status(iris.StatusOK).
|
||||
ContentType("text/html", "utf-8").
|
||||
Body().Equal("<b>text</b>")
|
||||
Body().IsEqual("<b>text</b>")
|
||||
|
||||
e.GET("/custom/response").Expect().Status(iris.StatusOK).
|
||||
ContentType("text/html", "utf-8").
|
||||
Body().Equal("<b>text</b>")
|
||||
Body().IsEqual("<b>text</b>")
|
||||
e.GET("/custom/response/with/status/ok").Expect().Status(iris.StatusOK).
|
||||
ContentType("text/html", "utf-8").
|
||||
Body().Equal("<b>OK</b>")
|
||||
Body().IsEqual("<b>OK</b>")
|
||||
e.GET("/custom/response/with/status/not/ok").Expect().Status(iris.StatusInternalServerError).
|
||||
ContentType("text/html", "utf-8").
|
||||
Body().Equal("<b>internal server error</b>")
|
||||
Body().IsEqual("<b>internal server error</b>")
|
||||
|
||||
expectedResultFromCustomStruct := map[string]interface{}{
|
||||
"name": "Iris",
|
||||
"age": 2,
|
||||
}
|
||||
e.GET("/custom/struct").Expect().Status(iris.StatusOK).
|
||||
JSON().Equal(expectedResultFromCustomStruct)
|
||||
JSON().IsEqual(expectedResultFromCustomStruct)
|
||||
e.GET("/custom/struct/with/status/not/ok").Expect().Status(iris.StatusInternalServerError).
|
||||
JSON().Equal(expectedResultFromCustomStruct)
|
||||
JSON().IsEqual(expectedResultFromCustomStruct)
|
||||
e.GET("/custom/struct/with/content/type").Expect().Status(iris.StatusOK).
|
||||
ContentType("text/xml", "utf-8")
|
||||
e.GET("/custom/struct/with/error").Expect().Status(iris.StatusOK).
|
||||
JSON().Equal(expectedResultFromCustomStruct)
|
||||
JSON().IsEqual(expectedResultFromCustomStruct)
|
||||
e.GET("/custom/struct/with/error").WithQuery("err", true).Expect().
|
||||
Status(iris.StatusBadRequest). // the default status code if error is not nil
|
||||
// the content should be not JSON it should be the status code's text
|
||||
// it will fire the error's text
|
||||
Body().Equal("omit return of testCustomStruct and fire error")
|
||||
Body().IsEqual("omit return of testCustomStruct and fire error")
|
||||
}
|
||||
|
||||
type testControllerViewResultRespectCtxViewData struct {
|
||||
|
|
|
@ -28,23 +28,23 @@ func TestControllerOverlap(t *testing.T) {
|
|||
}
|
||||
|
||||
e := httptest.New(t, app)
|
||||
e.GET("/user").Expect().Status(httptest.StatusUnauthorized).Body().Equal("unauth")
|
||||
e.GET("/user").Expect().Status(httptest.StatusUnauthorized).Body().IsEqual("unauth")
|
||||
// Test raw stop execution with a status code sent on the controller's method.
|
||||
e.GET("/user/with/status/on/method").Expect().Status(httptest.StatusBadRequest).Body().Equal("unauth")
|
||||
e.GET("/user/with/status/on/method").Expect().Status(httptest.StatusBadRequest).Body().IsEqual("unauth")
|
||||
// Test stop execution with status but last code sent through the controller's method.
|
||||
e.GET("/user/with/status/on/method/too").Expect().Status(httptest.StatusInternalServerError).Body().Equal("unauth")
|
||||
e.GET("/user/with/status/on/method/too").Expect().Status(httptest.StatusInternalServerError).Body().IsEqual("unauth")
|
||||
// Test raw stop execution and no status code sent on controller's method (should be OK).
|
||||
e.GET("/user/with/no/status").Expect().Status(httptest.StatusOK).Body().Equal("unauth")
|
||||
e.GET("/user/with/no/status").Expect().Status(httptest.StatusOK).Body().IsEqual("unauth")
|
||||
|
||||
// Test authenticated request.
|
||||
e.GET("/user").WithQuery("id", 42).Expect().Status(httptest.StatusOK).Body().Equal("auth: 42")
|
||||
e.GET("/user").WithQuery("id", 42).Expect().Status(httptest.StatusOK).Body().IsEqual("auth: 42")
|
||||
|
||||
// Test HandleHTTPError method accepts a not found and returns a 404
|
||||
// from a shared controller and overlapped, the url parameter matters because this method was overlapped.
|
||||
e.GET("/user/notfound").Expect().Status(httptest.StatusBadRequest).
|
||||
Body().Equal("error: *mvc_test.UnauthenticatedUserController: from: 404 to: 400")
|
||||
Body().IsEqual("error: *mvc_test.UnauthenticatedUserController: from: 404 to: 400")
|
||||
e.GET("/user/notfound").WithQuery("id", 42).Expect().Status(httptest.StatusBadRequest).
|
||||
Body().Equal("error: *mvc_test.AuthenticatedUserController: from: 404 to: 400")
|
||||
Body().IsEqual("error: *mvc_test.AuthenticatedUserController: from: 404 to: 400")
|
||||
}
|
||||
|
||||
type AuthenticatedTest uint64
|
||||
|
|
|
@ -82,13 +82,13 @@ func TestControllerMethodFuncs(t *testing.T) {
|
|||
for _, method := range router.AllMethods {
|
||||
|
||||
e.Request(method, "/").Expect().Status(iris.StatusOK).
|
||||
Body().Equal(method)
|
||||
Body().IsEqual(method)
|
||||
|
||||
e.Request(method, "/all").Expect().Status(iris.StatusOK).
|
||||
Body().Equal(method)
|
||||
Body().IsEqual(method)
|
||||
|
||||
e.Request(method, "/any").Expect().Status(iris.StatusOK).
|
||||
Body().Equal(method)
|
||||
Body().IsEqual(method)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -137,9 +137,9 @@ func TestControllerBeginAndEndRequestFunc(t *testing.T) {
|
|||
|
||||
for _, username := range usernames {
|
||||
e.GET("/profile/" + username).Expect().Status(iris.StatusOK).
|
||||
Body().Equal(username + doneResponse)
|
||||
Body().IsEqual(username + doneResponse)
|
||||
e.POST("/profile/" + username).Expect().Status(iris.StatusOK).
|
||||
Body().Equal(username + doneResponse)
|
||||
Body().IsEqual(username + doneResponse)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -178,17 +178,17 @@ func TestControllerBeginAndEndRequestFuncBindMiddleware(t *testing.T) {
|
|||
getEx := e.GET("/profile/" + username).Expect()
|
||||
if allow {
|
||||
getEx.Status(iris.StatusOK).
|
||||
Body().Equal(username + doneResponse)
|
||||
Body().IsEqual(username + doneResponse)
|
||||
} else {
|
||||
getEx.Status(iris.StatusForbidden).Body().Equal("forbidden")
|
||||
getEx.Status(iris.StatusForbidden).Body().IsEqual("forbidden")
|
||||
}
|
||||
|
||||
postEx := e.POST("/profile/" + username).Expect()
|
||||
if allow {
|
||||
postEx.Status(iris.StatusOK).
|
||||
Body().Equal(username + doneResponse)
|
||||
Body().IsEqual(username + doneResponse)
|
||||
} else {
|
||||
postEx.Status(iris.StatusForbidden).Body().Equal("forbidden")
|
||||
postEx.Status(iris.StatusForbidden).Body().IsEqual("forbidden")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -251,7 +251,7 @@ func TestControllerEndRequestAwareness(t *testing.T) {
|
|||
|
||||
for _, username := range usernames {
|
||||
e.GET("/era/" + username).Expect().Status(iris.StatusOK).
|
||||
Body().Equal(username + username + "2")
|
||||
Body().IsEqual(username + username + "2")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -315,17 +315,17 @@ func TestControllerDependencies(t *testing.T) {
|
|||
e := httptest.New(t, app)
|
||||
expected := t1 + t2
|
||||
e.GET("/").Expect().Status(iris.StatusOK).
|
||||
Body().Equal(expected)
|
||||
Body().IsEqual(expected)
|
||||
e.GET("/ctx").Expect().Status(iris.StatusContinue)
|
||||
|
||||
e.GET("/deep").Expect().Status(iris.StatusOK).
|
||||
Body().Equal(expected)
|
||||
Body().IsEqual(expected)
|
||||
|
||||
e.POST("/deep").WithJSON(iris.Map{"name": "kataras"}).Expect().Status(iris.StatusOK).
|
||||
Body().Equal("kataras")
|
||||
Body().IsEqual("kataras")
|
||||
|
||||
e.POST("/deep").Expect().Status(iris.StatusBadRequest).
|
||||
Body().Equal("EOF")
|
||||
Body().IsEqual("EOF")
|
||||
}
|
||||
|
||||
type testCtrl0 struct {
|
||||
|
@ -381,7 +381,7 @@ func TestControllerInsideControllerRecursively(t *testing.T) {
|
|||
|
||||
e := httptest.New(t, app)
|
||||
e.GET("/user/" + username).Expect().
|
||||
Status(iris.StatusOK).Body().Equal(expected)
|
||||
Status(iris.StatusOK).Body().IsEqual(expected)
|
||||
}
|
||||
|
||||
type testControllerRelPathFromFunc struct{}
|
||||
|
@ -421,47 +421,47 @@ func TestControllerRelPathFromFunc(t *testing.T) {
|
|||
|
||||
e := httptest.New(t, app)
|
||||
e.GET("/").Expect().Status(iris.StatusOK).
|
||||
Body().Equal("GET:/")
|
||||
Body().IsEqual("GET:/")
|
||||
|
||||
e.GET("/18446744073709551615").Expect().Status(iris.StatusOK).
|
||||
Body().Equal("GET:/18446744073709551615")
|
||||
Body().IsEqual("GET:/18446744073709551615")
|
||||
e.GET("/uint8/ratio/255").Expect().Status(iris.StatusOK).
|
||||
Body().Equal("GET:/uint8/ratio/255")
|
||||
Body().IsEqual("GET:/uint8/ratio/255")
|
||||
e.GET("/uint8/ratio/256").Expect().Status(iris.StatusNotFound)
|
||||
e.GET("/int64/ratio/-42").Expect().Status(iris.StatusOK).
|
||||
Body().Equal("GET:/int64/ratio/-42")
|
||||
Body().IsEqual("GET:/int64/ratio/-42")
|
||||
e.GET("/something/true").Expect().Status(iris.StatusOK).
|
||||
Body().Equal("GET:/something/true")
|
||||
Body().IsEqual("GET:/something/true")
|
||||
e.GET("/something/false").Expect().Status(iris.StatusOK).
|
||||
Body().Equal("GET:/something/false")
|
||||
Body().IsEqual("GET:/something/false")
|
||||
e.GET("/something/truee").Expect().Status(iris.StatusNotFound)
|
||||
e.GET("/something/falsee").Expect().Status(iris.StatusNotFound)
|
||||
e.GET("/something/kataras/42").Expect().Status(iris.StatusOK).
|
||||
Body().Equal("GET:/something/kataras/42")
|
||||
Body().IsEqual("GET:/something/kataras/42")
|
||||
e.GET("/something/new/kataras/42").Expect().Status(iris.StatusOK).
|
||||
Body().Equal("GET:/something/new/kataras/42")
|
||||
Body().IsEqual("GET:/something/new/kataras/42")
|
||||
e.GET("/something/true/else/this/42").Expect().Status(iris.StatusOK).
|
||||
Body().Equal("GET:/something/true/else/this/42")
|
||||
Body().IsEqual("GET:/something/true/else/this/42")
|
||||
|
||||
e.GET("/login").Expect().Status(iris.StatusOK).
|
||||
Body().Equal("GET:/login")
|
||||
Body().IsEqual("GET:/login")
|
||||
e.POST("/login").Expect().Status(iris.StatusOK).
|
||||
Body().Equal("POST:/login")
|
||||
Body().IsEqual("POST:/login")
|
||||
e.GET("/admin/login").Expect().Status(iris.StatusOK).
|
||||
Body().Equal("GET:/admin/login")
|
||||
Body().IsEqual("GET:/admin/login")
|
||||
e.PUT("/something/into/this").Expect().Status(iris.StatusOK).
|
||||
Body().Equal("PUT:/something/into/this")
|
||||
Body().IsEqual("PUT:/something/into/this")
|
||||
e.GET("/42").Expect().Status(iris.StatusOK).
|
||||
Body().Equal("GET:/42")
|
||||
Body().IsEqual("GET:/42")
|
||||
e.GET("/anything/here").Expect().Status(iris.StatusOK).
|
||||
Body().Equal("GET:/anything/here")
|
||||
Body().IsEqual("GET:/anything/here")
|
||||
|
||||
e.GET("/location/x").Expect().Status(iris.StatusOK).
|
||||
Body().Equal("GET:/location/x")
|
||||
Body().IsEqual("GET:/location/x")
|
||||
e.GET("/location/x/y").Expect().Status(iris.StatusOK).
|
||||
Body().Equal("GET:/location/x/y")
|
||||
Body().IsEqual("GET:/location/x/y")
|
||||
e.GET("/location/z/42").Expect().Status(iris.StatusOK).
|
||||
Body().Equal("GET:/location/z/42")
|
||||
Body().IsEqual("GET:/location/z/42")
|
||||
}
|
||||
|
||||
type testControllerActivateListener struct {
|
||||
|
@ -502,16 +502,16 @@ func TestControllerActivateListener(t *testing.T) {
|
|||
|
||||
e := httptest.New(t, app)
|
||||
e.GET("/").Expect().Status(iris.StatusOK).
|
||||
Body().Equal("overrides the dependency but not the field")
|
||||
Body().IsEqual("overrides the dependency but not the field")
|
||||
e.GET("/me/tos-read").Expect().Status(iris.StatusOK).
|
||||
Body().Equal("MeTOSRead")
|
||||
Body().IsEqual("MeTOSRead")
|
||||
e.POST("/me/tos-read").Expect().Status(iris.StatusOK).
|
||||
Body().Equal("MeTOSRead")
|
||||
Body().IsEqual("MeTOSRead")
|
||||
|
||||
e.GET("/manual").Expect().Status(iris.StatusOK).
|
||||
Body().Equal("overrides the dependency but not the field")
|
||||
Body().IsEqual("overrides the dependency but not the field")
|
||||
e.GET("/manual2").Expect().Status(iris.StatusOK).
|
||||
Body().Equal("my manual title")
|
||||
Body().IsEqual("my manual title")
|
||||
}
|
||||
|
||||
type testControllerNotCreateNewDueManuallySettingAllFields struct {
|
||||
|
@ -550,7 +550,7 @@ func TestControllerNotCreateNewDueManuallySettingAllFields(t *testing.T) {
|
|||
|
||||
e := httptest.New(t, app)
|
||||
e.GET("/").Expect().Status(iris.StatusOK).
|
||||
Body().Equal("my title")
|
||||
Body().IsEqual("my title")
|
||||
}
|
||||
|
||||
type testControllerRequestScopedDependencies struct {
|
||||
|
@ -594,11 +594,11 @@ func TestControllerRequestScopedDependencies(t *testing.T) {
|
|||
|
||||
e := httptest.New(t, app)
|
||||
e.GET("/").WithQuery("name", "kataras").WithQuery("age", 27).
|
||||
Expect().Status(httptest.StatusOK).JSON().Equal(&testCustomStruct{
|
||||
Expect().Status(httptest.StatusOK).JSON().IsEqual(&testCustomStruct{
|
||||
Name: "kataras",
|
||||
Age: 27,
|
||||
})
|
||||
e.GET("/custom/context").Expect().Status(httptest.StatusOK).Body().Equal("test")
|
||||
e.GET("/custom/context").Expect().Status(httptest.StatusOK).Body().IsEqual("test")
|
||||
}
|
||||
|
||||
type (
|
||||
|
@ -637,7 +637,7 @@ func TestControllersInsideControllerDeep(t *testing.T) {
|
|||
m.Handle(new(FinalController))
|
||||
|
||||
e := httptest.New(t, app)
|
||||
e.GET("/something").Expect().Status(httptest.StatusOK).Body().Equal("foo bar")
|
||||
e.GET("/something").Expect().Status(httptest.StatusOK).Body().IsEqual("foo bar")
|
||||
}
|
||||
|
||||
type testApplicationDependency struct {
|
||||
|
@ -657,8 +657,8 @@ func TestApplicationDependency(t *testing.T) {
|
|||
m2.Handle(new(testApplicationDependency))
|
||||
|
||||
e := httptest.New(t, app)
|
||||
e.GET("/").Expect().Status(httptest.StatusOK).Body().Equal("app1")
|
||||
e.GET("/other").Expect().Status(httptest.StatusOK).Body().Equal("app2")
|
||||
e.GET("/").Expect().Status(httptest.StatusOK).Body().IsEqual("app1")
|
||||
e.GET("/other").Expect().Status(httptest.StatusOK).Body().IsEqual("app2")
|
||||
}
|
||||
|
||||
type testControllerMethodHandlerBindStruct struct{}
|
||||
|
@ -701,11 +701,11 @@ func TestControllerMethodHandlerBindStruct(t *testing.T) {
|
|||
manyData := []bindStructData{data, {"john doe"}}
|
||||
|
||||
e := httptest.New(t, app)
|
||||
e.GET("/data").WithQueryObject(data).Expect().Status(httptest.StatusOK).JSON().Equal(data)
|
||||
e.PATCH("/data").WithJSON(data).Expect().Status(httptest.StatusOK).JSON().Equal(data)
|
||||
e.POST("/data/42/slice").WithJSON(manyData).Expect().Status(httptest.StatusOK).JSON().Equal(manyData)
|
||||
e.POST("/data/42/slicetype").WithJSON(manyData).Expect().Status(httptest.StatusOK).JSON().Equal(manyData)
|
||||
e.POST("/data/42/slicetypeptr").WithJSON(manyData).Expect().Status(httptest.StatusOK).JSON().Equal(manyData)
|
||||
e.GET("/data").WithQueryObject(data).Expect().Status(httptest.StatusOK).JSON().IsEqual(data)
|
||||
e.PATCH("/data").WithJSON(data).Expect().Status(httptest.StatusOK).JSON().IsEqual(data)
|
||||
e.POST("/data/42/slice").WithJSON(manyData).Expect().Status(httptest.StatusOK).JSON().IsEqual(manyData)
|
||||
e.POST("/data/42/slicetype").WithJSON(manyData).Expect().Status(httptest.StatusOK).JSON().IsEqual(manyData)
|
||||
e.POST("/data/42/slicetypeptr").WithJSON(manyData).Expect().Status(httptest.StatusOK).JSON().IsEqual(manyData)
|
||||
// more tests inside the hero package itself.
|
||||
}
|
||||
|
||||
|
@ -721,7 +721,7 @@ func TestErrorHandlerContinue(t *testing.T) {
|
|||
WithFormField("username", "makis").
|
||||
WithFormField("age", "27").
|
||||
WithFormField("unknown", "continue").
|
||||
Expect().Status(httptest.StatusOK).Body().Equal("makis is 27 years old\n")
|
||||
Expect().Status(httptest.StatusOK).Body().IsEqual("makis is 27 years old\n")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -114,7 +114,7 @@ func testSessions(t *testing.T, app *iris.Application) {
|
|||
d.JSON().Object().Empty()
|
||||
|
||||
d = e.GET("/after_destroy_renew").Expect().Status(iris.StatusOK)
|
||||
d.Body().Equal("true")
|
||||
d.Body().IsEqual("true")
|
||||
d.Cookies().NotEmpty()
|
||||
|
||||
// set and clear again
|
||||
|
@ -123,7 +123,7 @@ func testSessions(t *testing.T, app *iris.Application) {
|
|||
|
||||
// test start on the same request but more than one times
|
||||
|
||||
e.GET("/multi_start_set_get").Expect().Status(iris.StatusOK).Body().Equal("value")
|
||||
e.GET("/multi_start_set_get").Expect().Status(iris.StatusOK).Body().IsEqual("value")
|
||||
}
|
||||
|
||||
func TestFlashMessages(t *testing.T) {
|
||||
|
@ -211,7 +211,7 @@ func TestFlashMessages(t *testing.T) {
|
|||
|
||||
// set again in order to take the single one ( we don't test Cookies.NotEmpty because httpexpect default conf reads that from the request-only)
|
||||
e.POST("/set").WithJSON(values).Expect().Status(iris.StatusOK)
|
||||
e.GET("/get_single").Expect().Status(iris.StatusOK).Body().Equal(valueSingleValue)
|
||||
e.GET("/get_single").Expect().Status(iris.StatusOK).Body().IsEqual(valueSingleValue)
|
||||
}
|
||||
|
||||
func TestSessionsUpdateExpiration(t *testing.T) {
|
||||
|
@ -268,11 +268,11 @@ func TestSessionsUpdateExpiration(t *testing.T) {
|
|||
|
||||
expectedResponse := response{SessionID: sessionID, Logged: true}
|
||||
e.GET("/get").Expect().Status(httptest.StatusOK).
|
||||
JSON().Equal(expectedResponse)
|
||||
JSON().IsEqual(expectedResponse)
|
||||
|
||||
tt = e.POST("/remember_me").Expect().Status(httptest.StatusOK)
|
||||
tt.Cookie(cookieName).MaxAge().InRange(23*time.Hour, 24*time.Hour)
|
||||
tt.JSON().Equal(expectedResponse)
|
||||
tt.JSON().IsEqual(expectedResponse)
|
||||
|
||||
// Test call `UpdateExpiration` when cookie is firstly created.
|
||||
e.GET("/destroy").Expect().Status(httptest.StatusOK)
|
||||
|
@ -312,7 +312,7 @@ func TestSessionsUpdateExpirationConcurrently(t *testing.T) {
|
|||
for i < 1000 {
|
||||
go func() {
|
||||
tt := e.GET("/get").Expect().Status(httptest.StatusOK)
|
||||
tt.Body().Equal(id)
|
||||
tt.Body().IsEqual(id)
|
||||
tt.Cookie(cookieName).MaxAge().InRange(29*time.Minute, 30*time.Minute)
|
||||
wg.Done()
|
||||
}()
|
||||
|
@ -320,6 +320,6 @@ func TestSessionsUpdateExpirationConcurrently(t *testing.T) {
|
|||
}
|
||||
wg.Wait()
|
||||
tt := e.GET("/get").Expect()
|
||||
tt.Status(httptest.StatusOK).Body().Equal(id)
|
||||
tt.Status(httptest.StatusOK).Body().IsEqual(id)
|
||||
tt.Cookie(cookieName).MaxAge().InRange(29*time.Minute, 30*time.Minute)
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ func TestDeprecated(t *testing.T) {
|
|||
e := httptest.New(t, app)
|
||||
|
||||
ex := e.GET("/").WithHeader(versioning.AcceptVersionHeaderKey, "1.0").Expect()
|
||||
ex.Status(iris.StatusOK).Body().Equal("1.0")
|
||||
ex.Status(iris.StatusOK).Body().IsEqual("1.0")
|
||||
ex.Header("X-API-Warn").Equal(opts.WarnMessage)
|
||||
expectedDateStr := opts.DeprecationDate.Format(app.ConfigurationReadOnly().GetTimeFormat())
|
||||
ex.Header("X-API-Deprecation-Date").Equal(expectedDateStr)
|
||||
|
|
|
@ -37,20 +37,20 @@ func TestNewGroup(t *testing.T) {
|
|||
e := httptest.New(t, app)
|
||||
|
||||
ex := e.GET("/api/user").WithHeader(versioning.AcceptVersionHeaderKey, "1.0.0").Expect()
|
||||
ex.Status(iris.StatusOK).Body().Equal(v10Response)
|
||||
ex.Status(iris.StatusOK).Body().IsEqual(v10Response)
|
||||
ex.Header("X-API-Warn").Equal(versioning.DefaultDeprecationOptions.WarnMessage)
|
||||
|
||||
e.GET("/api/user").WithHeader(versioning.AcceptVersionHeaderKey, "2.0.0").Expect().
|
||||
Status(iris.StatusOK).Body().Equal(v2Response)
|
||||
Status(iris.StatusOK).Body().IsEqual(v2Response)
|
||||
e.GET("/api/user").WithHeader(versioning.AcceptVersionHeaderKey, "2.1.0").Expect().
|
||||
Status(iris.StatusOK).Body().Equal(v2Response)
|
||||
Status(iris.StatusOK).Body().IsEqual(v2Response)
|
||||
e.GET("/api/user").WithHeader(versioning.AcceptVersionHeaderKey, "2.9.9").Expect().
|
||||
Status(iris.StatusOK).Body().Equal(v2Response)
|
||||
Status(iris.StatusOK).Body().IsEqual(v2Response)
|
||||
e.POST("/api/user").WithHeader(versioning.AcceptVersionHeaderKey, "2.0.0").Expect().
|
||||
Status(iris.StatusOK).Body().Equal(v2Response)
|
||||
Status(iris.StatusOK).Body().IsEqual(v2Response)
|
||||
e.PUT("/api/user/other").WithHeader(versioning.AcceptVersionHeaderKey, "2.9.0").Expect().
|
||||
Status(iris.StatusOK).Body().Equal(v2Response)
|
||||
Status(iris.StatusOK).Body().IsEqual(v2Response)
|
||||
|
||||
e.GET("/api/user").WithHeader(versioning.AcceptVersionHeaderKey, "3.0").Expect().
|
||||
Status(iris.StatusNotImplemented).Body().Equal("version not found")
|
||||
Status(iris.StatusNotImplemented).Body().IsEqual("version not found")
|
||||
}
|
||||
|
|
|
@ -33,27 +33,27 @@ func TestGetVersion(t *testing.T) {
|
|||
e := httptest.New(t, app)
|
||||
|
||||
e.GET("/").WithHeader(versioning.AcceptVersionHeaderKey, "1.0.0").Expect().
|
||||
Status(iris.StatusOK).Body().Equal("1.0.0")
|
||||
Status(iris.StatusOK).Body().IsEqual("1.0.0")
|
||||
e.GET("/").WithHeader(versioning.AcceptHeaderKey, "application/vnd.api+json; version=2.1.0").Expect().
|
||||
Status(iris.StatusOK).Body().Equal("2.1.0")
|
||||
Status(iris.StatusOK).Body().IsEqual("2.1.0")
|
||||
e.GET("/").WithHeader(versioning.AcceptHeaderKey, "application/vnd.api+json; version=2.1.0 ;other=dsa").Expect().
|
||||
Status(iris.StatusOK).Body().Equal("2.1.0")
|
||||
Status(iris.StatusOK).Body().IsEqual("2.1.0")
|
||||
e.GET("/").WithHeader(versioning.AcceptHeaderKey, "version=2.1.0").Expect().
|
||||
Status(iris.StatusOK).Body().Equal("2.1.0")
|
||||
Status(iris.StatusOK).Body().IsEqual("2.1.0")
|
||||
e.GET("/").WithHeader(versioning.AcceptHeaderKey, "version=1.0.0").Expect().
|
||||
Status(iris.StatusOK).Body().Equal("1.0.0")
|
||||
Status(iris.StatusOK).Body().IsEqual("1.0.0")
|
||||
|
||||
// unknown versions.
|
||||
e.GET("/").WithHeader(versioning.AcceptVersionHeaderKey, "").Expect().
|
||||
Status(iris.StatusOK).Body().Equal("")
|
||||
Status(iris.StatusOK).Body().IsEqual("")
|
||||
e.GET("/").WithHeader(versioning.AcceptHeaderKey, "application/vnd.api+json; version=").Expect().
|
||||
Status(iris.StatusOK).Body().Equal("")
|
||||
Status(iris.StatusOK).Body().IsEqual("")
|
||||
e.GET("/").WithHeader(versioning.AcceptHeaderKey, "application/vnd.api+json; version= ;other=dsa").Expect().
|
||||
Status(iris.StatusOK).Body().Equal("")
|
||||
Status(iris.StatusOK).Body().IsEqual("")
|
||||
e.GET("/").WithHeader(versioning.AcceptHeaderKey, "version=").Expect().
|
||||
Status(iris.StatusOK).Body().Equal("")
|
||||
Status(iris.StatusOK).Body().IsEqual("")
|
||||
|
||||
e.GET("/manual").Expect().Status(iris.StatusOK).Body().Equal("11.0.5")
|
||||
e.GET("/manual").Expect().Status(iris.StatusOK).Body().IsEqual("11.0.5")
|
||||
}
|
||||
|
||||
func TestVersionAliases(t *testing.T) {
|
||||
|
@ -87,21 +87,21 @@ func TestVersionAliases(t *testing.T) {
|
|||
e := httptest.New(t, app)
|
||||
|
||||
// Make sure the SetVersion still works.
|
||||
e.GET("/api/manual").Expect().Status(iris.StatusOK).Body().Equal("12.0.0")
|
||||
e.GET("/api/manual").Expect().Status(iris.StatusOK).Body().IsEqual("12.0.0")
|
||||
|
||||
// Test Empty default.
|
||||
e.GET("/api").WithHeader(versioning.AcceptVersionHeaderKey, "").Expect().
|
||||
Status(iris.StatusOK).Body().Equal("1.0.0")
|
||||
Status(iris.StatusOK).Body().IsEqual("1.0.0")
|
||||
// Test NotFound error, aliases are not responsible for that.
|
||||
e.GET("/api").WithHeader(versioning.AcceptVersionHeaderKey, "4.0.0").Expect().
|
||||
Status(iris.StatusNotImplemented).Body().Equal("version not found")
|
||||
Status(iris.StatusNotImplemented).Body().IsEqual("version not found")
|
||||
// Test "stage" alias.
|
||||
e.GET("/api").WithHeader(versioning.AcceptVersionHeaderKey, "stage").Expect().
|
||||
Status(iris.StatusOK).Body().Equal("2.0.0")
|
||||
Status(iris.StatusOK).Body().IsEqual("2.0.0")
|
||||
// Test version 2.
|
||||
e.GET("/api").WithHeader(versioning.AcceptVersionHeaderKey, "2.0.0").Expect().
|
||||
Status(iris.StatusOK).Body().Equal("2.0.0")
|
||||
Status(iris.StatusOK).Body().IsEqual("2.0.0")
|
||||
// Test version 3 (registered first).
|
||||
e.GET("/api").WithHeader(versioning.AcceptVersionHeaderKey, "3.1.0").Expect().
|
||||
Status(iris.StatusOK).Body().Equal("3.1.0")
|
||||
Status(iris.StatusOK).Body().IsEqual("3.1.0")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user