Digamos que estoy probando una característica que llama a un servicio web, y que el servicio se burlaban con httptest.NewServer
func TestSomeFeature(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(200)
}))
SomeFeature(server.URL, "foo")
}
func SomeFeature(host, a string) {
if a == "foo" {
http.Get(fmt.Sprintf("%v/foo", host))
}
if a == "bar" {
http.Get(fmt.Sprintf("%v/bar", host))
}
}
¿Cómo puedo afirmar que el servidor se ha llamado a la url correcta /foo
y fallar la prueba si es llamada con la dirección url incorrecta o no llamado a todos?
server
?