1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-18 02:17:05 +00:00

add iris.Minify middleware and Context.OnCloseErr/OnConnectionCloseErr

This commit is contained in:
Gerasimos (Makis) Maropoulos
2020-08-15 17:21:57 +03:00
parent ab226d925a
commit ef7d365e81
10 changed files with 178 additions and 4 deletions

View File

@@ -9,11 +9,18 @@ func main() {
func newApp() *iris.Application {
app := iris.New()
// Create the "test.mydomain.com" subdomain.
test := app.Subdomain("test")
// Register views for the test subdomain.
test.RegisterView(iris.HTML("./views", ".html").
Layout("layouts/test.layout.html"))
// Optionally, to minify the HTML5 error response.
// Note that minification might be slower, caching is advised.
test.UseError(iris.Minify)
// Register error code 404 handler.
test.OnErrorCode(iris.StatusNotFound, handleNotFoundTestSubdomain)
test.Get("/", testIndex)
return app

View File

@@ -0,0 +1,40 @@
package main
import (
"testing"
"github.com/kataras/iris/v12/httptest"
)
func TestSubdomainsHTTPErrorsView(t *testing.T) {
app := newApp()
// hard coded.
expectedHTMLResponse := `<html>
<head>
<title>Test Subdomain</title>
</head>
<body>
<div style="background-color: black; color: red">
<h1>Oups, you've got an error!</h1>
<div style="background-color: white; color: red">
<h1>Not Found</h1>
</div>
</div>
</body>
</html>`
e := httptest.New(t, app)
got := e.GET("/not_found").WithURL("http://test.mydomain.com").Expect().Status(httptest.StatusNotFound).
ContentType("text/html", "utf-8").Body().Raw()
if expected, _ := app.Minifier().String("text/html", expectedHTMLResponse); expected != got {
t.Fatalf("expected:\n'%s'\nbut got:\n'%s'", expected, got)
}
}