Skip to content
Myr

test(context): use t.TempDir() for SaveUploadedFile permission test on WSL (#4709)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* fix: change file creation to use c.Temp instead to work on wsl * test(context): use t.TempDir() in SaveUploadedFile failure test for WSL Mirror the WSL-portability fix applied to TestSaveUploadedFileWithPermission: write under t.TempDir() instead of a relative path so the test does not depend on the working directory's filesystem (drvfs reports 0o777 on WSL) and is cleaned up automatically. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> ---------

authored by Pierre F. · committed by GitHub · parent 074b669 · Browse files · 1 file+6 added−7 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Co-authored-by: Bo-Yi Wu <appleboy.tw@gmail.com>
  • Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Diff stats

1 file+6 added−7 removed

  • other:+6 added−7 removed

1 file+6 added−7 removed

modified:context_test.go+6 added-7 removed
246 unmodified lines
247 f, err := c.FormFile("file")248 require.NoError(t, err)249 assert.Equal(t, "permission_test", f.Filename)250 var mode fs.FileMode = 0o755251 require.NoError(t, c.SaveUploadedFile(f, "permission_test", mode))252 t.Cleanup(func() {253 assert.NoError(t, os.Remove("permission_test"))254 })255 info, err := os.Stat(filepath.Dir("permission_test"))251 dst := filepath.Join(t.TempDir(), "subdir", "permission_test")252 require.NoError(t, c.SaveUploadedFile(f, dst, mode))253 info, err := os.Stat(filepath.Dir(dst))254 require.NoError(t, err)257 assert.Equal(t, info.Mode().Perm(), mode)255 assert.Equal(t, mode, info.Mode().Perm())256}257258func TestSaveUploadedFileWithPermissionFailed(t *testing.T) {259 buf := new(bytes.Buffer)
9 unmodified lines
269 f, err := c.FormFile("file")270 require.NoError(t, err)271 assert.Equal(t, "permission_test", f.Filename)272 var mode fs.FileMode = 0o644273 dst := filepath.Join(t.TempDir(), "test", "permission_test")275 require.Error(t, c.SaveUploadedFile(f, "test/permission_test", mode))274 require.Error(t, c.SaveUploadedFile(f, dst, mode))275}276277func TestContextReset(t *testing.T) {278 router := New()
3635 unmodified lines