1
0
mirror of https://github.com/kataras/iris.git synced 2026-01-20 02:16:08 +00:00

add the stale release

This commit is contained in:
Gerasimos (Makis) Maropoulos
2020-08-12 23:41:20 +03:00
parent 535fb6dc0d
commit 2a4ce876b6
793 changed files with 188 additions and 52415 deletions

View File

@@ -4,7 +4,7 @@ import (
"fmt"
"net/http"
"github.com/kataras/iris/v12/context"
"github.com/kataras/iris/context"
)
// FromStd converts native http.Handler & http.HandlerFunc to context.Handler.

View File

@@ -1,71 +0,0 @@
// black-box testing
package handlerconv_test
import (
stdContext "context"
"net/http"
"testing"
"github.com/kataras/iris/v12"
"github.com/kataras/iris/v12/context"
"github.com/kataras/iris/v12/core/handlerconv"
"github.com/kataras/iris/v12/httptest"
)
func TestFromStd(t *testing.T) {
expected := "ok"
std := func(w http.ResponseWriter, r *http.Request) {
_, err := w.Write([]byte(expected))
if err != nil {
t.Fatal(err)
}
}
h := handlerconv.FromStd(http.HandlerFunc(std))
hFunc := handlerconv.FromStd(std)
app := iris.New()
app.Get("/handler", h)
app.Get("/func", hFunc)
e := httptest.New(t, app)
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"
type contextKey string
stdWNext := func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
if username, password, ok := r.BasicAuth(); ok &&
username == basicauth && password == basicauth {
ctx := stdContext.WithValue(r.Context(), contextKey("key"), "ok")
next.ServeHTTP(w, r.WithContext(ctx))
return
}
w.WriteHeader(iris.StatusForbidden)
}
h := handlerconv.FromStdWithNext(stdWNext)
next := func(ctx *context.Context) {
ctx.WriteString(ctx.Request().Context().Value(contextKey("key")).(string))
}
app := iris.New()
app.Get("/handlerwithnext", h, next)
e := httptest.New(t, app)
e.GET("/handlerwithnext").
Expect().Status(iris.StatusForbidden)
e.GET("/handlerwithnext").WithBasicAuth(basicauth, basicauth).
Expect().Status(iris.StatusOK).Body().Equal(passed)
}