(t *testing.T)
| 109 | } |
| 110 | |
| 111 | func TestRenderJsonpJSON(t *testing.T) { |
| 112 | w1 := httptest.NewRecorder() |
| 113 | data := map[string]any{ |
| 114 | "foo": "bar", |
| 115 | } |
| 116 | |
| 117 | (JsonpJSON{"x", data}).WriteContentType(w1) |
| 118 | assert.Equal(t, "application/javascript; charset=utf-8", w1.Header().Get("Content-Type")) |
| 119 | |
| 120 | err1 := (JsonpJSON{"x", data}).Render(w1) |
| 121 | |
| 122 | require.NoError(t, err1) |
| 123 | assert.Equal(t, "x({\"foo\":\"bar\"});", w1.Body.String()) |
| 124 | assert.Equal(t, "application/javascript; charset=utf-8", w1.Header().Get("Content-Type")) |
| 125 | |
| 126 | w2 := httptest.NewRecorder() |
| 127 | datas := []map[string]any{{ |
| 128 | "foo": "bar", |
| 129 | }, { |
| 130 | "bar": "foo", |
| 131 | }} |
| 132 | |
| 133 | err2 := (JsonpJSON{"x", datas}).Render(w2) |
| 134 | require.NoError(t, err2) |
| 135 | assert.Equal(t, "x([{\"foo\":\"bar\"},{\"bar\":\"foo\"}]);", w2.Body.String()) |
| 136 | assert.Equal(t, "application/javascript; charset=utf-8", w2.Header().Get("Content-Type")) |
| 137 | } |
| 138 | |
| 139 | type errorWriter struct { |
| 140 | bufString string |
nothing calls this directly
no test coverage detected