all: Grand test refactor (fixes #8779, fixes #8799)

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:
Jakob Borg
2023-05-09 10:01:57 +00:00
co-authored by Eric P
parent ddce692f72
commit 1103a27337
54 changed files with 1133 additions and 1594 deletions
+11 -6
View File
@@ -10,6 +10,7 @@ import (
"errors"
"fmt"
"path"
"path/filepath"
"sort"
"strings"
"time"
@@ -90,11 +91,11 @@ func (f *FolderConfiguration) CreateMarker() error {
return nil
}
permBits := fs.FileMode(0777)
permBits := fs.FileMode(0o777)
if build.IsWindows {
// Windows has no umask so we must chose a safer set of bits to
// begin with.
permBits = 0700
permBits = 0o700
}
fs := f.Filesystem(nil)
err := fs.Mkdir(DefaultMarkerName, permBits)
@@ -113,7 +114,11 @@ func (f *FolderConfiguration) CreateMarker() error {
// CheckPath returns nil if the folder root exists and contains the marker file
func (f *FolderConfiguration) CheckPath() error {
fi, err := f.Filesystem(nil).Stat(".")
return f.checkFilesystemPath(f.Filesystem(nil), ".")
}
func (f *FolderConfiguration) checkFilesystemPath(ffs fs.Filesystem, path string) error {
fi, err := ffs.Stat(path)
if err != nil {
if !fs.IsNotExist(err) {
return err
@@ -131,7 +136,7 @@ func (f *FolderConfiguration) CheckPath() error {
return ErrPathNotDirectory
}
_, err = f.Filesystem(nil).Stat(f.MarkerName)
_, err = ffs.Stat(filepath.Join(path, f.MarkerName))
if err != nil {
if !fs.IsNotExist(err) {
return err
@@ -145,11 +150,11 @@ func (f *FolderConfiguration) CheckPath() error {
func (f *FolderConfiguration) CreateRoot() (err error) {
// Directory permission bits. Will be filtered down to something
// sane by umask on Unixes.
permBits := fs.FileMode(0777)
permBits := fs.FileMode(0o777)
if build.IsWindows {
// Windows has no umask so we must chose a safer set of bits to
// begin with.
permBits = 0700
permBits = 0o700
}
filesystem := f.Filesystem(nil)