MCPcopy
hub / github.com/harness/harness / TestWriteJSON

Function TestWriteJSON

app/api/render/render_test.go:144–171  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

142}
143
144func TestWriteJSON(t *testing.T) {
145 // without indent
146 {
147 w := httptest.NewRecorder()
148 JSON(w, http.StatusTeapot, map[string]string{"hello": "world"})
149 if got, want := w.Body.String(), "{\"hello\":\"world\"}\n"; got != want {
150 t.Errorf("Want JSON body %q, got %q", want, got)
151 }
152 if got, want := w.Header().Get("Content-Type"), "application/json; charset=utf-8"; got != want {
153 t.Errorf("Want Content-Type %q, got %q", want, got)
154 }
155 if got, want := w.Code, http.StatusTeapot; got != want {
156 t.Errorf("Want status code %d, got %d", want, got)
157 }
158 }
159 // with indent
160 {
161 indent = true
162 defer func() {
163 indent = false
164 }()
165 w := httptest.NewRecorder()
166 JSON(w, http.StatusTeapot, map[string]string{"hello": "world"})
167 if got, want := w.Body.String(), "{\n \"hello\": \"world\"\n}\n"; got != want {
168 t.Errorf("Want JSON body %q, got %q", want, got)
169 }
170 }
171}
172
173func TestJSONArrayDynamic(t *testing.T) {
174 noctx := context.Background()

Callers

nothing calls this directly

Calls 5

JSONFunction · 0.85
GetMethod · 0.65
StringMethod · 0.45
ErrorfMethod · 0.45
HeaderMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…