2020-03-01 01:17:19 +01:00
|
|
|
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).
|
2023-07-08 01:08:18 +02:00
|
|
|
JSON().IsEqual(testOutput{ID: 42, Name: "my_email"})
|
2020-03-01 01:17:19 +01:00
|
|
|
|
|
|
|
// 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().
|
2023-07-08 01:08:18 +02:00
|
|
|
Status(httptest.StatusAccepted).Body().IsEmpty()
|
2020-03-01 01:17:19 +01:00
|
|
|
|
|
|
|
// it should stop the execution at the middleware and return the error's text.
|
|
|
|
e.POST("/42").WithJSON(testInput{Email: "error"}).Expect().
|
2023-07-08 01:08:18 +02:00
|
|
|
Status(httptest.StatusConflict).Body().IsEqual("my_error")
|
2020-03-01 01:17:19 +01:00
|
|
|
}
|