1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-18 10:27:06 +00:00

add a dependency-injection examples folder for the next release and some improvements

Former-commit-id: 040168afb7caf808618f7da5e68ae8eb01cb7170
This commit is contained in:
Gerasimos (Makis) Maropoulos
2020-03-01 02:17:19 +02:00
parent 5fc24812bc
commit ce2eae9121
19 changed files with 214 additions and 76 deletions

View File

@@ -0,0 +1,25 @@
package main
import (
"testing"
"github.com/kataras/iris/v12/httptest"
)
func TestDependencyInjectionBasic_Middleware(t *testing.T) {
app := newApp()
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"})
// 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()
// 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")
}