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

testing: add a 'Do' helper that accepts http.ResponseWriter and http.Request for integration with the standard net/http/httptest package for easier transition from net/http and other frameworks into Iris

Former-commit-id: 8ec6e3468affc28ce34c9bef6795b444fffa08c5
This commit is contained in:
Gerasimos (Makis) Maropoulos
2020-07-20 05:44:12 +03:00
parent 302597faac
commit beb67dc495
3 changed files with 53 additions and 0 deletions

View File

@@ -3,6 +3,7 @@ package main
import (
"testing"
"github.com/kataras/iris/v12"
"github.com/kataras/iris/v12/httptest"
)
@@ -28,3 +29,16 @@ func TestNewApp(t *testing.T) {
e.GET("/admin/settings").WithBasicAuth("invalidusername", "invalidpassword").
Expect().Status(httptest.StatusUnauthorized)
}
func TestHandlerUsingNetHTTP(t *testing.T) {
handler := func(ctx iris.Context) {
ctx.WriteString("Hello, World!")
}
w := httptest.NewRecorder()
r := httptest.NewRequest("GET", "/", nil)
httptest.Do(w, r, handler)
if expected, got := "Hello, World!", w.Body.String(); expected != got {
t.Fatalf("expected body: %s but got: %s", expected, got)
}
}