mirror of https://github.com/gin-gonic/gin.git
test(TOML): Add some tests for the TOML render (#3401)
This commit is contained in:
parent
297b664cf8
commit
e868fd1d3d
|
@ -8,6 +8,7 @@ import (
|
|||
"encoding/xml"
|
||||
"errors"
|
||||
"html/template"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strconv"
|
||||
|
@ -254,6 +255,27 @@ func TestRenderYAMLFail(t *testing.T) {
|
|||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
func TestRenderTOML(t *testing.T) {
|
||||
w := httptest.NewRecorder()
|
||||
data := map[string]any{
|
||||
"foo": "bar",
|
||||
"html": "<b>",
|
||||
}
|
||||
(TOML{data}).WriteContentType(w)
|
||||
assert.Equal(t, "application/toml; charset=utf-8", w.Header().Get("Content-Type"))
|
||||
|
||||
err := (TOML{data}).Render(w)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "foo = 'bar'\nhtml = '<b>'\n", w.Body.String())
|
||||
assert.Equal(t, "application/toml; charset=utf-8", w.Header().Get("Content-Type"))
|
||||
}
|
||||
|
||||
func TestRenderTOMLFail(t *testing.T) {
|
||||
w := httptest.NewRecorder()
|
||||
err := (TOML{net.IPv4bcast}).Render(w)
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
// test Protobuf rendering
|
||||
func TestRenderProtoBuf(t *testing.T) {
|
||||
w := httptest.NewRecorder()
|
||||
|
|
Loading…
Reference in New Issue