0
package main

import (
    "net/http"
)

func main() {
    http.HandleFunc("/je/b2", myController)
    http.ListenAndServe(":8080", nil)
}

func myController(w http.ResponseWriter, r *http.Request)  {
    w.Write([]byte(`{"error":{"message":"not found","info": ""}}`))
}
1
  • Как? Если б знал не спрашивал бы. Сумму или деление например могу с трудом написать тест, здесь даже не знаю как и с чего начать.
    – Ivan
    15 ноя 2017 в 18:22

1 ответ 1

1

Берёте и пишете:

func TestMyController(t *testing.T) {
    w := httptest.NewRecorder()
    r, err := http.NewRequest(http.MethodGet, "/je/b2", nil)
    if err != nil {
        t.Fatal(err)
    }

    myController(w, r)
    if w.Code != http.StatusOK {
        t.Errorf("exp %d, got %d", http.StatusOK, w.Code)
    }
}

Подробнее:

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.