mirror of
https://github.com/kataras/iris.git
synced 2025-12-18 02:17:05 +00:00
❤️ awesome and unique features for end-developers are coming...
total refactor of the hero and mvc packages, see README#Next (it's not completed yet) Former-commit-id: b85ae99cbfe5965ba919c1e15cf4989e787982c0
This commit is contained in:
59
hero/container_test.go
Normal file
59
hero/container_test.go
Normal file
@@ -0,0 +1,59 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user