| 1041 | } |
| 1042 | |
| 1043 | func 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 |
| 1071 | func TestUpdateRouteTreesCalledOnce(t *testing.T) { |