MCPcopy
hub / github.com/caddyserver/caddy / TestRespondWithJSON

Function TestRespondWithJSON

caddytest/integration/handler_test.go:34–59  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

32}
33
34func TestRespondWithJSON(t *testing.T) {
35 tester := caddytest.NewTester(t)
36 tester.InitServer(`
37 {
38 skip_install_trust
39 admin localhost:2999
40 http_port 9080
41 https_port 9443
42 grace_period 1ns
43 }
44 localhost {
45 respond {http.request.body}
46 }
47 `, "caddyfile")
48
49 res, _ := tester.AssertPostResponseBody("https://localhost:9443/",
50 nil,
51 bytes.NewBufferString(`{
52 "greeting": "Hello, world!"
53 }`), 200, `{
54 "greeting": "Hello, world!"
55 }`)
56 if res.Header.Get("Content-Type") != "application/json" {
57 t.Errorf("expected Content-Type to be application/json, but was %s", res.Header.Get("Content-Type"))
58 }
59}

Callers

nothing calls this directly

Calls 4

InitServerMethod · 0.95
NewTesterFunction · 0.92
GetMethod · 0.65

Tested by

no test coverage detected