From 66c4b81579a6b357b848dafffde22159d3dfd8af Mon Sep 17 00:00:00 2001 From: Naoki Takano Date: Wed, 30 Dec 2015 22:49:38 -0800 Subject: [PATCH] Added exits check tests for binding --- binding/binding_test.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/binding/binding_test.go b/binding/binding_test.go index 713e2e5a..1488d575 100644 --- a/binding/binding_test.go +++ b/binding/binding_test.go @@ -121,6 +121,28 @@ func TestValidationDisabled(t *testing.T) { assert.NoError(t, err) } +func TestExistsSucceeds(t *testing.T) { + type HogeStruct struct { + Hoge *int `json:"hoge" binding:"exists"` + } + + var obj HogeStruct + req := requestWithBody("POST", "/", `{"hoge": 0}`) + err := JSON.Bind(req, &obj) + assert.NoError(t, err) +} + +func TestExistsFails(t *testing.T) { + type HogeStruct struct { + Hoge *int `json:"foo" binding:"exists"` + } + + var obj HogeStruct + req := requestWithBody("POST", "/", `{"boen": 0}`) + err := JSON.Bind(req, &obj) + assert.Error(t, err) +} + func testFormBinding(t *testing.T, method, path, badPath, body, badBody string) { b := Form assert.Equal(t, b.Name(), "form")