File: subrouter_test.go

package info (click to toggle)
golang-github-zenazn-goji 1.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 464 kB
  • sloc: makefile: 3
file content (28 lines) | stat: -rw-r--r-- 507 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package middleware

import (
	"net/http"
	"net/http/httptest"
	"testing"

	"github.com/zenazn/goji/web"
)

func TestSubRouterMatch(t *testing.T) {
	m := web.New()
	m.Use(m.Router)

	m2 := web.New()
	m2.Use(SubRouter)
	m2.Get("/bar", func(w http.ResponseWriter, r *http.Request) {})

	m.Get("/foo/*", m2)

	r, err := http.NewRequest("GET", "/foo/bar", nil)
	if err != nil {
		t.Fatal(err)
	}

	// This function will recurse forever if SubRouter + Match didn't work.
	m.ServeHTTP(httptest.NewRecorder(), r)
}