forked from spf13/afero
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Return os consistent error in ReadOnlyFs filter
fixes spf13#350: Use `os.ErrPermission` instead of `syscall.EPerm` to make sure that the error is consistent over different operating systems and can be checked with `os.isPermission(err)`
- Loading branch information
Showing
3 changed files
with
46 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package afero | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
"time" | ||
) | ||
|
||
func checkForErrPermission(t *testing.T, err error) { | ||
t.Helper() | ||
if err == nil || !os.IsPermission(err) { | ||
t.Errorf("Expected err !=nil && err == ErrPermission, got %[1]T (%[1]v)", err) | ||
} | ||
} | ||
|
||
// Make sure that the ReadOnlyFs filter returns errors that can be | ||
// checked with os.IsPermission | ||
func TestReadOnlyFsErrPermission(t *testing.T) { | ||
fs := NewReadOnlyFs(NewMemMapFs()) | ||
|
||
_, err := fs.Create("test") | ||
checkForErrPermission(t, err) | ||
checkForErrPermission(t, fs.Chtimes("test", time.Now(), time.Now())) | ||
checkForErrPermission(t, fs.Chmod("test", os.ModePerm)) | ||
checkForErrPermission(t, fs.Chown("test", 0, 0)) | ||
checkForErrPermission(t, fs.Mkdir("test", os.ModePerm)) | ||
checkForErrPermission(t, fs.MkdirAll("test", os.ModePerm)) | ||
_, err = fs.OpenFile("test", os.O_CREATE, os.ModePerm) | ||
checkForErrPermission(t, err) | ||
checkForErrPermission(t, fs.Remove("test")) | ||
checkForErrPermission(t, fs.RemoveAll("test")) | ||
checkForErrPermission(t, fs.Rename("test", "test")) | ||
|
||
} |