MCPcopy
hub / github.com/gin-gonic/gin / TestLiteralColonWithHTTPServer

Function TestLiteralColonWithHTTPServer

gin_test.go:1043–1068  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1041}
1042
1043func TestLiteralColonWithHTTPServer(t *testing.T) {
1044 SetMode(TestMode)
1045 router := New()
1046
1047 router.GET(`/test\:action`, func(c *Context) {
1048 c.JSON(http.StatusOK, H{"path": "literal_colon"})
1049 })
1050
1051 router.GET("/test/:param", func(c *Context) {
1052 c.JSON(http.StatusOK, H{"param": c.Param("param")})
1053 })
1054
1055 w := httptest.NewRecorder()
1056 req, _ := http.NewRequest(http.MethodGet, "/test:action", nil)
1057 router.ServeHTTP(w, req)
1058
1059 assert.Equal(t, http.StatusOK, w.Code)
1060 assert.Contains(t, w.Body.String(), "literal_colon")
1061
1062 w2 := httptest.NewRecorder()
1063 req2, _ := http.NewRequest(http.MethodGet, "/test/foo", nil)
1064 router.ServeHTTP(w2, req2)
1065
1066 assert.Equal(t, http.StatusOK, w2.Code)
1067 assert.Contains(t, w2.Body.String(), "foo")
1068}
1069
1070// Test that updateRouteTrees is called only once
1071func TestUpdateRouteTreesCalledOnce(t *testing.T) {

Callers

nothing calls this directly

Calls 7

SetModeFunction · 0.85
NewFunction · 0.85
ParamMethod · 0.80
GETMethod · 0.65
StringMethod · 0.65
JSONMethod · 0.45
ServeHTTPMethod · 0.45

Tested by

no test coverage detected