func TestWithHttptestWithSpecifiedPort(t *testing.T) { router := New() router.GET("/example", func(c *Context) { c.String(http.StatusOK, "it worked") }) l, _ := net.Listen("tcp", ":8033") ts := httptest.Server{ Listener: l, Config: &http.Server{Handler: router}, } ts.Start() defer ts.Cl
(t *testing.T)
| 432 | // } |
| 433 | |
| 434 | func TestTreeRunDynamicRouting(t *testing.T) { |
| 435 | router := New() |
| 436 | router.GET("/aa/*xx", func(c *Context) { c.String(http.StatusOK, "/aa/*xx") }) |
| 437 | router.GET("/ab/*xx", func(c *Context) { c.String(http.StatusOK, "/ab/*xx") }) |
| 438 | router.GET("/", func(c *Context) { c.String(http.StatusOK, "home") }) |
| 439 | router.GET("/:cc", func(c *Context) { c.String(http.StatusOK, "/:cc") }) |
| 440 | router.GET("/c1/:dd/e", func(c *Context) { c.String(http.StatusOK, "/c1/:dd/e") }) |
| 441 | router.GET("/c1/:dd/e1", func(c *Context) { c.String(http.StatusOK, "/c1/:dd/e1") }) |
| 442 | router.GET("/c1/:dd/f1", func(c *Context) { c.String(http.StatusOK, "/c1/:dd/f1") }) |
| 443 | router.GET("/c1/:dd/f2", func(c *Context) { c.String(http.StatusOK, "/c1/:dd/f2") }) |
| 444 | router.GET("/:cc/cc", func(c *Context) { c.String(http.StatusOK, "/:cc/cc") }) |
| 445 | router.GET("/:cc/:dd/ee", func(c *Context) { c.String(http.StatusOK, "/:cc/:dd/ee") }) |
| 446 | router.GET("/:cc/:dd/f", func(c *Context) { c.String(http.StatusOK, "/:cc/:dd/f") }) |
| 447 | router.GET("/:cc/:dd/:ee/ff", func(c *Context) { c.String(http.StatusOK, "/:cc/:dd/:ee/ff") }) |
| 448 | router.GET("/:cc/:dd/:ee/:ff/gg", func(c *Context) { c.String(http.StatusOK, "/:cc/:dd/:ee/:ff/gg") }) |
| 449 | router.GET("/:cc/:dd/:ee/:ff/:gg/hh", func(c *Context) { c.String(http.StatusOK, "/:cc/:dd/:ee/:ff/:gg/hh") }) |
| 450 | router.GET("/get/test/abc/", func(c *Context) { c.String(http.StatusOK, "/get/test/abc/") }) |
| 451 | router.GET("/get/:param/abc/", func(c *Context) { c.String(http.StatusOK, "/get/:param/abc/") }) |
| 452 | router.GET("/something/:paramname/thirdthing", func(c *Context) { c.String(http.StatusOK, "/something/:paramname/thirdthing") }) |
| 453 | router.GET("/something/secondthing/test", func(c *Context) { c.String(http.StatusOK, "/something/secondthing/test") }) |
| 454 | router.GET("/get/abc", func(c *Context) { c.String(http.StatusOK, "/get/abc") }) |
| 455 | router.GET("/get/:param", func(c *Context) { c.String(http.StatusOK, "/get/:param") }) |
| 456 | router.GET("/get/abc/123abc", func(c *Context) { c.String(http.StatusOK, "/get/abc/123abc") }) |
| 457 | router.GET("/get/abc/:param", func(c *Context) { c.String(http.StatusOK, "/get/abc/:param") }) |
| 458 | router.GET("/get/abc/123abc/xxx8", func(c *Context) { c.String(http.StatusOK, "/get/abc/123abc/xxx8") }) |
| 459 | router.GET("/get/abc/123abc/:param", func(c *Context) { c.String(http.StatusOK, "/get/abc/123abc/:param") }) |
| 460 | router.GET("/get/abc/123abc/xxx8/1234", func(c *Context) { c.String(http.StatusOK, "/get/abc/123abc/xxx8/1234") }) |
| 461 | router.GET("/get/abc/123abc/xxx8/:param", func(c *Context) { c.String(http.StatusOK, "/get/abc/123abc/xxx8/:param") }) |
| 462 | router.GET("/get/abc/123abc/xxx8/1234/ffas", func(c *Context) { c.String(http.StatusOK, "/get/abc/123abc/xxx8/1234/ffas") }) |
| 463 | router.GET("/get/abc/123abc/xxx8/1234/:param", func(c *Context) { c.String(http.StatusOK, "/get/abc/123abc/xxx8/1234/:param") }) |
| 464 | router.GET("/get/abc/123abc/xxx8/1234/kkdd/12c", func(c *Context) { c.String(http.StatusOK, "/get/abc/123abc/xxx8/1234/kkdd/12c") }) |
| 465 | router.GET("/get/abc/123abc/xxx8/1234/kkdd/:param", func(c *Context) { c.String(http.StatusOK, "/get/abc/123abc/xxx8/1234/kkdd/:param") }) |
| 466 | router.GET("/get/abc/:param/test", func(c *Context) { c.String(http.StatusOK, "/get/abc/:param/test") }) |
| 467 | router.GET("/get/abc/123abd/:param", func(c *Context) { c.String(http.StatusOK, "/get/abc/123abd/:param") }) |
| 468 | router.GET("/get/abc/123abddd/:param", func(c *Context) { c.String(http.StatusOK, "/get/abc/123abddd/:param") }) |
| 469 | router.GET("/get/abc/123/:param", func(c *Context) { c.String(http.StatusOK, "/get/abc/123/:param") }) |
| 470 | router.GET("/get/abc/123abg/:param", func(c *Context) { c.String(http.StatusOK, "/get/abc/123abg/:param") }) |
| 471 | router.GET("/get/abc/123abf/:param", func(c *Context) { c.String(http.StatusOK, "/get/abc/123abf/:param") }) |
| 472 | router.GET("/get/abc/123abfff/:param", func(c *Context) { c.String(http.StatusOK, "/get/abc/123abfff/:param") }) |
| 473 | |
| 474 | ts := httptest.NewServer(router) |
| 475 | defer ts.Close() |
| 476 | |
| 477 | testRequest(t, ts.URL+"/", "", "home") |
| 478 | testRequest(t, ts.URL+"/aa/aa", "", "/aa/*xx") |
| 479 | testRequest(t, ts.URL+"/ab/ab", "", "/ab/*xx") |
| 480 | testRequest(t, ts.URL+"/all", "", "/:cc") |
| 481 | testRequest(t, ts.URL+"/all/cc", "", "/:cc/cc") |
| 482 | testRequest(t, ts.URL+"/a/cc", "", "/:cc/cc") |
| 483 | testRequest(t, ts.URL+"/c1/d/e", "", "/c1/:dd/e") |
| 484 | testRequest(t, ts.URL+"/c1/d/e1", "", "/c1/:dd/e1") |
| 485 | testRequest(t, ts.URL+"/c1/d/ee", "", "/:cc/:dd/ee") |
| 486 | testRequest(t, ts.URL+"/c1/d/f", "", "/:cc/:dd/f") |
| 487 | testRequest(t, ts.URL+"/c/d/ee", "", "/:cc/:dd/ee") |
| 488 | testRequest(t, ts.URL+"/c/d/e/ff", "", "/:cc/:dd/:ee/ff") |
| 489 | testRequest(t, ts.URL+"/c/d/e/f/gg", "", "/:cc/:dd/:ee/:ff/gg") |
| 490 | testRequest(t, ts.URL+"/c/d/e/f/g/hh", "", "/:cc/:dd/:ee/:ff/:gg/hh") |
| 491 | testRequest(t, ts.URL+"/cc/dd/ee/ff/gg/hh", "", "/:cc/:dd/:ee/:ff/:gg/hh") |
nothing calls this directly
no test coverage detected