mirror of
https://github.com/kataras/iris.git
synced 2026-01-09 21:15:56 +00:00
a bit linting and some tests are online again
Former-commit-id: bd5463a169a36b078dba1c1b6e7dd3ffbd627617
This commit is contained in:
66
core/handlerconv/from_std_test.go
Normal file
66
core/handlerconv/from_std_test.go
Normal file
@@ -0,0 +1,66 @@
|
||||
// black-box testing
|
||||
package handlerconv_test
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/kataras/iris"
|
||||
"github.com/kataras/iris/context"
|
||||
"github.com/kataras/iris/core/handlerconv"
|
||||
"github.com/kataras/iris/httptest"
|
||||
)
|
||||
|
||||
func TestFromStd(t *testing.T) {
|
||||
expected := "ok"
|
||||
std := func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Write([]byte(expected))
|
||||
}
|
||||
|
||||
h := handlerconv.FromStd(http.HandlerFunc(std))
|
||||
|
||||
hFunc := handlerconv.FromStd(std)
|
||||
|
||||
app := iris.New()
|
||||
app.Get("/handler", h)
|
||||
app.Get("/func", hFunc)
|
||||
|
||||
e := httptest.New(app, t)
|
||||
|
||||
e.GET("/handler").
|
||||
Expect().Status(iris.StatusOK).Body().Equal(expected)
|
||||
|
||||
e.GET("/func").
|
||||
Expect().Status(iris.StatusOK).Body().Equal(expected)
|
||||
}
|
||||
|
||||
func TestFromStdWithNext(t *testing.T) {
|
||||
|
||||
basicauth := "secret"
|
||||
passed := "ok"
|
||||
|
||||
stdWNext := func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
|
||||
if username, password, ok := r.BasicAuth(); ok &&
|
||||
username == basicauth && password == basicauth {
|
||||
next.ServeHTTP(w, r)
|
||||
return
|
||||
}
|
||||
w.WriteHeader(iris.StatusForbidden)
|
||||
}
|
||||
|
||||
h := handlerconv.FromStdWithNext(stdWNext)
|
||||
next := func(ctx context.Context) {
|
||||
ctx.WriteString(passed)
|
||||
}
|
||||
|
||||
app := iris.New()
|
||||
app.Get("/handlerwithnext", h, next)
|
||||
|
||||
e := httptest.New(app, t)
|
||||
|
||||
e.GET("/handlerwithnext").
|
||||
Expect().Status(iris.StatusForbidden)
|
||||
|
||||
e.GET("/handlerwithnext").WithBasicAuth(basicauth, basicauth).
|
||||
Expect().Status(iris.StatusOK).Body().Equal(passed)
|
||||
}
|
||||
Reference in New Issue
Block a user