This fixes various test issues with Go 1.20. - Most tests rewritten to use fakefs where possible - Some tests that were already skipped, or dubious (invasive, unmaintainable, unclear what they even tested) have been removed - Some actual code rewritten to better support testing in fakefs Co-authored-by: Eric P <eric@kastelo.net>
This commit is contained in:
+34
-15
@@ -172,21 +172,23 @@ var (
|
||||
|
||||
// Equivalents from os package.
|
||||
|
||||
const ModePerm = FileMode(os.ModePerm)
|
||||
const ModeSetgid = FileMode(os.ModeSetgid)
|
||||
const ModeSetuid = FileMode(os.ModeSetuid)
|
||||
const ModeSticky = FileMode(os.ModeSticky)
|
||||
const ModeSymlink = FileMode(os.ModeSymlink)
|
||||
const ModeType = FileMode(os.ModeType)
|
||||
const PathSeparator = os.PathSeparator
|
||||
const OptAppend = os.O_APPEND
|
||||
const OptCreate = os.O_CREATE
|
||||
const OptExclusive = os.O_EXCL
|
||||
const OptReadOnly = os.O_RDONLY
|
||||
const OptReadWrite = os.O_RDWR
|
||||
const OptSync = os.O_SYNC
|
||||
const OptTruncate = os.O_TRUNC
|
||||
const OptWriteOnly = os.O_WRONLY
|
||||
const (
|
||||
ModePerm = FileMode(os.ModePerm)
|
||||
ModeSetgid = FileMode(os.ModeSetgid)
|
||||
ModeSetuid = FileMode(os.ModeSetuid)
|
||||
ModeSticky = FileMode(os.ModeSticky)
|
||||
ModeSymlink = FileMode(os.ModeSymlink)
|
||||
ModeType = FileMode(os.ModeType)
|
||||
PathSeparator = os.PathSeparator
|
||||
OptAppend = os.O_APPEND
|
||||
OptCreate = os.O_CREATE
|
||||
OptExclusive = os.O_EXCL
|
||||
OptReadOnly = os.O_RDONLY
|
||||
OptReadWrite = os.O_RDWR
|
||||
OptSync = os.O_SYNC
|
||||
OptTruncate = os.O_TRUNC
|
||||
OptWriteOnly = os.O_WRONLY
|
||||
)
|
||||
|
||||
// SkipDir is used as a return value from WalkFuncs to indicate that
|
||||
// the directory named in the call is to be skipped. It is not returned
|
||||
@@ -354,3 +356,20 @@ func unwrapFilesystem(fs Filesystem, wrapperType filesystemWrapperType) (Filesys
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// WriteFile writes data to the named file, creating it if necessary.
|
||||
// If the file does not exist, WriteFile creates it with permissions perm (before umask);
|
||||
// otherwise WriteFile truncates it before writing, without changing permissions.
|
||||
// Since Writefile requires multiple system calls to complete, a failure mid-operation
|
||||
// can leave the file in a partially written state.
|
||||
func WriteFile(fs Filesystem, name string, data []byte, perm FileMode) error {
|
||||
f, err := fs.OpenFile(name, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, perm)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = f.Write(data)
|
||||
if err1 := f.Close(); err1 != nil && err == nil {
|
||||
err = err1
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user