Browse Source

Add RespondAsInternalServerError func, tests

Volodymyr Tkach 2 years ago
parent
commit
f6d6a697ee
2 changed files with 29 additions and 0 deletions
  1. 5 0
      utils/http/helpers/helpers.go
  2. 24 0
      utils/http/helpers/helpers_test.go

+ 5 - 0
utils/http/helpers/helpers.go

@@ -27,6 +27,7 @@ import (
 // func HandleTextXml(data string) http.Handler
 // func MinifyHtmlCode(str string) string
 // func RespondAsBadRequest(w http.ResponseWriter, r *http.Request, err error)
+// func RespondAsInternalServerError(w http.ResponseWriter, r *http.Request)
 // func RespondAsMethodNotAllowed(w http.ResponseWriter, r *http.Request)
 // func SessionStart(w http.ResponseWriter, r *http.Request) (*session.Session, error)
 // func SetLanguageCookie(w http.ResponseWriter, r *http.Request) error
@@ -173,6 +174,10 @@ func RespondAsBadRequest(w http.ResponseWriter, r *http.Request, err error) {
 	}
 }
 
+func RespondAsInternalServerError(w http.ResponseWriter, r *http.Request) {
+	w.WriteHeader(http.StatusInternalServerError)
+}
+
 func RespondAsMethodNotAllowed(w http.ResponseWriter, r *http.Request) {
 	w.WriteHeader(http.StatusMethodNotAllowed)
 }

+ 24 - 0
utils/http/helpers/helpers_test.go

@@ -299,6 +299,30 @@ var _ = Describe("helpers", func() {
 			})
 		})
 
+		Context("RespondAsInternalServerError", func() {
+			BeforeEach(func() {
+				var handler = func() http.HandlerFunc {
+					return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+						helpers.RespondAsInternalServerError(w, r)
+					})
+				}
+
+				srv = httptest.NewServer(handler())
+				client = srv.Client()
+				resp, err = client.Get(srv.URL + "/")
+				Expect(err).To(Succeed())
+			})
+
+			AfterEach(func() {
+				Expect(resp.Body.Close()).To(Succeed())
+				srv.Close()
+			})
+
+			It("handle method not allowed", func() {
+				Expect(resp.StatusCode).To(Equal(http.StatusInternalServerError))
+			})
+		})
+
 		Context("RespondAsMethodNotAllowed", func() {
 			BeforeEach(func() {
 				var handler = func() http.HandlerFunc {