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

Function TestContextRenderFileFromFS

context_test.go:1431–1444  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1429}
1430
1431func TestContextRenderFileFromFS(t *testing.T) {
1432 w := httptest.NewRecorder()
1433 c, _ := CreateTestContext(w)
1434
1435 c.Request, _ = http.NewRequest(http.MethodGet, "/some/path", nil)
1436 c.FileFromFS("./gin.go", Dir(".", false))
1437
1438 assert.Equal(t, http.StatusOK, w.Code)
1439 assert.Contains(t, w.Body.String(), "func New(opts ...OptionFunc) *Engine {")
1440 // Content-Type='text/plain; charset=utf-8' when go version <= 1.16,
1441 // else, Content-Type='text/x-go; charset=utf-8'
1442 assert.NotEmpty(t, w.Header().Get("Content-Type"))
1443 assert.Equal(t, "/some/path", c.Request.URL.Path)
1444}
1445
1446func TestContextRenderAttachment(t *testing.T) {
1447 w := httptest.NewRecorder()

Callers

nothing calls this directly

Calls 6

CreateTestContextFunction · 0.85
DirFunction · 0.85
FileFromFSMethod · 0.80
StringMethod · 0.65
GetMethod · 0.45
HeaderMethod · 0.45

Tested by

no test coverage detected