Created
March 8, 2019 06:45
-
-
Save andresprogra/c1040e0f55c65ebd293cb5e9369a4096 to your computer and use it in GitHub Desktop.
andres.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.... | |
// Main server | |
mux.HandleFunc("/api/v1/plans/{id:[0-9]+}", handlers.GetPlan).Methods(http.MethodGet) // Esto funciona perfecto. | |
// Si ejecuto este endpoint en el navegador la lógica funciona de maravilla. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Test file | |
req := httptest.NewRequest("GET", "/api/v1/plans/132",nil) | |
w := httptest.NewRecorder() | |
handlers.GetPlan(w, req) | |
resp := w.Result() | |
body, _ := ioutil.ReadAll(resp.Body) | |
fmt.Println(string(body)) | |
// Al ejecutar la pruebas me retorna un 404, porque el :id (que debería ser 132) llega al handler como nulo, entonces se interpreta | |
// como un 0 y en la base de datos no existe ningún recurso con ID 0. | |
// Pero hago enfásis en que si ejecuto ese mismo endpoint en el navegador el ID 132 SÍ existe. | |
// el problema lo tengo al escribir el test, pero según yo y la documentación está todo en perfecto estado. Es el único escenario | |
// en el que tengo problemas. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment