lundi 22 juin 2015

Adding POST variables to glolang test http Request

I am trying to add form variables to a golang http request.

So here's how my golang test looks like:

func sample_test(t *testing.T) {
    handler := &my_listener_class{}
    reader := strings.NewReader("number=2")
    req, _ := http.NewRequest("POST", "/my_url", reader)
    w := httptest.NewRecorder()
    handler.function_to_test(w, req)
    if w.Code != http.StatusOK {
        t.Errorf("Home page didn't return %v", http.StatusOK, w.Body)
    }
}

The issue is that, the form data never gets passed on to the function I need to test.

The other relevant function is:

func (listener *my_listener_class) function_to_test(writer http.ResponseWriter, request *http.Request) {
..//
}

Aucun commentaire:

Enregistrer un commentaire