check response header. (#266)

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu 2017-08-06 09:53:38 +08:00 committed by GitHub
parent b9104de2c5
commit 2bcc17de51
2 changed files with 4 additions and 1 deletions

View File

@ -6,6 +6,7 @@ import (
"net/http"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"golang.org/x/crypto/acme/autocert"
@ -35,7 +36,7 @@ func pushHandler(c *gin.Context) {
var form RequestPush
var msg string
if err := c.BindJSON(&form); err != nil {
if err := c.ShouldBindWith(&form, binding.JSON); err != nil {
msg = "Missing notifications field."
LogAccess.Debug(msg)
abortWithError(c, http.StatusBadRequest, msg)

View File

@ -101,6 +101,7 @@ func TestRootHandler(t *testing.T) {
assert.Equal(t, "Welcome to notification server.", value)
assert.Equal(t, http.StatusOK, r.Code)
assert.Equal(t, "application/json; charset=utf-8", r.HeaderMap.Get("Content-Type"))
})
}
@ -160,6 +161,7 @@ func TestMissingNotificationsParameter(t *testing.T) {
Run(routerEngine(), func(r gofight.HTTPResponse, rq gofight.HTTPRequest) {
assert.Equal(t, http.StatusBadRequest, r.Code)
assert.Equal(t, "application/json; charset=utf-8", r.HeaderMap.Get("Content-Type"))
})
}