Skip to content

Commit

Permalink
fix #2158 and more
Browse files Browse the repository at this point in the history
  • Loading branch information
kataras committed Jul 7, 2023
1 parent 757e7fe commit 6add1ba
Show file tree
Hide file tree
Showing 79 changed files with 547 additions and 463 deletions.
6 changes: 3 additions & 3 deletions _examples/auth/basicauth/basic/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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").
Expand Down
8 changes: 4 additions & 4 deletions _examples/bootstrapper/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
4 changes: 2 additions & 2 deletions _examples/cookies/basic/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ 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)
t3.Body().Contains(cookieName)

t4 := e.GET(fmt.Sprintf("/cookies/%s", cookieName)).Expect().Status(httptest.StatusOK)
t4.Cookies().Empty()
t4.Body().Empty()
t4.Body().IsEmpty()
}
4 changes: 2 additions & 2 deletions _examples/cookies/options/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ 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)
t3.Body().Contains(fmt.Sprintf("cookie %s removed, value should be empty=%s", cookieName, ""))

t4 := e.GET(fmt.Sprintf("/get/%s", cookieName)).Expect().Status(httptest.StatusOK)
t4.Cookies().Empty()
t4.Body().Empty()
t4.Body().IsEmpty()
}
4 changes: 2 additions & 2 deletions _examples/cookies/securecookie/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ 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)
t3.Body().Contains(cookieName)

t4 := e.GET(fmt.Sprintf("/cookies/%s", cookieName)).Expect().Status(httptest.StatusOK)
t4.Cookies().Empty()
t4.Body().Empty()
t4.Body().IsEmpty()
}
6 changes: 3 additions & 3 deletions _examples/dependency-injection/basic/middleware/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
4 changes: 2 additions & 2 deletions _examples/file-server/basic/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand All @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion _examples/file-server/subdomain/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
24 changes: 12 additions & 12 deletions _examples/i18n/basic/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]")
}
8 changes: 4 additions & 4 deletions _examples/i18n/template-embedded/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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("Λογαριασμός Συνδέσεις")
}
8 changes: 4 additions & 4 deletions _examples/i18n/template/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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("Λογαριασμός Συνδέσεις")
}
2 changes: 1 addition & 1 deletion _examples/logging/json-logger/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}()
}
Expand Down
6 changes: 3 additions & 3 deletions _examples/mvc/authenticated-controller/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
4 changes: 2 additions & 2 deletions _examples/mvc/error-handler-http/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion _examples/mvc/grpc-compatible/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"})
}
6 changes: 3 additions & 3 deletions _examples/mvc/hello-world/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
12 changes: 6 additions & 6 deletions _examples/mvc/versioned-controller/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions _examples/request-body/read-body/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion _examples/request-body/read-custom-per-type/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion _examples/request-body/read-params/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Loading

0 comments on commit 6add1ba

Please sign in to comment.