Skip to content
Myr

gin_integration_test.go

This file

Path

gin_integration_test.go

608 lines · 23.0 KiB · Go

Last changed by

docs: align function comments with names (#4814)daixiheguubefore adoptione318c6a

History of this file

Take it

1// Copyright 2017 Manu Martinez-Almeida. All rights reserved.2// Use of this source code is governed by a MIT style3// license that can be found in the LICENSE file.45package gin67import (8	"bufio"9	"crypto/tls"10	"fmt"11	"html/template"12	"io"13	"net"14	"net/http"15	"net/http/httptest"16	"os"17	"path/filepath"18	"runtime"19	"strings"20	"sync"21	"testing"22	"time"2324	"github.com/stretchr/testify/assert"25	"github.com/stretchr/testify/require"26)2728// testRequest sends a request and validates its response.29// params[0]=url example:http://127.0.0.1:8080/index (cannot be empty)30// params[1]=response status (custom compare status) default:"200 OK"31// params[2]=response body (custom compare content)  default:"it worked"32func testRequest(t *testing.T, params ...string) {33	if len(params) == 0 {34		t.Fatal("url cannot be empty")35	}3637	tr := &http.Transport{38		TLSClientConfig: &tls.Config{39			InsecureSkipVerify: true,40		},41	}42	client := &http.Client{Transport: tr}4344	resp, err := client.Get(params[0])45	require.NoError(t, err)46	defer resp.Body.Close()4748	body, ioerr := io.ReadAll(resp.Body)49	require.NoError(t, ioerr)5051	responseStatus := "200 OK"52	if len(params) > 1 && params[1] != "" {53		responseStatus = params[1]54	}5556	responseBody := "it worked"57	if len(params) > 2 && params[2] != "" {58		responseBody = params[2]59	}6061	assert.Equal(t, responseStatus, resp.Status, "should get a "+responseStatus)62	if responseStatus == "200 OK" {63		assert.Equal(t, responseBody, string(body), "resp body should match")64	}65}6667func TestRunEmpty(t *testing.T) {68	os.Setenv("PORT", "")69	router := New()70	go func() {71		router.GET("/example", func(c *Context) { c.String(http.StatusOK, "it worked") })72		assert.NoError(t, router.Run())73	}()7475	// Wait for server to be ready with exponential backoff76	err := waitForServerReady("http://localhost:8080/example", 10)77	require.NoError(t, err, "server should start successfully")7879	require.Error(t, router.Run(":8080"))80	testRequest(t, "http://localhost:8080/example")81}8283func TestBadTrustedCIDRs(t *testing.T) {84	router := New()85	require.Error(t, router.SetTrustedProxies([]string{"hello/world"}))86}8788/* legacy tests89func TestBadTrustedCIDRsForRun(t *testing.T) {90	os.Setenv("PORT", "")91	router := New()92	router.TrustedProxies = []string{"hello/world"}93	require.Error(t, router.Run(":8080"))94}9596func TestBadTrustedCIDRsForRunUnix(t *testing.T) {97	router := New()98	router.TrustedProxies = []string{"hello/world"}99100	unixTestSocket := filepath.Join(os.TempDir(), "unix_unit_test")101102	defer os.Remove(unixTestSocket)103104	go func() {105		router.GET("/example", func(c *Context) { c.String(http.StatusOK, "it worked") })106		require.Error(t, router.RunUnix(unixTestSocket))107	}()108	// have to wait for the goroutine to start and run the server109	// otherwise the main thread will complete110	time.Sleep(5 * time.Millisecond)111}112113func TestBadTrustedCIDRsForRunFd(t *testing.T) {114	router := New()115	router.TrustedProxies = []string{"hello/world"}116117	addr, err := net.ResolveTCPAddr("tcp", "localhost:0")118	require.NoError(t, err)119	listener, err := net.ListenTCP("tcp", addr)120	require.NoError(t, err)121	socketFile, err := listener.File()122	require.NoError(t, err)123124	go func() {125		router.GET("/example", func(c *Context) { c.String(http.StatusOK, "it worked") })126		require.Error(t, router.RunFd(int(socketFile.Fd())))127	}()128	// have to wait for the goroutine to start and run the server129	// otherwise the main thread will complete130	time.Sleep(5 * time.Millisecond)131}132133func TestBadTrustedCIDRsForRunListener(t *testing.T) {134	router := New()135	router.TrustedProxies = []string{"hello/world"}136137	addr, err := net.ResolveTCPAddr("tcp", "localhost:0")138	require.NoError(t, err)139	listener, err := net.ListenTCP("tcp", addr)140	require.NoError(t, err)141	go func() {142		router.GET("/example", func(c *Context) { c.String(http.StatusOK, "it worked") })143		require.Error(t, router.RunListener(listener))144	}()145	// have to wait for the goroutine to start and run the server146	// otherwise the main thread will complete147	time.Sleep(5 * time.Millisecond)148}149150func TestBadTrustedCIDRsForRunTLS(t *testing.T) {151	os.Setenv("PORT", "")152	router := New()153	router.TrustedProxies = []string{"hello/world"}154	require.Error(t, router.RunTLS(":8080", "./testdata/certificate/cert.pem", "./testdata/certificate/key.pem"))155}156*/157158func TestRunTLS(t *testing.T) {159	router := New()160	go func() {161		router.GET("/example", func(c *Context) { c.String(http.StatusOK, "it worked") })162163		assert.NoError(t, router.RunTLS(":8443", "./testdata/certificate/cert.pem", "./testdata/certificate/key.pem"))164	}()165166	// have to wait for the goroutine to start and run the server167	// otherwise the main thread will complete168	time.Sleep(5 * time.Millisecond)169170	require.Error(t, router.RunTLS(":8443", "./testdata/certificate/cert.pem", "./testdata/certificate/key.pem"))171	testRequest(t, "https://localhost:8443/example")172}173174func TestPusher(t *testing.T) {175	html := template.Must(template.New("https").Parse(`176<html>177<head>178  <title>Https Test</title>179  <script src="/assets/app.js"></script>180</head>181<body>182  <h1 style="color:red;">Welcome, Ginner!</h1>183</body>184</html>185`))186187	router := New()188	router.Static("./assets", "./assets")189	router.SetHTMLTemplate(html)190191	go func() {192		router.GET("/pusher", func(c *Context) {193			if pusher := c.Writer.Pusher(); pusher != nil {194				err := pusher.Push("/assets/app.js", nil)195				assert.NoError(t, err)196			}197			c.String(http.StatusOK, "it worked")198		})199200		assert.NoError(t, router.RunTLS(":8449", "./testdata/certificate/cert.pem", "./testdata/certificate/key.pem"))201	}()202203	// have to wait for the goroutine to start and run the server204	// otherwise the main thread will complete205	time.Sleep(5 * time.Millisecond)206207	require.Error(t, router.RunTLS(":8449", "./testdata/certificate/cert.pem", "./testdata/certificate/key.pem"))208	testRequest(t, "https://localhost:8449/pusher")209}210211func TestRunEmptyWithEnv(t *testing.T) {212	os.Setenv("PORT", "3123")213	router := New()214	go func() {215		router.GET("/example", func(c *Context) { c.String(http.StatusOK, "it worked") })216		assert.NoError(t, router.Run())217	}()218219	// Wait for server to be ready with exponential backoff220	err := waitForServerReady("http://localhost:3123/example", 10)221	require.NoError(t, err, "server should start successfully")222223	require.Error(t, router.Run(":3123"))224	testRequest(t, "http://localhost:3123/example")225}226227func TestRunTooMuchParams(t *testing.T) {228	router := New()229	assert.Panics(t, func() {230		require.NoError(t, router.Run("2", "2"))231	})232}233234func TestRunWithPort(t *testing.T) {235	router := New()236	go func() {237		router.GET("/example", func(c *Context) { c.String(http.StatusOK, "it worked") })238		assert.NoError(t, router.Run(":5150"))239	}()240241	// Wait for server to be ready with exponential backoff242	err := waitForServerReady("http://localhost:5150/example", 10)243	require.NoError(t, err, "server should start successfully")244245	require.Error(t, router.Run(":5150"))246	testRequest(t, "http://localhost:5150/example")247}248249func TestUnixSocket(t *testing.T) {250	router := New()251252	unixTestSocket := filepath.Join(os.TempDir(), "unix_unit_test")253254	defer os.Remove(unixTestSocket)255256	go func() {257		router.GET("/example", func(c *Context) { c.String(http.StatusOK, "it worked") })258		assert.NoError(t, router.RunUnix(unixTestSocket))259	}()260	// have to wait for the goroutine to start and run the server261	// otherwise the main thread will complete262	time.Sleep(5 * time.Millisecond)263264	c, err := net.Dial("unix", unixTestSocket)265	require.NoError(t, err)266267	fmt.Fprint(c, "GET /example HTTP/1.0\r\n\r\n")268	scanner := bufio.NewScanner(c)269	var responseBuilder strings.Builder270	for scanner.Scan() {271		responseBuilder.WriteString(scanner.Text())272	}273	response := responseBuilder.String()274	assert.Contains(t, response, "HTTP/1.0 200", "should get a 200")275	assert.Contains(t, response, "it worked", "resp body should match")276}277278func TestBadUnixSocket(t *testing.T) {279	router := New()280	require.Error(t, router.RunUnix("#/tmp/unix_unit_test"))281}282283func TestRunQUIC(t *testing.T) {284	router := New()285	go func() {286		router.GET("/example", func(c *Context) { c.String(http.StatusOK, "it worked") })287288		assert.NoError(t, router.RunQUIC(":8443", "./testdata/certificate/cert.pem", "./testdata/certificate/key.pem"))289	}()290291	// have to wait for the goroutine to start and run the server292	// otherwise the main thread will complete293	time.Sleep(5 * time.Millisecond)294295	require.Error(t, router.RunQUIC(":8443", "./testdata/certificate/cert.pem", "./testdata/certificate/key.pem"))296	testRequest(t, "https://localhost:8443/example")297}298299func TestFileDescriptor(t *testing.T) {300	router := New()301302	addr, err := net.ResolveTCPAddr("tcp", "localhost:0")303	require.NoError(t, err)304	listener, err := net.ListenTCP("tcp", addr)305	require.NoError(t, err)306	socketFile, err := listener.File()307	if isWindows() {308		// not supported by windows, it is unimplemented now309		require.Error(t, err)310	} else {311		require.NoError(t, err)312	}313314	if socketFile == nil {315		return316	}317318	go func() {319		router.GET("/example", func(c *Context) { c.String(http.StatusOK, "it worked") })320		assert.NoError(t, router.RunFd(int(socketFile.Fd())))321	}()322	// have to wait for the goroutine to start and run the server323	// otherwise the main thread will complete324	time.Sleep(5 * time.Millisecond)325326	c, err := net.Dial("tcp", listener.Addr().String())327	require.NoError(t, err)328329	fmt.Fprintf(c, "GET /example HTTP/1.0\r\n\r\n")330	scanner := bufio.NewScanner(c)331	var responseBuilder strings.Builder332	for scanner.Scan() {333		responseBuilder.WriteString(scanner.Text())334	}335	response := responseBuilder.String()336	assert.Contains(t, response, "HTTP/1.0 200", "should get a 200")337	assert.Contains(t, response, "it worked", "resp body should match")338}339340func TestBadFileDescriptor(t *testing.T) {341	router := New()342	require.Error(t, router.RunFd(0))343}344345func TestListener(t *testing.T) {346	router := New()347	addr, err := net.ResolveTCPAddr("tcp", "localhost:0")348	require.NoError(t, err)349	listener, err := net.ListenTCP("tcp", addr)350	require.NoError(t, err)351	go func() {352		router.GET("/example", func(c *Context) { c.String(http.StatusOK, "it worked") })353		assert.NoError(t, router.RunListener(listener))354	}()355	// have to wait for the goroutine to start and run the server356	// otherwise the main thread will complete357	time.Sleep(5 * time.Millisecond)358359	c, err := net.Dial("tcp", listener.Addr().String())360	require.NoError(t, err)361362	fmt.Fprintf(c, "GET /example HTTP/1.0\r\n\r\n")363	scanner := bufio.NewScanner(c)364	var responseBuilder strings.Builder365	for scanner.Scan() {366		responseBuilder.WriteString(scanner.Text())367	}368	response := responseBuilder.String()369	assert.Contains(t, response, "HTTP/1.0 200", "should get a 200")370	assert.Contains(t, response, "it worked", "resp body should match")371}372373func TestBadListener(t *testing.T) {374	router := New()375	addr, err := net.ResolveTCPAddr("tcp", "localhost:10086")376	require.NoError(t, err)377	listener, err := net.ListenTCP("tcp", addr)378	require.NoError(t, err)379	listener.Close()380	require.Error(t, router.RunListener(listener))381}382383func TestWithHttptestWithAutoSelectedPort(t *testing.T) {384	router := New()385	router.GET("/example", func(c *Context) { c.String(http.StatusOK, "it worked") })386387	ts := httptest.NewServer(router)388	defer ts.Close()389390	testRequest(t, ts.URL+"/example")391}392393func TestConcurrentHandleContext(t *testing.T) {394	router := New()395	router.GET("/", func(c *Context) {396		c.Request.URL.Path = "/example"397		router.HandleContext(c)398	})399	router.GET("/example", func(c *Context) { c.String(http.StatusOK, "it worked") })400401	var wg sync.WaitGroup402	iterations := 200403	wg.Add(iterations)404	for range iterations {405		go func() {406			req, err := http.NewRequest(http.MethodGet, "/", nil)407			assert.NoError(t, err)408409			w := httptest.NewRecorder()410			router.ServeHTTP(w, req)411412			assert.Equal(t, "it worked", w.Body.String(), "resp body should match")413			assert.Equal(t, 200, w.Code, "should get a 200")414			wg.Done()415		}()416	}417	wg.Wait()418}419420// func TestWithHttptestWithSpecifiedPort(t *testing.T) {421// 	router := New()422// 	router.GET("/example", func(c *Context) { c.String(http.StatusOK, "it worked") })423424// 	l, _ := net.Listen("tcp", ":8033")425// 	ts := httptest.Server{426// 		Listener: l,427// 		Config:   &http.Server{Handler: router},428// 	}429// 	ts.Start()430// 	defer ts.Close()431432// 	testRequest(t, "http://localhost:8033/example")433// }434435func TestTreeRunDynamicRouting(t *testing.T) {436	router := New()437	router.GET("/aa/*xx", func(c *Context) { c.String(http.StatusOK, "/aa/*xx") })438	router.GET("/ab/*xx", func(c *Context) { c.String(http.StatusOK, "/ab/*xx") })439	router.GET("/", func(c *Context) { c.String(http.StatusOK, "home") })440	router.GET("/:cc", func(c *Context) { c.String(http.StatusOK, "/:cc") })441	router.GET("/c1/:dd/e", func(c *Context) { c.String(http.StatusOK, "/c1/:dd/e") })442	router.GET("/c1/:dd/e1", func(c *Context) { c.String(http.StatusOK, "/c1/:dd/e1") })443	router.GET("/c1/:dd/f1", func(c *Context) { c.String(http.StatusOK, "/c1/:dd/f1") })444	router.GET("/c1/:dd/f2", func(c *Context) { c.String(http.StatusOK, "/c1/:dd/f2") })445	router.GET("/:cc/cc", func(c *Context) { c.String(http.StatusOK, "/:cc/cc") })446	router.GET("/:cc/:dd/ee", func(c *Context) { c.String(http.StatusOK, "/:cc/:dd/ee") })447	router.GET("/:cc/:dd/f", func(c *Context) { c.String(http.StatusOK, "/:cc/:dd/f") })448	router.GET("/:cc/:dd/:ee/ff", func(c *Context) { c.String(http.StatusOK, "/:cc/:dd/:ee/ff") })449	router.GET("/:cc/:dd/:ee/:ff/gg", func(c *Context) { c.String(http.StatusOK, "/:cc/:dd/:ee/:ff/gg") })450	router.GET("/:cc/:dd/:ee/:ff/:gg/hh", func(c *Context) { c.String(http.StatusOK, "/:cc/:dd/:ee/:ff/:gg/hh") })451	router.GET("/get/test/abc/", func(c *Context) { c.String(http.StatusOK, "/get/test/abc/") })452	router.GET("/get/:param/abc/", func(c *Context) { c.String(http.StatusOK, "/get/:param/abc/") })453	router.GET("/something/:paramname/thirdthing", func(c *Context) { c.String(http.StatusOK, "/something/:paramname/thirdthing") })454	router.GET("/something/secondthing/test", func(c *Context) { c.String(http.StatusOK, "/something/secondthing/test") })455	router.GET("/get/abc", func(c *Context) { c.String(http.StatusOK, "/get/abc") })456	router.GET("/get/:param", func(c *Context) { c.String(http.StatusOK, "/get/:param") })457	router.GET("/get/abc/123abc", func(c *Context) { c.String(http.StatusOK, "/get/abc/123abc") })458	router.GET("/get/abc/:param", func(c *Context) { c.String(http.StatusOK, "/get/abc/:param") })459	router.GET("/get/abc/123abc/xxx8", func(c *Context) { c.String(http.StatusOK, "/get/abc/123abc/xxx8") })460	router.GET("/get/abc/123abc/:param", func(c *Context) { c.String(http.StatusOK, "/get/abc/123abc/:param") })461	router.GET("/get/abc/123abc/xxx8/1234", func(c *Context) { c.String(http.StatusOK, "/get/abc/123abc/xxx8/1234") })462	router.GET("/get/abc/123abc/xxx8/:param", func(c *Context) { c.String(http.StatusOK, "/get/abc/123abc/xxx8/:param") })463	router.GET("/get/abc/123abc/xxx8/1234/ffas", func(c *Context) { c.String(http.StatusOK, "/get/abc/123abc/xxx8/1234/ffas") })464	router.GET("/get/abc/123abc/xxx8/1234/:param", func(c *Context) { c.String(http.StatusOK, "/get/abc/123abc/xxx8/1234/:param") })465	router.GET("/get/abc/123abc/xxx8/1234/kkdd/12c", func(c *Context) { c.String(http.StatusOK, "/get/abc/123abc/xxx8/1234/kkdd/12c") })466	router.GET("/get/abc/123abc/xxx8/1234/kkdd/:param", func(c *Context) { c.String(http.StatusOK, "/get/abc/123abc/xxx8/1234/kkdd/:param") })467	router.GET("/get/abc/:param/test", func(c *Context) { c.String(http.StatusOK, "/get/abc/:param/test") })468	router.GET("/get/abc/123abd/:param", func(c *Context) { c.String(http.StatusOK, "/get/abc/123abd/:param") })469	router.GET("/get/abc/123abddd/:param", func(c *Context) { c.String(http.StatusOK, "/get/abc/123abddd/:param") })470	router.GET("/get/abc/123/:param", func(c *Context) { c.String(http.StatusOK, "/get/abc/123/:param") })471	router.GET("/get/abc/123abg/:param", func(c *Context) { c.String(http.StatusOK, "/get/abc/123abg/:param") })472	router.GET("/get/abc/123abf/:param", func(c *Context) { c.String(http.StatusOK, "/get/abc/123abf/:param") })473	router.GET("/get/abc/123abfff/:param", func(c *Context) { c.String(http.StatusOK, "/get/abc/123abfff/:param") })474475	ts := httptest.NewServer(router)476	defer ts.Close()477478	testRequest(t, ts.URL+"/", "", "home")479	testRequest(t, ts.URL+"/aa/aa", "", "/aa/*xx")480	testRequest(t, ts.URL+"/ab/ab", "", "/ab/*xx")481	testRequest(t, ts.URL+"/all", "", "/:cc")482	testRequest(t, ts.URL+"/all/cc", "", "/:cc/cc")483	testRequest(t, ts.URL+"/a/cc", "", "/:cc/cc")484	testRequest(t, ts.URL+"/c1/d/e", "", "/c1/:dd/e")485	testRequest(t, ts.URL+"/c1/d/e1", "", "/c1/:dd/e1")486	testRequest(t, ts.URL+"/c1/d/ee", "", "/:cc/:dd/ee")487	testRequest(t, ts.URL+"/c1/d/f", "", "/:cc/:dd/f")488	testRequest(t, ts.URL+"/c/d/ee", "", "/:cc/:dd/ee")489	testRequest(t, ts.URL+"/c/d/e/ff", "", "/:cc/:dd/:ee/ff")490	testRequest(t, ts.URL+"/c/d/e/f/gg", "", "/:cc/:dd/:ee/:ff/gg")491	testRequest(t, ts.URL+"/c/d/e/f/g/hh", "", "/:cc/:dd/:ee/:ff/:gg/hh")492	testRequest(t, ts.URL+"/cc/dd/ee/ff/gg/hh", "", "/:cc/:dd/:ee/:ff/:gg/hh")493	testRequest(t, ts.URL+"/a", "", "/:cc")494	testRequest(t, ts.URL+"/d", "", "/:cc")495	testRequest(t, ts.URL+"/ad", "", "/:cc")496	testRequest(t, ts.URL+"/dd", "", "/:cc")497	testRequest(t, ts.URL+"/aa", "", "/:cc")498	testRequest(t, ts.URL+"/aaa", "", "/:cc")499	testRequest(t, ts.URL+"/aaa/cc", "", "/:cc/cc")500	testRequest(t, ts.URL+"/ab", "", "/:cc")501	testRequest(t, ts.URL+"/abb", "", "/:cc")502	testRequest(t, ts.URL+"/abb/cc", "", "/:cc/cc")503	testRequest(t, ts.URL+"/dddaa", "", "/:cc")504	testRequest(t, ts.URL+"/allxxxx", "", "/:cc")505	testRequest(t, ts.URL+"/alldd", "", "/:cc")506	testRequest(t, ts.URL+"/cc/cc", "", "/:cc/cc")507	testRequest(t, ts.URL+"/ccc/cc", "", "/:cc/cc")508	testRequest(t, ts.URL+"/deedwjfs/cc", "", "/:cc/cc")509	testRequest(t, ts.URL+"/acllcc/cc", "", "/:cc/cc")510	testRequest(t, ts.URL+"/get/test/abc/", "", "/get/test/abc/")511	testRequest(t, ts.URL+"/get/testaa/abc/", "", "/get/:param/abc/")512	testRequest(t, ts.URL+"/get/te/abc/", "", "/get/:param/abc/")513	testRequest(t, ts.URL+"/get/xx/abc/", "", "/get/:param/abc/")514	testRequest(t, ts.URL+"/get/tt/abc/", "", "/get/:param/abc/")515	testRequest(t, ts.URL+"/get/a/abc/", "", "/get/:param/abc/")516	testRequest(t, ts.URL+"/get/t/abc/", "", "/get/:param/abc/")517	testRequest(t, ts.URL+"/get/aa/abc/", "", "/get/:param/abc/")518	testRequest(t, ts.URL+"/get/abas/abc/", "", "/get/:param/abc/")519	testRequest(t, ts.URL+"/something/secondthing/test", "", "/something/secondthing/test")520	testRequest(t, ts.URL+"/something/secondthingaaaa/thirdthing", "", "/something/:paramname/thirdthing")521	testRequest(t, ts.URL+"/something/abcdad/thirdthing", "", "/something/:paramname/thirdthing")522	testRequest(t, ts.URL+"/something/se/thirdthing", "", "/something/:paramname/thirdthing")523	testRequest(t, ts.URL+"/something/s/thirdthing", "", "/something/:paramname/thirdthing")524	testRequest(t, ts.URL+"/something/secondthing/thirdthing", "", "/something/:paramname/thirdthing")525	testRequest(t, ts.URL+"/get/abc", "", "/get/abc")526	testRequest(t, ts.URL+"/get/a", "", "/get/:param")527	testRequest(t, ts.URL+"/get/abz", "", "/get/:param")528	testRequest(t, ts.URL+"/get/12a", "", "/get/:param")529	testRequest(t, ts.URL+"/get/abcd", "", "/get/:param")530	testRequest(t, ts.URL+"/get/abc/123abc", "", "/get/abc/123abc")531	testRequest(t, ts.URL+"/get/abc/12", "", "/get/abc/:param")532	testRequest(t, ts.URL+"/get/abc/123ab", "", "/get/abc/:param")533	testRequest(t, ts.URL+"/get/abc/xyz", "", "/get/abc/:param")534	testRequest(t, ts.URL+"/get/abc/123abcddxx", "", "/get/abc/:param")535	testRequest(t, ts.URL+"/get/abc/123abc/xxx8", "", "/get/abc/123abc/xxx8")536	testRequest(t, ts.URL+"/get/abc/123abc/x", "", "/get/abc/123abc/:param")537	testRequest(t, ts.URL+"/get/abc/123abc/xxx", "", "/get/abc/123abc/:param")538	testRequest(t, ts.URL+"/get/abc/123abc/abc", "", "/get/abc/123abc/:param")539	testRequest(t, ts.URL+"/get/abc/123abc/xxx8xxas", "", "/get/abc/123abc/:param")540	testRequest(t, ts.URL+"/get/abc/123abc/xxx8/1234", "", "/get/abc/123abc/xxx8/1234")541	testRequest(t, ts.URL+"/get/abc/123abc/xxx8/1", "", "/get/abc/123abc/xxx8/:param")542	testRequest(t, ts.URL+"/get/abc/123abc/xxx8/123", "", "/get/abc/123abc/xxx8/:param")543	testRequest(t, ts.URL+"/get/abc/123abc/xxx8/78k", "", "/get/abc/123abc/xxx8/:param")544	testRequest(t, ts.URL+"/get/abc/123abc/xxx8/1234xxxd", "", "/get/abc/123abc/xxx8/:param")545	testRequest(t, ts.URL+"/get/abc/123abc/xxx8/1234/ffas", "", "/get/abc/123abc/xxx8/1234/ffas")546	testRequest(t, ts.URL+"/get/abc/123abc/xxx8/1234/f", "", "/get/abc/123abc/xxx8/1234/:param")547	testRequest(t, ts.URL+"/get/abc/123abc/xxx8/1234/ffa", "", "/get/abc/123abc/xxx8/1234/:param")548	testRequest(t, ts.URL+"/get/abc/123abc/xxx8/1234/kka", "", "/get/abc/123abc/xxx8/1234/:param")549	testRequest(t, ts.URL+"/get/abc/123abc/xxx8/1234/ffas321", "", "/get/abc/123abc/xxx8/1234/:param")550	testRequest(t, ts.URL+"/get/abc/123abc/xxx8/1234/kkdd/12c", "", "/get/abc/123abc/xxx8/1234/kkdd/12c")551	testRequest(t, ts.URL+"/get/abc/123abc/xxx8/1234/kkdd/1", "", "/get/abc/123abc/xxx8/1234/kkdd/:param")552	testRequest(t, ts.URL+"/get/abc/123abc/xxx8/1234/kkdd/12", "", "/get/abc/123abc/xxx8/1234/kkdd/:param")553	testRequest(t, ts.URL+"/get/abc/123abc/xxx8/1234/kkdd/12b", "", "/get/abc/123abc/xxx8/1234/kkdd/:param")554	testRequest(t, ts.URL+"/get/abc/123abc/xxx8/1234/kkdd/34", "", "/get/abc/123abc/xxx8/1234/kkdd/:param")555	testRequest(t, ts.URL+"/get/abc/123abc/xxx8/1234/kkdd/12c2e3", "", "/get/abc/123abc/xxx8/1234/kkdd/:param")556	testRequest(t, ts.URL+"/get/abc/12/test", "", "/get/abc/:param/test")557	testRequest(t, ts.URL+"/get/abc/123abdd/test", "", "/get/abc/:param/test")558	testRequest(t, ts.URL+"/get/abc/123abdddf/test", "", "/get/abc/:param/test")559	testRequest(t, ts.URL+"/get/abc/123ab/test", "", "/get/abc/:param/test")560	testRequest(t, ts.URL+"/get/abc/123abgg/test", "", "/get/abc/:param/test")561	testRequest(t, ts.URL+"/get/abc/123abff/test", "", "/get/abc/:param/test")562	testRequest(t, ts.URL+"/get/abc/123abffff/test", "", "/get/abc/:param/test")563	testRequest(t, ts.URL+"/get/abc/123abd/test", "", "/get/abc/123abd/:param")564	testRequest(t, ts.URL+"/get/abc/123abddd/test", "", "/get/abc/123abddd/:param")565	testRequest(t, ts.URL+"/get/abc/123/test22", "", "/get/abc/123/:param")566	testRequest(t, ts.URL+"/get/abc/123abg/test", "", "/get/abc/123abg/:param")567	testRequest(t, ts.URL+"/get/abc/123abf/testss", "", "/get/abc/123abf/:param")568	testRequest(t, ts.URL+"/get/abc/123abfff/te", "", "/get/abc/123abfff/:param")569	// 404 not found570	testRequest(t, ts.URL+"/c/d/e", "404 Not Found")571	testRequest(t, ts.URL+"/c/d/e1", "404 Not Found")572	testRequest(t, ts.URL+"/c/d/eee", "404 Not Found")573	testRequest(t, ts.URL+"/c1/d/eee", "404 Not Found")574	testRequest(t, ts.URL+"/c1/d/e2", "404 Not Found")575	testRequest(t, ts.URL+"/cc/dd/ee/ff/gg/hh1", "404 Not Found")576	testRequest(t, ts.URL+"/a/dd", "404 Not Found")577	testRequest(t, ts.URL+"/addr/dd/aa", "404 Not Found")578	testRequest(t, ts.URL+"/something/secondthing/121", "404 Not Found")579}580581func isWindows() bool {582	return runtime.GOOS == "windows"583}584585func TestEscapedColon(t *testing.T) {586	router := New()587	f := func(u string) {588		router.GET(u, func(c *Context) { c.String(http.StatusOK, u) })589	}590	f("/r/r\\:r")591	f("/r/r:r")592	f("/r/r/:r")593	f("/r/r/\\:r")594	f("/r/r/r\\:r")595	assert.Panics(t, func() {596		f("\\foo:")597	})598599	router.updateRouteTrees()600	ts := httptest.NewServer(router)601	defer ts.Close()602603	testRequest(t, ts.URL+"/r/r123", "", "/r/r:r")604	testRequest(t, ts.URL+"/r/r:r", "", "/r/r\\:r")605	testRequest(t, ts.URL+"/r/r/r123", "", "/r/r/:r")606	testRequest(t, ts.URL+"/r/r/:r", "", "/r/r/\\:r")607	testRequest(t, ts.URL+"/r/r/r:r", "", "/r/r/r\\:r")608}