render_17_test.go 634 B

1234567891011121314151617181920212223242526
  1. // Copyright 2018 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. // +build go1.7
  5. package render
  6. import (
  7. "net/http/httptest"
  8. "testing"
  9. "github.com/stretchr/testify/assert"
  10. )
  11. func TestRenderPureJSON(t *testing.T) {
  12. w := httptest.NewRecorder()
  13. data := map[string]interface{}{
  14. "foo": "bar",
  15. "html": "<b>",
  16. }
  17. err := (PureJSON{data}).Render(w)
  18. assert.NoError(t, err)
  19. assert.Equal(t, "{\"foo\":\"bar\",\"html\":\"<b>\"}\n", w.Body.String())
  20. assert.Equal(t, "application/json; charset=utf-8", w.Header().Get("Content-Type"))
  21. }