...

Source file src/github.com/gin-gonic/gin/gin_integration_test.go

Documentation: github.com/gin-gonic/gin

     1  // Copyright 2017 Manu Martinez-Almeida. All rights reserved.
     2  // Use of this source code is governed by a MIT style
     3  // license that can be found in the LICENSE file.
     4  
     5  package gin
     6  
     7  import (
     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  	"sync"
    20  	"testing"
    21  	"time"
    22  
    23  	"github.com/stretchr/testify/assert"
    24  )
    25  
    26  // params[0]=url example:http://127.0.0.1:8080/index (cannot be empty)
    27  // params[1]=response status (custom compare status) default:"200 OK"
    28  // params[2]=response body (custom compare content)  default:"it worked"
    29  func testRequest(t *testing.T, params ...string) {
    30  
    31  	if len(params) == 0 {
    32  		t.Fatal("url cannot be empty")
    33  	}
    34  
    35  	tr := &http.Transport{
    36  		TLSClientConfig: &tls.Config{
    37  			InsecureSkipVerify: true,
    38  		},
    39  	}
    40  	client := &http.Client{Transport: tr}
    41  
    42  	resp, err := client.Get(params[0])
    43  	assert.NoError(t, err)
    44  	defer resp.Body.Close()
    45  
    46  	body, ioerr := io.ReadAll(resp.Body)
    47  	assert.NoError(t, ioerr)
    48  
    49  	var responseStatus = "200 OK"
    50  	if len(params) > 1 && params[1] != "" {
    51  		responseStatus = params[1]
    52  	}
    53  
    54  	var responseBody = "it worked"
    55  	if len(params) > 2 && params[2] != "" {
    56  		responseBody = params[2]
    57  	}
    58  
    59  	assert.Equal(t, responseStatus, resp.Status, "should get a "+responseStatus)
    60  	if responseStatus == "200 OK" {
    61  		assert.Equal(t, responseBody, string(body), "resp body should match")
    62  	}
    63  }
    64  
    65  func TestRunEmpty(t *testing.T) {
    66  	os.Setenv("PORT", "")
    67  	router := New()
    68  	go func() {
    69  		router.GET("/example", func(c *Context) { c.String(http.StatusOK, "it worked") })
    70  		assert.NoError(t, router.Run())
    71  	}()
    72  	// have to wait for the goroutine to start and run the server
    73  	// otherwise the main thread will complete
    74  	time.Sleep(5 * time.Millisecond)
    75  
    76  	assert.Error(t, router.Run(":8080"))
    77  	testRequest(t, "http://localhost:8080/example")
    78  }
    79  
    80  func TestBadTrustedCIDRs(t *testing.T) {
    81  	router := New()
    82  	assert.Error(t, router.SetTrustedProxies([]string{"hello/world"}))
    83  }
    84  
    85  /* legacy tests
    86  func TestBadTrustedCIDRsForRun(t *testing.T) {
    87  	os.Setenv("PORT", "")
    88  	router := New()
    89  	router.TrustedProxies = []string{"hello/world"}
    90  	assert.Error(t, router.Run(":8080"))
    91  }
    92  
    93  func TestBadTrustedCIDRsForRunUnix(t *testing.T) {
    94  	router := New()
    95  	router.TrustedProxies = []string{"hello/world"}
    96  
    97  	unixTestSocket := filepath.Join(os.TempDir(), "unix_unit_test")
    98  
    99  	defer os.Remove(unixTestSocket)
   100  
   101  	go func() {
   102  		router.GET("/example", func(c *Context) { c.String(http.StatusOK, "it worked") })
   103  		assert.Error(t, router.RunUnix(unixTestSocket))
   104  	}()
   105  	// have to wait for the goroutine to start and run the server
   106  	// otherwise the main thread will complete
   107  	time.Sleep(5 * time.Millisecond)
   108  }
   109  
   110  func TestBadTrustedCIDRsForRunFd(t *testing.T) {
   111  	router := New()
   112  	router.TrustedProxies = []string{"hello/world"}
   113  
   114  	addr, err := net.ResolveTCPAddr("tcp", "localhost:0")
   115  	assert.NoError(t, err)
   116  	listener, err := net.ListenTCP("tcp", addr)
   117  	assert.NoError(t, err)
   118  	socketFile, err := listener.File()
   119  	assert.NoError(t, err)
   120  
   121  	go func() {
   122  		router.GET("/example", func(c *Context) { c.String(http.StatusOK, "it worked") })
   123  		assert.Error(t, router.RunFd(int(socketFile.Fd())))
   124  	}()
   125  	// have to wait for the goroutine to start and run the server
   126  	// otherwise the main thread will complete
   127  	time.Sleep(5 * time.Millisecond)
   128  }
   129  
   130  func TestBadTrustedCIDRsForRunListener(t *testing.T) {
   131  	router := New()
   132  	router.TrustedProxies = []string{"hello/world"}
   133  
   134  	addr, err := net.ResolveTCPAddr("tcp", "localhost:0")
   135  	assert.NoError(t, err)
   136  	listener, err := net.ListenTCP("tcp", addr)
   137  	assert.NoError(t, err)
   138  	go func() {
   139  		router.GET("/example", func(c *Context) { c.String(http.StatusOK, "it worked") })
   140  		assert.Error(t, router.RunListener(listener))
   141  	}()
   142  	// have to wait for the goroutine to start and run the server
   143  	// otherwise the main thread will complete
   144  	time.Sleep(5 * time.Millisecond)
   145  }
   146  
   147  func TestBadTrustedCIDRsForRunTLS(t *testing.T) {
   148  	os.Setenv("PORT", "")
   149  	router := New()
   150  	router.TrustedProxies = []string{"hello/world"}
   151  	assert.Error(t, router.RunTLS(":8080", "./testdata/certificate/cert.pem", "./testdata/certificate/key.pem"))
   152  }
   153  */
   154  
   155  func TestRunTLS(t *testing.T) {
   156  	router := New()
   157  	go func() {
   158  		router.GET("/example", func(c *Context) { c.String(http.StatusOK, "it worked") })
   159  
   160  		assert.NoError(t, router.RunTLS(":8443", "./testdata/certificate/cert.pem", "./testdata/certificate/key.pem"))
   161  	}()
   162  
   163  	// have to wait for the goroutine to start and run the server
   164  	// otherwise the main thread will complete
   165  	time.Sleep(5 * time.Millisecond)
   166  
   167  	assert.Error(t, router.RunTLS(":8443", "./testdata/certificate/cert.pem", "./testdata/certificate/key.pem"))
   168  	testRequest(t, "https://localhost:8443/example")
   169  }
   170  
   171  func TestPusher(t *testing.T) {
   172  	var html = template.Must(template.New("https").Parse(`
   173  <html>
   174  <head>
   175    <title>Https Test</title>
   176    <script src="/assets/app.js"></script>
   177  </head>
   178  <body>
   179    <h1 style="color:red;">Welcome, Ginner!</h1>
   180  </body>
   181  </html>
   182  `))
   183  
   184  	router := New()
   185  	router.Static("./assets", "./assets")
   186  	router.SetHTMLTemplate(html)
   187  
   188  	go func() {
   189  		router.GET("/pusher", func(c *Context) {
   190  			if pusher := c.Writer.Pusher(); pusher != nil {
   191  				err := pusher.Push("/assets/app.js", nil)
   192  				assert.NoError(t, err)
   193  			}
   194  			c.String(http.StatusOK, "it worked")
   195  		})
   196  
   197  		assert.NoError(t, router.RunTLS(":8449", "./testdata/certificate/cert.pem", "./testdata/certificate/key.pem"))
   198  	}()
   199  
   200  	// have to wait for the goroutine to start and run the server
   201  	// otherwise the main thread will complete
   202  	time.Sleep(5 * time.Millisecond)
   203  
   204  	assert.Error(t, router.RunTLS(":8449", "./testdata/certificate/cert.pem", "./testdata/certificate/key.pem"))
   205  	testRequest(t, "https://localhost:8449/pusher")
   206  }
   207  
   208  func TestRunEmptyWithEnv(t *testing.T) {
   209  	os.Setenv("PORT", "3123")
   210  	router := New()
   211  	go func() {
   212  		router.GET("/example", func(c *Context) { c.String(http.StatusOK, "it worked") })
   213  		assert.NoError(t, router.Run())
   214  	}()
   215  	// have to wait for the goroutine to start and run the server
   216  	// otherwise the main thread will complete
   217  	time.Sleep(5 * time.Millisecond)
   218  
   219  	assert.Error(t, router.Run(":3123"))
   220  	testRequest(t, "http://localhost:3123/example")
   221  }
   222  
   223  func TestRunTooMuchParams(t *testing.T) {
   224  	router := New()
   225  	assert.Panics(t, func() {
   226  		assert.NoError(t, router.Run("2", "2"))
   227  	})
   228  }
   229  
   230  func TestRunWithPort(t *testing.T) {
   231  	router := New()
   232  	go func() {
   233  		router.GET("/example", func(c *Context) { c.String(http.StatusOK, "it worked") })
   234  		assert.NoError(t, router.Run(":5150"))
   235  	}()
   236  	// have to wait for the goroutine to start and run the server
   237  	// otherwise the main thread will complete
   238  	time.Sleep(5 * time.Millisecond)
   239  
   240  	assert.Error(t, router.Run(":5150"))
   241  	testRequest(t, "http://localhost:5150/example")
   242  }
   243  
   244  func TestUnixSocket(t *testing.T) {
   245  	router := New()
   246  
   247  	unixTestSocket := filepath.Join(os.TempDir(), "unix_unit_test")
   248  
   249  	defer os.Remove(unixTestSocket)
   250  
   251  	go func() {
   252  		router.GET("/example", func(c *Context) { c.String(http.StatusOK, "it worked") })
   253  		assert.NoError(t, router.RunUnix(unixTestSocket))
   254  	}()
   255  	// have to wait for the goroutine to start and run the server
   256  	// otherwise the main thread will complete
   257  	time.Sleep(5 * time.Millisecond)
   258  
   259  	c, err := net.Dial("unix", unixTestSocket)
   260  	assert.NoError(t, err)
   261  
   262  	fmt.Fprint(c, "GET /example HTTP/1.0\r\n\r\n")
   263  	scanner := bufio.NewScanner(c)
   264  	var response string
   265  	for scanner.Scan() {
   266  		response += scanner.Text()
   267  	}
   268  	assert.Contains(t, response, "HTTP/1.0 200", "should get a 200")
   269  	assert.Contains(t, response, "it worked", "resp body should match")
   270  }
   271  
   272  func TestBadUnixSocket(t *testing.T) {
   273  	router := New()
   274  	assert.Error(t, router.RunUnix("#/tmp/unix_unit_test"))
   275  }
   276  
   277  func TestFileDescriptor(t *testing.T) {
   278  	router := New()
   279  
   280  	addr, err := net.ResolveTCPAddr("tcp", "localhost:0")
   281  	assert.NoError(t, err)
   282  	listener, err := net.ListenTCP("tcp", addr)
   283  	assert.NoError(t, err)
   284  	socketFile, err := listener.File()
   285  	if isWindows() {
   286  		// not supported by windows, it is unimplemented now
   287  		assert.Error(t, err)
   288  	} else {
   289  		assert.NoError(t, err)
   290  	}
   291  
   292  	if socketFile == nil {
   293  		return
   294  	}
   295  
   296  	go func() {
   297  		router.GET("/example", func(c *Context) { c.String(http.StatusOK, "it worked") })
   298  		assert.NoError(t, router.RunFd(int(socketFile.Fd())))
   299  	}()
   300  	// have to wait for the goroutine to start and run the server
   301  	// otherwise the main thread will complete
   302  	time.Sleep(5 * time.Millisecond)
   303  
   304  	c, err := net.Dial("tcp", listener.Addr().String())
   305  	assert.NoError(t, err)
   306  
   307  	fmt.Fprintf(c, "GET /example HTTP/1.0\r\n\r\n")
   308  	scanner := bufio.NewScanner(c)
   309  	var response string
   310  	for scanner.Scan() {
   311  		response += scanner.Text()
   312  	}
   313  	assert.Contains(t, response, "HTTP/1.0 200", "should get a 200")
   314  	assert.Contains(t, response, "it worked", "resp body should match")
   315  }
   316  
   317  func TestBadFileDescriptor(t *testing.T) {
   318  	router := New()
   319  	assert.Error(t, router.RunFd(0))
   320  }
   321  
   322  func TestListener(t *testing.T) {
   323  	router := New()
   324  	addr, err := net.ResolveTCPAddr("tcp", "localhost:0")
   325  	assert.NoError(t, err)
   326  	listener, err := net.ListenTCP("tcp", addr)
   327  	assert.NoError(t, err)
   328  	go func() {
   329  		router.GET("/example", func(c *Context) { c.String(http.StatusOK, "it worked") })
   330  		assert.NoError(t, router.RunListener(listener))
   331  	}()
   332  	// have to wait for the goroutine to start and run the server
   333  	// otherwise the main thread will complete
   334  	time.Sleep(5 * time.Millisecond)
   335  
   336  	c, err := net.Dial("tcp", listener.Addr().String())
   337  	assert.NoError(t, err)
   338  
   339  	fmt.Fprintf(c, "GET /example HTTP/1.0\r\n\r\n")
   340  	scanner := bufio.NewScanner(c)
   341  	var response string
   342  	for scanner.Scan() {
   343  		response += scanner.Text()
   344  	}
   345  	assert.Contains(t, response, "HTTP/1.0 200", "should get a 200")
   346  	assert.Contains(t, response, "it worked", "resp body should match")
   347  }
   348  
   349  func TestBadListener(t *testing.T) {
   350  	router := New()
   351  	addr, err := net.ResolveTCPAddr("tcp", "localhost:10086")
   352  	assert.NoError(t, err)
   353  	listener, err := net.ListenTCP("tcp", addr)
   354  	assert.NoError(t, err)
   355  	listener.Close()
   356  	assert.Error(t, router.RunListener(listener))
   357  }
   358  
   359  func TestWithHttptestWithAutoSelectedPort(t *testing.T) {
   360  	router := New()
   361  	router.GET("/example", func(c *Context) { c.String(http.StatusOK, "it worked") })
   362  
   363  	ts := httptest.NewServer(router)
   364  	defer ts.Close()
   365  
   366  	testRequest(t, ts.URL+"/example")
   367  }
   368  
   369  func TestConcurrentHandleContext(t *testing.T) {
   370  	router := New()
   371  	router.GET("/", func(c *Context) {
   372  		c.Request.URL.Path = "/example"
   373  		router.HandleContext(c)
   374  	})
   375  	router.GET("/example", func(c *Context) { c.String(http.StatusOK, "it worked") })
   376  
   377  	var wg sync.WaitGroup
   378  	iterations := 200
   379  	wg.Add(iterations)
   380  	for i := 0; i < iterations; i++ {
   381  		go func() {
   382  			testGetRequestHandler(t, router, "/")
   383  			wg.Done()
   384  		}()
   385  	}
   386  	wg.Wait()
   387  }
   388  
   389  // func TestWithHttptestWithSpecifiedPort(t *testing.T) {
   390  // 	router := New()
   391  // 	router.GET("/example", func(c *Context) { c.String(http.StatusOK, "it worked") })
   392  
   393  // 	l, _ := net.Listen("tcp", ":8033")
   394  // 	ts := httptest.Server{
   395  // 		Listener: l,
   396  // 		Config:   &http.Server{Handler: router},
   397  // 	}
   398  // 	ts.Start()
   399  // 	defer ts.Close()
   400  
   401  // 	testRequest(t, "http://localhost:8033/example")
   402  // }
   403  
   404  func testGetRequestHandler(t *testing.T, h http.Handler, url string) {
   405  	req, err := http.NewRequest(http.MethodGet, url, nil)
   406  	assert.NoError(t, err)
   407  
   408  	w := httptest.NewRecorder()
   409  	h.ServeHTTP(w, req)
   410  
   411  	assert.Equal(t, "it worked", w.Body.String(), "resp body should match")
   412  	assert.Equal(t, 200, w.Code, "should get a 200")
   413  }
   414  
   415  func TestTreeRunDynamicRouting(t *testing.T) {
   416  	router := New()
   417  	router.GET("/aa/*xx", func(c *Context) { c.String(http.StatusOK, "/aa/*xx") })
   418  	router.GET("/ab/*xx", func(c *Context) { c.String(http.StatusOK, "/ab/*xx") })
   419  	router.GET("/", func(c *Context) { c.String(http.StatusOK, "home") })
   420  	router.GET("/:cc", func(c *Context) { c.String(http.StatusOK, "/:cc") })
   421  	router.GET("/c1/:dd/e", func(c *Context) { c.String(http.StatusOK, "/c1/:dd/e") })
   422  	router.GET("/c1/:dd/e1", func(c *Context) { c.String(http.StatusOK, "/c1/:dd/e1") })
   423  	router.GET("/c1/:dd/f1", func(c *Context) { c.String(http.StatusOK, "/c1/:dd/f1") })
   424  	router.GET("/c1/:dd/f2", func(c *Context) { c.String(http.StatusOK, "/c1/:dd/f2") })
   425  	router.GET("/:cc/cc", func(c *Context) { c.String(http.StatusOK, "/:cc/cc") })
   426  	router.GET("/:cc/:dd/ee", func(c *Context) { c.String(http.StatusOK, "/:cc/:dd/ee") })
   427  	router.GET("/:cc/:dd/f", func(c *Context) { c.String(http.StatusOK, "/:cc/:dd/f") })
   428  	router.GET("/:cc/:dd/:ee/ff", func(c *Context) { c.String(http.StatusOK, "/:cc/:dd/:ee/ff") })
   429  	router.GET("/:cc/:dd/:ee/:ff/gg", func(c *Context) { c.String(http.StatusOK, "/:cc/:dd/:ee/:ff/gg") })
   430  	router.GET("/:cc/:dd/:ee/:ff/:gg/hh", func(c *Context) { c.String(http.StatusOK, "/:cc/:dd/:ee/:ff/:gg/hh") })
   431  	router.GET("/get/test/abc/", func(c *Context) { c.String(http.StatusOK, "/get/test/abc/") })
   432  	router.GET("/get/:param/abc/", func(c *Context) { c.String(http.StatusOK, "/get/:param/abc/") })
   433  	router.GET("/something/:paramname/thirdthing", func(c *Context) { c.String(http.StatusOK, "/something/:paramname/thirdthing") })
   434  	router.GET("/something/secondthing/test", func(c *Context) { c.String(http.StatusOK, "/something/secondthing/test") })
   435  	router.GET("/get/abc", func(c *Context) { c.String(http.StatusOK, "/get/abc") })
   436  	router.GET("/get/:param", func(c *Context) { c.String(http.StatusOK, "/get/:param") })
   437  	router.GET("/get/abc/123abc", func(c *Context) { c.String(http.StatusOK, "/get/abc/123abc") })
   438  	router.GET("/get/abc/:param", func(c *Context) { c.String(http.StatusOK, "/get/abc/:param") })
   439  	router.GET("/get/abc/123abc/xxx8", func(c *Context) { c.String(http.StatusOK, "/get/abc/123abc/xxx8") })
   440  	router.GET("/get/abc/123abc/:param", func(c *Context) { c.String(http.StatusOK, "/get/abc/123abc/:param") })
   441  	router.GET("/get/abc/123abc/xxx8/1234", func(c *Context) { c.String(http.StatusOK, "/get/abc/123abc/xxx8/1234") })
   442  	router.GET("/get/abc/123abc/xxx8/:param", func(c *Context) { c.String(http.StatusOK, "/get/abc/123abc/xxx8/:param") })
   443  	router.GET("/get/abc/123abc/xxx8/1234/ffas", func(c *Context) { c.String(http.StatusOK, "/get/abc/123abc/xxx8/1234/ffas") })
   444  	router.GET("/get/abc/123abc/xxx8/1234/:param", func(c *Context) { c.String(http.StatusOK, "/get/abc/123abc/xxx8/1234/:param") })
   445  	router.GET("/get/abc/123abc/xxx8/1234/kkdd/12c", func(c *Context) { c.String(http.StatusOK, "/get/abc/123abc/xxx8/1234/kkdd/12c") })
   446  	router.GET("/get/abc/123abc/xxx8/1234/kkdd/:param", func(c *Context) { c.String(http.StatusOK, "/get/abc/123abc/xxx8/1234/kkdd/:param") })
   447  	router.GET("/get/abc/:param/test", func(c *Context) { c.String(http.StatusOK, "/get/abc/:param/test") })
   448  	router.GET("/get/abc/123abd/:param", func(c *Context) { c.String(http.StatusOK, "/get/abc/123abd/:param") })
   449  	router.GET("/get/abc/123abddd/:param", func(c *Context) { c.String(http.StatusOK, "/get/abc/123abddd/:param") })
   450  	router.GET("/get/abc/123/:param", func(c *Context) { c.String(http.StatusOK, "/get/abc/123/:param") })
   451  	router.GET("/get/abc/123abg/:param", func(c *Context) { c.String(http.StatusOK, "/get/abc/123abg/:param") })
   452  	router.GET("/get/abc/123abf/:param", func(c *Context) { c.String(http.StatusOK, "/get/abc/123abf/:param") })
   453  	router.GET("/get/abc/123abfff/:param", func(c *Context) { c.String(http.StatusOK, "/get/abc/123abfff/:param") })
   454  
   455  	ts := httptest.NewServer(router)
   456  	defer ts.Close()
   457  
   458  	testRequest(t, ts.URL+"/", "", "home")
   459  	testRequest(t, ts.URL+"/aa/aa", "", "/aa/*xx")
   460  	testRequest(t, ts.URL+"/ab/ab", "", "/ab/*xx")
   461  	testRequest(t, ts.URL+"/all", "", "/:cc")
   462  	testRequest(t, ts.URL+"/all/cc", "", "/:cc/cc")
   463  	testRequest(t, ts.URL+"/a/cc", "", "/:cc/cc")
   464  	testRequest(t, ts.URL+"/c1/d/e", "", "/c1/:dd/e")
   465  	testRequest(t, ts.URL+"/c1/d/e1", "", "/c1/:dd/e1")
   466  	testRequest(t, ts.URL+"/c1/d/ee", "", "/:cc/:dd/ee")
   467  	testRequest(t, ts.URL+"/c1/d/f", "", "/:cc/:dd/f")
   468  	testRequest(t, ts.URL+"/c/d/ee", "", "/:cc/:dd/ee")
   469  	testRequest(t, ts.URL+"/c/d/e/ff", "", "/:cc/:dd/:ee/ff")
   470  	testRequest(t, ts.URL+"/c/d/e/f/gg", "", "/:cc/:dd/:ee/:ff/gg")
   471  	testRequest(t, ts.URL+"/c/d/e/f/g/hh", "", "/:cc/:dd/:ee/:ff/:gg/hh")
   472  	testRequest(t, ts.URL+"/cc/dd/ee/ff/gg/hh", "", "/:cc/:dd/:ee/:ff/:gg/hh")
   473  	testRequest(t, ts.URL+"/a", "", "/:cc")
   474  	testRequest(t, ts.URL+"/d", "", "/:cc")
   475  	testRequest(t, ts.URL+"/ad", "", "/:cc")
   476  	testRequest(t, ts.URL+"/dd", "", "/:cc")
   477  	testRequest(t, ts.URL+"/aa", "", "/:cc")
   478  	testRequest(t, ts.URL+"/aaa", "", "/:cc")
   479  	testRequest(t, ts.URL+"/aaa/cc", "", "/:cc/cc")
   480  	testRequest(t, ts.URL+"/ab", "", "/:cc")
   481  	testRequest(t, ts.URL+"/abb", "", "/:cc")
   482  	testRequest(t, ts.URL+"/abb/cc", "", "/:cc/cc")
   483  	testRequest(t, ts.URL+"/dddaa", "", "/:cc")
   484  	testRequest(t, ts.URL+"/allxxxx", "", "/:cc")
   485  	testRequest(t, ts.URL+"/alldd", "", "/:cc")
   486  	testRequest(t, ts.URL+"/cc/cc", "", "/:cc/cc")
   487  	testRequest(t, ts.URL+"/ccc/cc", "", "/:cc/cc")
   488  	testRequest(t, ts.URL+"/deedwjfs/cc", "", "/:cc/cc")
   489  	testRequest(t, ts.URL+"/acllcc/cc", "", "/:cc/cc")
   490  	testRequest(t, ts.URL+"/get/test/abc/", "", "/get/test/abc/")
   491  	testRequest(t, ts.URL+"/get/testaa/abc/", "", "/get/:param/abc/")
   492  	testRequest(t, ts.URL+"/get/te/abc/", "", "/get/:param/abc/")
   493  	testRequest(t, ts.URL+"/get/xx/abc/", "", "/get/:param/abc/")
   494  	testRequest(t, ts.URL+"/get/tt/abc/", "", "/get/:param/abc/")
   495  	testRequest(t, ts.URL+"/get/a/abc/", "", "/get/:param/abc/")
   496  	testRequest(t, ts.URL+"/get/t/abc/", "", "/get/:param/abc/")
   497  	testRequest(t, ts.URL+"/get/aa/abc/", "", "/get/:param/abc/")
   498  	testRequest(t, ts.URL+"/get/abas/abc/", "", "/get/:param/abc/")
   499  	testRequest(t, ts.URL+"/something/secondthing/test", "", "/something/secondthing/test")
   500  	testRequest(t, ts.URL+"/something/secondthingaaaa/thirdthing", "", "/something/:paramname/thirdthing")
   501  	testRequest(t, ts.URL+"/something/abcdad/thirdthing", "", "/something/:paramname/thirdthing")
   502  	testRequest(t, ts.URL+"/something/se/thirdthing", "", "/something/:paramname/thirdthing")
   503  	testRequest(t, ts.URL+"/something/s/thirdthing", "", "/something/:paramname/thirdthing")
   504  	testRequest(t, ts.URL+"/something/secondthing/thirdthing", "", "/something/:paramname/thirdthing")
   505  	testRequest(t, ts.URL+"/get/abc", "", "/get/abc")
   506  	testRequest(t, ts.URL+"/get/a", "", "/get/:param")
   507  	testRequest(t, ts.URL+"/get/abz", "", "/get/:param")
   508  	testRequest(t, ts.URL+"/get/12a", "", "/get/:param")
   509  	testRequest(t, ts.URL+"/get/abcd", "", "/get/:param")
   510  	testRequest(t, ts.URL+"/get/abc/123abc", "", "/get/abc/123abc")
   511  	testRequest(t, ts.URL+"/get/abc/12", "", "/get/abc/:param")
   512  	testRequest(t, ts.URL+"/get/abc/123ab", "", "/get/abc/:param")
   513  	testRequest(t, ts.URL+"/get/abc/xyz", "", "/get/abc/:param")
   514  	testRequest(t, ts.URL+"/get/abc/123abcddxx", "", "/get/abc/:param")
   515  	testRequest(t, ts.URL+"/get/abc/123abc/xxx8", "", "/get/abc/123abc/xxx8")
   516  	testRequest(t, ts.URL+"/get/abc/123abc/x", "", "/get/abc/123abc/:param")
   517  	testRequest(t, ts.URL+"/get/abc/123abc/xxx", "", "/get/abc/123abc/:param")
   518  	testRequest(t, ts.URL+"/get/abc/123abc/abc", "", "/get/abc/123abc/:param")
   519  	testRequest(t, ts.URL+"/get/abc/123abc/xxx8xxas", "", "/get/abc/123abc/:param")
   520  	testRequest(t, ts.URL+"/get/abc/123abc/xxx8/1234", "", "/get/abc/123abc/xxx8/1234")
   521  	testRequest(t, ts.URL+"/get/abc/123abc/xxx8/1", "", "/get/abc/123abc/xxx8/:param")
   522  	testRequest(t, ts.URL+"/get/abc/123abc/xxx8/123", "", "/get/abc/123abc/xxx8/:param")
   523  	testRequest(t, ts.URL+"/get/abc/123abc/xxx8/78k", "", "/get/abc/123abc/xxx8/:param")
   524  	testRequest(t, ts.URL+"/get/abc/123abc/xxx8/1234xxxd", "", "/get/abc/123abc/xxx8/:param")
   525  	testRequest(t, ts.URL+"/get/abc/123abc/xxx8/1234/ffas", "", "/get/abc/123abc/xxx8/1234/ffas")
   526  	testRequest(t, ts.URL+"/get/abc/123abc/xxx8/1234/f", "", "/get/abc/123abc/xxx8/1234/:param")
   527  	testRequest(t, ts.URL+"/get/abc/123abc/xxx8/1234/ffa", "", "/get/abc/123abc/xxx8/1234/:param")
   528  	testRequest(t, ts.URL+"/get/abc/123abc/xxx8/1234/kka", "", "/get/abc/123abc/xxx8/1234/:param")
   529  	testRequest(t, ts.URL+"/get/abc/123abc/xxx8/1234/ffas321", "", "/get/abc/123abc/xxx8/1234/:param")
   530  	testRequest(t, ts.URL+"/get/abc/123abc/xxx8/1234/kkdd/12c", "", "/get/abc/123abc/xxx8/1234/kkdd/12c")
   531  	testRequest(t, ts.URL+"/get/abc/123abc/xxx8/1234/kkdd/1", "", "/get/abc/123abc/xxx8/1234/kkdd/:param")
   532  	testRequest(t, ts.URL+"/get/abc/123abc/xxx8/1234/kkdd/12", "", "/get/abc/123abc/xxx8/1234/kkdd/:param")
   533  	testRequest(t, ts.URL+"/get/abc/123abc/xxx8/1234/kkdd/12b", "", "/get/abc/123abc/xxx8/1234/kkdd/:param")
   534  	testRequest(t, ts.URL+"/get/abc/123abc/xxx8/1234/kkdd/34", "", "/get/abc/123abc/xxx8/1234/kkdd/:param")
   535  	testRequest(t, ts.URL+"/get/abc/123abc/xxx8/1234/kkdd/12c2e3", "", "/get/abc/123abc/xxx8/1234/kkdd/:param")
   536  	testRequest(t, ts.URL+"/get/abc/12/test", "", "/get/abc/:param/test")
   537  	testRequest(t, ts.URL+"/get/abc/123abdd/test", "", "/get/abc/:param/test")
   538  	testRequest(t, ts.URL+"/get/abc/123abdddf/test", "", "/get/abc/:param/test")
   539  	testRequest(t, ts.URL+"/get/abc/123ab/test", "", "/get/abc/:param/test")
   540  	testRequest(t, ts.URL+"/get/abc/123abgg/test", "", "/get/abc/:param/test")
   541  	testRequest(t, ts.URL+"/get/abc/123abff/test", "", "/get/abc/:param/test")
   542  	testRequest(t, ts.URL+"/get/abc/123abffff/test", "", "/get/abc/:param/test")
   543  	testRequest(t, ts.URL+"/get/abc/123abd/test", "", "/get/abc/123abd/:param")
   544  	testRequest(t, ts.URL+"/get/abc/123abddd/test", "", "/get/abc/123abddd/:param")
   545  	testRequest(t, ts.URL+"/get/abc/123/test22", "", "/get/abc/123/:param")
   546  	testRequest(t, ts.URL+"/get/abc/123abg/test", "", "/get/abc/123abg/:param")
   547  	testRequest(t, ts.URL+"/get/abc/123abf/testss", "", "/get/abc/123abf/:param")
   548  	testRequest(t, ts.URL+"/get/abc/123abfff/te", "", "/get/abc/123abfff/:param")
   549  	// 404 not found
   550  	testRequest(t, ts.URL+"/c/d/e", "404 Not Found")
   551  	testRequest(t, ts.URL+"/c/d/e1", "404 Not Found")
   552  	testRequest(t, ts.URL+"/c/d/eee", "404 Not Found")
   553  	testRequest(t, ts.URL+"/c1/d/eee", "404 Not Found")
   554  	testRequest(t, ts.URL+"/c1/d/e2", "404 Not Found")
   555  	testRequest(t, ts.URL+"/cc/dd/ee/ff/gg/hh1", "404 Not Found")
   556  	testRequest(t, ts.URL+"/a/dd", "404 Not Found")
   557  	testRequest(t, ts.URL+"/addr/dd/aa", "404 Not Found")
   558  	testRequest(t, ts.URL+"/something/secondthing/121", "404 Not Found")
   559  }
   560  
   561  func isWindows() bool {
   562  	return runtime.GOOS == "windows"
   563  }
   564  

View as plain text