MCPcopy
hub / github.com/gin-gonic/gin / TestRenderYAML

Function TestRenderYAML

render/render_test.go:308–330  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

306}
307
308func TestRenderYAML(t *testing.T) {
309 w := httptest.NewRecorder()
310 data := `
311a : Easy!
312b:
313 c: 2
314 d: [3, 4]
315 `
316 (YAML{data}).WriteContentType(w)
317 assert.Equal(t, "application/yaml; charset=utf-8", w.Header().Get("Content-Type"))
318
319 err := (YAML{data}).Render(w)
320 require.NoError(t, err)
321
322 // With github.com/goccy/go-yaml, the output format is different from gopkg.in/yaml.v3
323 // We're checking that the output contains the expected data, not the exact formatting
324 output := w.Body.String()
325 assert.Contains(t, output, "a : Easy!")
326 assert.Contains(t, output, "b:")
327 assert.Contains(t, output, "c: 2")
328 assert.Contains(t, output, "d: [3, 4]")
329 assert.Equal(t, "application/yaml; charset=utf-8", w.Header().Get("Content-Type"))
330}
331
332type fail struct{}
333

Callers

nothing calls this directly

Calls 5

WriteContentTypeMethod · 0.65
RenderMethod · 0.65
StringMethod · 0.65
GetMethod · 0.45
HeaderMethod · 0.45

Tested by

no test coverage detected