mirror of
https://github.com/kataras/iris.git
synced 2025-12-20 03:17:04 +00:00
Implement the Status Method Not Allowed for gorilla mux too and add some tests
Former-commit-id: b157bacfa15567b8c98f959f3359e025fdf1b205
This commit is contained in:
61
handler_test.go
Normal file
61
handler_test.go
Normal file
@@ -0,0 +1,61 @@
|
||||
// black-box
|
||||
package iris_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"gopkg.in/kataras/iris.v6"
|
||||
"gopkg.in/kataras/iris.v6/httptest"
|
||||
)
|
||||
|
||||
const testCustomHandlerParamName = "myparam"
|
||||
|
||||
type myTestHandlerData struct {
|
||||
Sysname string // this will be the same for all requests
|
||||
Version int // this will be the same for all requests
|
||||
URLParameter string // this will be different for each request
|
||||
}
|
||||
|
||||
type myTestCustomHandler struct {
|
||||
data myTestHandlerData
|
||||
}
|
||||
|
||||
func (m *myTestCustomHandler) Serve(ctx *iris.Context) {
|
||||
data := &m.data
|
||||
data.URLParameter = ctx.URLParam(testCustomHandlerParamName)
|
||||
ctx.JSON(iris.StatusOK, data)
|
||||
}
|
||||
|
||||
func TestCustomHandler(t *testing.T) {
|
||||
app := iris.New()
|
||||
app.Adapt(newTestNativeRouter())
|
||||
|
||||
myData := myTestHandlerData{
|
||||
Sysname: "Redhat",
|
||||
Version: 1,
|
||||
}
|
||||
app.Handle("GET", "/custom_handler_1", &myTestCustomHandler{myData})
|
||||
app.Handle("GET", "/custom_handler_2", &myTestCustomHandler{myData})
|
||||
|
||||
e := httptest.New(app, t, httptest.Debug(true))
|
||||
// two times per testRoute
|
||||
param1 := "thisimyparam1"
|
||||
expectedData1 := myData
|
||||
expectedData1.URLParameter = param1
|
||||
e.GET("/custom_handler_1/").WithQuery(testCustomHandlerParamName, param1).Expect().Status(iris.StatusOK).JSON().Equal(expectedData1)
|
||||
|
||||
param2 := "thisimyparam2"
|
||||
expectedData2 := myData
|
||||
expectedData2.URLParameter = param2
|
||||
e.GET("/custom_handler_1/").WithQuery(testCustomHandlerParamName, param2).Expect().Status(iris.StatusOK).JSON().Equal(expectedData2)
|
||||
|
||||
param3 := "thisimyparam3"
|
||||
expectedData3 := myData
|
||||
expectedData3.URLParameter = param3
|
||||
e.GET("/custom_handler_2/").WithQuery(testCustomHandlerParamName, param3).Expect().Status(iris.StatusOK).JSON().Equal(expectedData3)
|
||||
|
||||
param4 := "thisimyparam4"
|
||||
expectedData4 := myData
|
||||
expectedData4.URLParameter = param4
|
||||
e.GET("/custom_handler_2/").WithQuery(testCustomHandlerParamName, param4).Expect().Status(iris.StatusOK).JSON().Equal(expectedData4)
|
||||
}
|
||||
Reference in New Issue
Block a user