deprecated_test.go 772 B

123456789101112131415161718192021222324252627282930313233
  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. package gin
  5. import (
  6. "bytes"
  7. "net/http"
  8. "net/http/httptest"
  9. "testing"
  10. "github.com/gin-gonic/gin/binding"
  11. "github.com/stretchr/testify/assert"
  12. )
  13. func TestBindWith(t *testing.T) {
  14. w := httptest.NewRecorder()
  15. c, _ := CreateTestContext(w)
  16. c.Request, _ = http.NewRequest("POST", "/?foo=bar&bar=foo", bytes.NewBufferString("foo=unused"))
  17. var obj struct {
  18. Foo string `form:"foo"`
  19. Bar string `form:"bar"`
  20. }
  21. captureOutput(t, func() {
  22. assert.NoError(t, c.BindWith(&obj, binding.Form))
  23. })
  24. assert.Equal(t, "foo", obj.Bar)
  25. assert.Equal(t, "bar", obj.Foo)
  26. assert.Equal(t, 0, w.Body.Len())
  27. }