Пример #1
0
func TestBindPanicsOnPointer(t *testing.T) {
	is := is.New(t)
	var err interface{}

	func() {
		defer func() {
			err = recover()
		}()
		_ = bind.JSON(&TestStruct{})
	}()
	is.Equal(err.(string), "Bind to pointer is not allowed")
}
Пример #2
0
func TestBindJSON(t *testing.T) {
	is := is.New(t)
	buf := bytes.NewBuffer([]byte(`{"a": 1, "b": "Ololo"}`))
	emptyBuf := bytes.NewBuffer([]byte{})

	n := noodle.New(bind.JSON(TestStruct{})).Then(bindHandlerFactory(is))
	r, _ := http.NewRequest("POST", "http://localhost", buf)
	is.NotErr(n(context.TODO(), httptest.NewRecorder(), r))

	r, _ = http.NewRequest("POST", "http://localhost", emptyBuf)
	is.Err(n(context.TODO(), httptest.NewRecorder(), r))
}