MCPcopy Create free account
hub / github.com/kataras/iris / TestStruct

Function TestStruct

hero/struct_test.go:33–54  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

31}
32
33func TestStruct(t *testing.T) {
34 app := iris.New()
35
36 b := New()
37 s := b.Struct(&testStruct{}, 0)
38
39 postHandler := s.MethodHandler("MyHandler", 0) // fallbacks such as {path} and {string} should registered first when same path.
40 app.Post("/{name:string}", postHandler)
41 postHandler2 := s.MethodHandler("MyHandler2", 0)
42 app.Post("/{id:int}", postHandler2)
43 postHandler3 := s.MethodHandler("MyHandler3", 0)
44 app.Post("/myHandler3", postHandler3)
45 getHandler := s.MethodHandler("MyHandler4", 0)
46 app.Get("/myHandler4", getHandler)
47
48 e := httptest.New(t, app)
49 e.POST("/" + input.Name).Expect().Status(httptest.StatusOK).JSON().IsEqual(expectedOutput)
50 path := fmt.Sprintf("/%d", expectedOutput.ID)
51 e.POST(path).WithJSON(input).Expect().Status(httptest.StatusOK).JSON().IsEqual(expectedOutput)
52 e.POST("/myHandler3").WithJSON(input).Expect().Status(httptest.StatusOK).JSON().IsEqual(expectedOutput)
53 e.GET("/myHandler4").Expect().Status(httptest.StatusOK).Body().IsEqual("MyHandler4")
54}
55
56type testStructErrorHandler struct{}
57

Callers

nothing calls this directly

Calls 10

NewFunction · 0.92
NewMethod · 0.80
MethodHandlerMethod · 0.80
StatusMethod · 0.80
NewFunction · 0.70
StructMethod · 0.65
PostMethod · 0.65
GetMethod · 0.65
BodyMethod · 0.65
JSONMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…