github.com/hellobchain/third_party@v0.0.0-20230331131523-deb0478a2e52/gin/deprecated_test.go (about) 1 // Copyright 2014 Manu Martinez-Almeida. All rights reserved. 2 // Use of this source code is governed by a MIT style 3 // license that can be found in the LICENSE file. 4 5 package gin 6 7 import ( 8 "bytes" 9 "github.com/hellobchain/newcryptosm/http" 10 "github.com/hellobchain/newcryptosm/http/httptest" 11 "testing" 12 13 "github.com/stretchr/testify/assert" 14 "github.com/hellobchain/third_party/gin/binding" 15 ) 16 17 func TestBindWith(t *testing.T) { 18 w := httptest.NewRecorder() 19 c, _ := CreateTestContext(w) 20 21 c.Request, _ = http.NewRequest("POST", "/?foo=bar&bar=foo", bytes.NewBufferString("foo=unused")) 22 23 var obj struct { 24 Foo string `form:"foo"` 25 Bar string `form:"bar"` 26 } 27 captureOutput(t, func() { 28 assert.NoError(t, c.BindWith(&obj, binding.Form)) 29 }) 30 assert.Equal(t, "foo", obj.Bar) 31 assert.Equal(t, "bar", obj.Foo) 32 assert.Equal(t, 0, w.Body.Len()) 33 }