(t *testing.T)
| 1258 | } |
| 1259 | |
| 1260 | func TestContextRenderHTML2(t *testing.T) { |
| 1261 | w := httptest.NewRecorder() |
| 1262 | c, router := CreateTestContext(w) |
| 1263 | |
| 1264 | // print debug warning log when Engine.trees > 0 |
| 1265 | router.addRoute(http.MethodGet, "/", HandlersChain{func(_ *Context) {}}) |
| 1266 | assert.Len(t, router.trees, 1) |
| 1267 | |
| 1268 | templ := template.Must(template.New("t").Parse(`Hello {{.name}}`)) |
| 1269 | re := captureOutput(t, func() { |
| 1270 | SetMode(DebugMode) |
| 1271 | router.SetHTMLTemplate(templ) |
| 1272 | SetMode(TestMode) |
| 1273 | }) |
| 1274 | |
| 1275 | assert.Equal(t, "[GIN-debug] [WARNING] Since SetHTMLTemplate() is NOT thread-safe. It should only be called\nat initialization. ie. before any route is registered or the router is listening in a socket:\n\n\trouter := gin.Default()\n\trouter.SetHTMLTemplate(template) // << good place\n\n", re) |
| 1276 | |
| 1277 | c.HTML(http.StatusCreated, "t", H{"name": "alexandernyquist"}) |
| 1278 | |
| 1279 | assert.Equal(t, http.StatusCreated, w.Code) |
| 1280 | assert.Equal(t, "Hello alexandernyquist", w.Body.String()) |
| 1281 | assert.Equal(t, "text/html; charset=utf-8", w.Header().Get("Content-Type")) |
| 1282 | } |
| 1283 | |
| 1284 | // Tests that no HTML is rendered if code is 204 |
| 1285 | func TestContextRenderNoContentHTML(t *testing.T) { |
nothing calls this directly
no test coverage detected