added context tests

This commit is contained in:
jarch09 2022-09-10 15:06:04 -04:00
parent 32304c721f
commit 0220b302d7

View File

@ -1623,6 +1623,20 @@ func TestContextBindWithJSON(t *testing.T) {
assert.Equal(t, 0, w.Body.Len())
}
func TestContextBindWithProtoJSON(t *testing.T) {
w := httptest.NewRecorder()
c, _ := CreateTestContext(w)
c.Request, _ = http.NewRequest("POST", "/", bytes.NewBufferString("{\"label\":\"bar\",\"optionalField\":\"foo\"}"))
c.Request.Header.Add("Content-Type", MIMEJSON)
var obj testdata.Test
assert.NoError(t, c.BindProtoJSON(&obj))
assert.Equal(t, "bar", obj.Label)
assert.Equal(t, "foo", *obj.OptionalField)
assert.Equal(t, 0, w.Body.Len())
}
func TestContextBindWithXML(t *testing.T) {
w := httptest.NewRecorder()
c, _ := CreateTestContext(w)
@ -1769,6 +1783,20 @@ func TestContextShouldBindWithJSON(t *testing.T) {
assert.Equal(t, 0, w.Body.Len())
}
func TestContextShouldBindWithProtoJSON(t *testing.T) {
w := httptest.NewRecorder()
c, _ := CreateTestContext(w)
c.Request, _ = http.NewRequest("POST", "/", bytes.NewBufferString("{\"label\":\"bar\", \"optionalField\":\"foo\"}"))
c.Request.Header.Add("Content-Type", MIMEJSON) // set fake content-type
var obj testdata.Test
assert.NoError(t, c.ShouldBindProtoJSON(&obj))
assert.Equal(t, "bar", obj.Label)
assert.Equal(t, "foo", *obj.OptionalField)
assert.Equal(t, 0, w.Body.Len())
}
func TestContextShouldBindWithXML(t *testing.T) {
w := httptest.NewRecorder()
c, _ := CreateTestContext(w)