check response header. (#266)
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
parent
b9104de2c5
commit
2bcc17de51
|
@ -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)
|
||||
|
|
|
@ -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"))
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue