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

Function TestSaveUploadedFileWithPermissionFailed

context_test.go:259–275  ·  context_test.go::TestSaveUploadedFileWithPermissionFailed
(t *testing.T)

Source from the content-addressed store, hash-verified

257}
258
259func TestSaveUploadedFileWithPermissionFailed(t *testing.T) {
260 buf := new(bytes.Buffer)
261 mw := multipart.NewWriter(buf)
262 w, err := mw.CreateFormFile("file", "permission_test")
263 require.NoError(t, err)
264 _, err = w.Write([]byte("permission_test"))
265 require.NoError(t, err)
266 mw.Close()
267 c, _ := CreateTestContext(httptest.NewRecorder())
268 c.Request, _ = http.NewRequest(http.MethodPost, "/", buf)
269 c.Request.Header.Set("Content-Type", mw.FormDataContentType())
270 f, err := c.FormFile("file")
271 require.NoError(t, err)
272 assert.Equal(t, "permission_test", f.Filename)
273 var mode fs.FileMode = 0o644
274 require.Error(t, c.SaveUploadedFile(f, "test/permission_test", mode))
275}
276
277func TestContextReset(t *testing.T) {
278 router := New()

Callers

nothing calls this directly

Calls 7

CreateTestContextFunction · 0.85
CloseMethod · 0.80
SetMethod · 0.80
FormFileMethod · 0.80
SaveUploadedFileMethod · 0.80
WriteMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected