mirror of
https://github.com/kataras/iris.git
synced 2025-01-23 18:51:03 +01:00
5fc24812bc
total refactor of the hero and mvc packages, see README#Next (it's not completed yet) Former-commit-id: b85ae99cbfe5965ba919c1e15cf4989e787982c0
60 lines
1010 B
Go
60 lines
1010 B
Go
package hero_test
|
|
|
|
import (
|
|
"fmt"
|
|
"reflect"
|
|
"testing"
|
|
|
|
"github.com/kataras/iris/v12"
|
|
. "github.com/kataras/iris/v12/hero"
|
|
"github.com/kataras/iris/v12/httptest"
|
|
)
|
|
|
|
var errTyp = reflect.TypeOf((*error)(nil)).Elem()
|
|
|
|
// isError returns true if "typ" is type of `error`.
|
|
func isError(typ reflect.Type) bool {
|
|
return typ.Implements(errTyp)
|
|
}
|
|
|
|
type (
|
|
testInput struct {
|
|
Name string `json:"name"`
|
|
}
|
|
|
|
testOutput struct {
|
|
ID int `json:"id"`
|
|
Name string `json:"name"`
|
|
}
|
|
)
|
|
|
|
var (
|
|
fn = func(id int, in testInput) testOutput {
|
|
return testOutput{
|
|
ID: id,
|
|
Name: in.Name,
|
|
}
|
|
}
|
|
|
|
expectedOutput = testOutput{
|
|
ID: 42,
|
|
Name: "makis",
|
|
}
|
|
|
|
input = testInput{
|
|
Name: "makis",
|
|
}
|
|
)
|
|
|
|
func TestHeroHandler(t *testing.T) {
|
|
app := iris.New()
|
|
|
|
b := New()
|
|
postHandler := b.Handler(fn)
|
|
app.Post("/{id:int}", postHandler)
|
|
|
|
e := httptest.New(t, app)
|
|
path := fmt.Sprintf("/%d", expectedOutput.ID)
|
|
e.POST(path).WithJSON(input).Expect().Status(httptest.StatusOK).JSON().Equal(expectedOutput)
|
|
}
|