This question already has an answer here:
- How to test http request handlers 1 answer
There is the most common controller that returns files, there is a need to conduct unit testing, but there’s no idea how to do it. In the tests i'm receiving 404 error, cause file not found in FS, maybe there a way to mock the fs.Open() calls in the http module?
func GetProfileAvatarHandler() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if r.Header.Get("something") == "there" {
http.ServeFile(w, r, "images/default_avatar.jpg")
return
}
http.ServeFile(w, r, "images/user_avatar.jpg")
}
}
Aucun commentaire:
Enregistrer un commentaire