大猩猩多路复用器在测试期间返回空白的URL参数

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)

            //...
}

Gorilla mux needs to be included in your test. In your app code you are setting up the route using mux but in your test you are not.

Here is a question dealing with this issue on go-nuts.