The code below extracts the url value when running the appengine server, but during tests the url var are blank.
Any ideas to why this would be?
func init() {
s := scheduleApi{}
r := NewAERouter()
r.HandleFunc("/leagues/{leagueId}/schedule", s.get).Methods("GET")
http.Handle("/", r.router)
}
func (s *scheduleApi) get(c appengine.Context, w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
fmt.Printf("=======================
")
fmt.Printf("URL => %v
", r.URL)
fmt.Printf("params => %v
", params) // empty map
fmt.Printf("leageid => %v
", params["leagueId"]) // blank
fmt.Printf("=======================
")
}
Test
func Test_Get(t *testing.T) {
r, _ := http.NewRequest("GET", "/leagues/99/schedule", nil)
w := httptest.NewRecorder()
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
s := scheduleApi{}
c, _ := aetest.NewContext(nil)
s.get(c, w, r)
})
handler.ServeHTTP(w, r)
//...
}