mirror of
https://github.com/kataras/iris.git
synced 2025-12-22 20:37:05 +00:00
This commit is contained in:
34
http_test.go
34
http_test.go
@@ -433,11 +433,11 @@ func TestMuxPathEscape(t *testing.T) {
|
||||
Expect().Status(StatusOK).Body().Equal("name=Sakamoto desu ga,highlight=text")
|
||||
}
|
||||
|
||||
func TestMuxEncodeURL(t *testing.T) {
|
||||
func TestMuxDecodeURL(t *testing.T) {
|
||||
initDefault()
|
||||
|
||||
Get("/encoding/:url", func(ctx *Context) {
|
||||
url := URLEncode(ctx.Param("url"))
|
||||
url := DecodeURL(ctx.Param("url"))
|
||||
ctx.SetStatusCode(StatusOK)
|
||||
ctx.Write(url)
|
||||
})
|
||||
@@ -562,6 +562,36 @@ func TestMuxAPI(t *testing.T) {
|
||||
e.DELETE("/users/" + userID).Expect().Status(StatusOK).Body().Equal(middlewareResponseText + "Delete By " + userID + "\n")
|
||||
}
|
||||
|
||||
func TestMuxAPIWithParty(t *testing.T) {
|
||||
initDefault()
|
||||
siteParty := Party("sites/:site")
|
||||
|
||||
middlewareResponseText := "I assume that you are authenticated\n"
|
||||
siteParty.API("/users", testUserAPI{}, func(ctx *Context) {
|
||||
ctx.Set("user", "username")
|
||||
ctx.Next()
|
||||
}, func(ctx *Context) {
|
||||
if ctx.Get("user") == "username" {
|
||||
ctx.Write(middlewareResponseText)
|
||||
ctx.Next()
|
||||
} else {
|
||||
ctx.SetStatusCode(StatusUnauthorized)
|
||||
}
|
||||
})
|
||||
|
||||
e := Tester(t)
|
||||
siteID := "1"
|
||||
apiPath := "/sites/" + siteID + "/users"
|
||||
userID := "4077"
|
||||
formname := "kataras"
|
||||
|
||||
e.GET(apiPath).Expect().Status(StatusOK).Body().Equal(middlewareResponseText + "Get Users\n")
|
||||
e.GET(apiPath + "/" + userID).Expect().Status(StatusOK).Body().Equal(middlewareResponseText + "Get By " + userID + "\n")
|
||||
e.PUT(apiPath).WithFormField("name", formname).Expect().Status(StatusOK).Body().Equal(middlewareResponseText + "Put, name: " + formname + "\n")
|
||||
e.POST(apiPath+"/"+userID).WithFormField("name", formname).Expect().Status(StatusOK).Body().Equal(middlewareResponseText + "Post By " + userID + ", name: " + formname + "\n")
|
||||
e.DELETE(apiPath + "/" + userID).Expect().Status(StatusOK).Body().Equal(middlewareResponseText + "Delete By " + userID + "\n")
|
||||
}
|
||||
|
||||
type myTestHandlerData struct {
|
||||
Sysname string // this will be the same for all requests
|
||||
Version int // this will be the same for all requests
|
||||
|
||||
Reference in New Issue
Block a user