json_test.go 486 B

123456789101112131415161718192021
  1. // Copyright 2019 Gin Core Team. 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 binding
  5. import (
  6. "testing"
  7. "github.com/stretchr/testify/assert"
  8. "github.com/stretchr/testify/require"
  9. )
  10. func TestJSONBindingBindBody(t *testing.T) {
  11. var s struct {
  12. Foo string `json:"foo"`
  13. }
  14. err := jsonBinding{}.BindBody([]byte(`{"foo": "FOO"}`), &s)
  15. require.NoError(t, err)
  16. assert.Equal(t, "FOO", s.Foo)
  17. }