forked from restic/restic
-
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.
Merge pull request restic#2266 from restic/fix-windows-tests
Fix tests on Windows
- Loading branch information
Showing
5 changed files
with
166 additions
and
118 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,41 @@ | ||
// +build !windows | ||
|
||
package archiver | ||
|
||
import ( | ||
"os" | ||
"syscall" | ||
"testing" | ||
) | ||
|
||
type wrappedFileInfo struct { | ||
os.FileInfo | ||
sys interface{} | ||
mode os.FileMode | ||
} | ||
|
||
func (fi wrappedFileInfo) Sys() interface{} { | ||
return fi.sys | ||
} | ||
|
||
func (fi wrappedFileInfo) Mode() os.FileMode { | ||
return fi.mode | ||
} | ||
|
||
// wrapFileInfo returns a new os.FileInfo with the mode, owner, and group fields changed. | ||
func wrapFileInfo(t testing.TB, fi os.FileInfo) os.FileInfo { | ||
// get the underlying stat_t and modify the values | ||
stat := fi.Sys().(*syscall.Stat_t) | ||
stat.Mode = mockFileInfoMode | ||
stat.Uid = mockFileInfoUID | ||
stat.Gid = mockFileInfoGID | ||
|
||
// wrap the os.FileInfo so we can return a modified stat_t | ||
res := wrappedFileInfo{ | ||
FileInfo: fi, | ||
sys: stat, | ||
mode: mockFileInfoMode, | ||
} | ||
|
||
return res | ||
} |
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,28 @@ | ||
// +build windows | ||
|
||
package archiver | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
) | ||
|
||
type wrappedFileInfo struct { | ||
os.FileInfo | ||
mode os.FileMode | ||
} | ||
|
||
func (fi wrappedFileInfo) Mode() os.FileMode { | ||
return fi.mode | ||
} | ||
|
||
// wrapFileInfo returns a new os.FileInfo with the mode, owner, and group fields changed. | ||
func wrapFileInfo(t testing.TB, fi os.FileInfo) os.FileInfo { | ||
// wrap the os.FileInfo and return the modified mode, uid and gid are ignored on Windows | ||
res := wrappedFileInfo{ | ||
FileInfo: fi, | ||
mode: mockFileInfoMode, | ||
} | ||
|
||
return res | ||
} |
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