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

Function TestContextFileSimple

context_file_test.go:12–24  ·  view source on GitHub ↗

TestContextFileSimple tests the Context.File() method with a simple case

(t *testing.T)

Source from the content-addressed store, hash-verified

10
11// TestContextFileSimple tests the Context.File() method with a simple case
12func TestContextFileSimple(t *testing.T) {
13 // Test serving an existing file
14 testFile := "testdata/test_file.txt"
15 w := httptest.NewRecorder()
16 c, _ := CreateTestContext(w)
17 c.Request = httptest.NewRequest(http.MethodGet, "/test", nil)
18
19 c.File(testFile)
20
21 assert.Equal(t, http.StatusOK, w.Code)
22 assert.Contains(t, w.Body.String(), "This is a test file")
23 assert.Equal(t, "text/plain; charset=utf-8", w.Header().Get("Content-Type"))
24}
25
26// TestContextFileNotFound tests serving a non-existent file
27func TestContextFileNotFound(t *testing.T) {

Callers

nothing calls this directly

Calls 5

CreateTestContextFunction · 0.85
FileMethod · 0.80
StringMethod · 0.65
GetMethod · 0.45
HeaderMethod · 0.45

Tested by

no test coverage detected