https://plus.google.com/101022900381697718949/posts/eWy6DjFJ6uW
(t *testing.T)
| 2002 | |
| 2003 | // https://plus.google.com/101022900381697718949/posts/eWy6DjFJ6uW |
| 2004 | func TestSubrouterHeader(t *testing.T) { |
| 2005 | expected := "func1 response" |
| 2006 | func1 := func(w http.ResponseWriter, r *http.Request) { |
| 2007 | fmt.Fprint(w, expected) |
| 2008 | } |
| 2009 | func2 := func(http.ResponseWriter, *http.Request) {} |
| 2010 | |
| 2011 | r := NewRouter() |
| 2012 | s := r.Headers("SomeSpecialHeader", "").Subrouter() |
| 2013 | s.HandleFunc("/", func1).Name("func1") |
| 2014 | r.HandleFunc("/", func2).Name("func2") |
| 2015 | |
| 2016 | req, _ := http.NewRequest("GET", "http://localhost/", nil) |
| 2017 | req.Header.Add("SomeSpecialHeader", "foo") |
| 2018 | match := new(RouteMatch) |
| 2019 | matched := r.Match(req, match) |
| 2020 | if !matched { |
| 2021 | t.Errorf("Should match request") |
| 2022 | } |
| 2023 | if match.Route.GetName() != "func1" { |
| 2024 | t.Errorf("Expecting func1 handler, got %s", match.Route.GetName()) |
| 2025 | } |
| 2026 | resp := NewRecorder() |
| 2027 | match.Handler.ServeHTTP(resp, req) |
| 2028 | if resp.Body.String() != expected { |
| 2029 | t.Errorf("Expecting %q", expected) |
| 2030 | } |
| 2031 | } |
| 2032 | |
| 2033 | func TestNoMatchMethodErrorHandler(t *testing.T) { |
| 2034 | func1 := func(w http.ResponseWriter, r *http.Request) {} |
nothing calls this directly
no test coverage detected