Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

github: Update Go build matrix #385

Merged
merged 2 commits into from
Feb 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
test:
strategy:
matrix:
go-version: [1.16.x,1.17.x,1.18.x]
go-version: [1.18.x,1.19.x,1.20.x]
platform: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.platform }}
steps:
Expand All @@ -16,7 +16,7 @@ jobs:
with:
go-version: ${{ matrix.go-version }}
- name: Install staticcheck
if: matrix.go-version != '1.16.x'
if: matrix.go-version == '1.20.x'
run: go install honnef.co/go/tools/cmd/staticcheck@latest
shell: bash
- name: Update PATH
Expand All @@ -31,7 +31,7 @@ jobs:
- name: Vet
run: go vet ./...
- name: Staticcheck
if: matrix.go-version != '1.16.x'
if: matrix.go-version == '1.20.x'
run: staticcheck ./...
- name: Test
run: go test -race ./...
2 changes: 1 addition & 1 deletion afero.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ type Fs interface {
// Chown changes the uid and gid of the named file.
Chown(name string, uid, gid int) error

//Chtimes changes the access and modification times of the named file
// Chtimes changes the access and modification times of the named file
Chtimes(name string, atime time.Time, mtime time.Time) error
}

Expand Down
25 changes: 13 additions & 12 deletions afero_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ import (
"testing"
)

var testName = "test.txt"
var Fss = []Fs{&MemMapFs{}, &OsFs{}}
var (
testName = "test.txt"
Fss = []Fs{&MemMapFs{}, &OsFs{}}
)

var testRegistry map[Fs][]string = make(map[Fs][]string)

Expand All @@ -45,7 +47,6 @@ func testDir(fs Fs) string {

func tmpFile(fs Fs) File {
x, err := TempFile(fs, "", "afero")

if err != nil {
panic(fmt.Sprint("unable to work with temp file", err))
}
Expand All @@ -55,7 +56,7 @@ func tmpFile(fs Fs) File {
return x
}

//Read with length 0 should not return EOF.
// Read with length 0 should not return EOF.
func TestRead0(t *testing.T) {
for _, fs := range Fss {
f := tmpFile(fs)
Expand Down Expand Up @@ -83,31 +84,31 @@ func TestOpenFile(t *testing.T) {
tmp := testDir(fs)
path := filepath.Join(tmp, testName)

f, err := fs.OpenFile(path, os.O_RDWR|os.O_CREATE, 0600)
f, err := fs.OpenFile(path, os.O_RDWR|os.O_CREATE, 0o600)
if err != nil {
t.Error(fs.Name(), "OpenFile (O_CREATE) failed:", err)
continue
}
io.WriteString(f, "initial")
f.Close()

f, err = fs.OpenFile(path, os.O_WRONLY|os.O_APPEND, 0600)
f, err = fs.OpenFile(path, os.O_WRONLY|os.O_APPEND, 0o600)
if err != nil {
t.Error(fs.Name(), "OpenFile (O_APPEND) failed:", err)
continue
}
io.WriteString(f, "|append")
f.Close()

f, _ = fs.OpenFile(path, os.O_RDONLY, 0600)
f, _ = fs.OpenFile(path, os.O_RDONLY, 0o600)
contents, _ := ioutil.ReadAll(f)
expectedContents := "initial|append"
if string(contents) != expectedContents {
t.Errorf("%v: appending, expected '%v', got: '%v'", fs.Name(), expectedContents, string(contents))
}
f.Close()

f, err = fs.OpenFile(path, os.O_RDWR|os.O_TRUNC, 0600)
f, err = fs.OpenFile(path, os.O_RDWR|os.O_TRUNC, 0o600)
if err != nil {
t.Error(fs.Name(), "OpenFile (O_TRUNC) failed:", err)
continue
Expand Down Expand Up @@ -333,7 +334,7 @@ func TestSeek(t *testing.T) {
whence int
out int64
}
var tests = []test{
tests := []test{
{0, 1, int64(len(data))},
{0, 0, 0},
{5, 0, 5},
Expand Down Expand Up @@ -424,7 +425,7 @@ func setupTestDirReusePath(t *testing.T, fs Fs, path string) string {

func setupTestFiles(t *testing.T, fs Fs, path string) string {
testSubDir := filepath.Join(path, "more", "subdirectories", "for", "testing", "we")
err := fs.MkdirAll(testSubDir, 0700)
err := fs.MkdirAll(testSubDir, 0o700)
if err != nil && !os.IsExist(err) {
t.Fatal(err)
}
Expand Down Expand Up @@ -637,7 +638,7 @@ func TestReaddirAll(t *testing.T) {
if err != nil {
t.Fatal(err)
}
var namesRoot = []string{}
namesRoot := []string{}
for _, e := range rootInfo {
namesRoot = append(namesRoot, e.Name())
}
Expand All @@ -652,7 +653,7 @@ func TestReaddirAll(t *testing.T) {
if err != nil {
t.Fatal(err)
}
var namesSub = []string{}
namesSub := []string{}
for _, e := range subInfo {
namesSub = append(namesSub, e.Name())
}
Expand Down
1 change: 0 additions & 1 deletion basepath.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ func (f *BasePathFile) Name() string {
func (f *BasePathFile) ReadDir(n int) ([]fs.DirEntry, error) {
if rdf, ok := f.File.(fs.ReadDirFile); ok {
return rdf.ReadDir(n)

}
return readDirFile{f.File}.ReadDir(n)
}
Expand Down
19 changes: 8 additions & 11 deletions basepath_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

func TestBasePath(t *testing.T) {
baseFs := &MemMapFs{}
baseFs.MkdirAll("/base/path/tmp", 0777)
baseFs.MkdirAll("/base/path/tmp", 0o777)
bp := NewBasePathFs(baseFs, "/base/path")

if _, err := bp.Create("/tmp/foo"); err != nil {
Expand All @@ -23,8 +23,8 @@ func TestBasePath(t *testing.T) {

func TestBasePathRoot(t *testing.T) {
baseFs := &MemMapFs{}
baseFs.MkdirAll("/base/path/foo/baz", 0777)
baseFs.MkdirAll("/base/path/boo/", 0777)
baseFs.MkdirAll("/base/path/foo/baz", 0o777)
baseFs.MkdirAll("/base/path/boo/", 0o777)
bp := NewBasePathFs(baseFs, "/base/path")

rd, err := ReadDir(bp, string(os.PathSeparator))
Expand Down Expand Up @@ -56,7 +56,6 @@ func TestRealPath(t *testing.T) {
subDir := filepath.Join(baseDir, "s1")

realPath, err := bp.RealPath("/s1")

if err != nil {
t.Errorf("Got error %s", err)
}
Expand All @@ -77,7 +76,6 @@ func TestRealPath(t *testing.T) {
// is not inside the base file system.
// The user will receive an os.ErrNotExist later.
surrealPath, err := bp.RealPath(anotherDir)

if err != nil {
t.Errorf("Got error %s", err)
}
Expand All @@ -88,7 +86,6 @@ func TestRealPath(t *testing.T) {
t.Errorf("Expected \n%s got \n%s", excpected, surrealPath)
}
}

}

func TestNestedBasePaths(t *testing.T) {
Expand Down Expand Up @@ -119,7 +116,7 @@ func TestNestedBasePaths(t *testing.T) {
}

for _, s := range specs {
if err := s.BaseFs.MkdirAll(s.FileName, 0755); err != nil {
if err := s.BaseFs.MkdirAll(s.FileName, 0o755); err != nil {
t.Errorf("Got error %s", err.Error())
}
if _, err := s.BaseFs.Stat(s.FileName); err != nil {
Expand All @@ -143,9 +140,9 @@ func TestNestedBasePaths(t *testing.T) {

func TestBasePathOpenFile(t *testing.T) {
baseFs := &MemMapFs{}
baseFs.MkdirAll("/base/path/tmp", 0777)
baseFs.MkdirAll("/base/path/tmp", 0o777)
bp := NewBasePathFs(baseFs, "/base/path")
f, err := bp.OpenFile("/tmp/file.txt", os.O_CREATE, 0600)
f, err := bp.OpenFile("/tmp/file.txt", os.O_CREATE, 0o600)
if err != nil {
t.Fatalf("failed to open file: %v", err)
}
Expand All @@ -156,7 +153,7 @@ func TestBasePathOpenFile(t *testing.T) {

func TestBasePathCreate(t *testing.T) {
baseFs := &MemMapFs{}
baseFs.MkdirAll("/base/path/tmp", 0777)
baseFs.MkdirAll("/base/path/tmp", 0o777)
bp := NewBasePathFs(baseFs, "/base/path")
f, err := bp.Create("/tmp/file.txt")
if err != nil {
Expand All @@ -169,7 +166,7 @@ func TestBasePathCreate(t *testing.T) {

func TestBasePathTempFile(t *testing.T) {
baseFs := &MemMapFs{}
baseFs.MkdirAll("/base/path/tmp", 0777)
baseFs.MkdirAll("/base/path/tmp", 0o777)
bp := NewBasePathFs(baseFs, "/base/path")

tDir, err := TempDir(bp, "/tmp", "")
Expand Down
35 changes: 17 additions & 18 deletions composite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ func TestUnionCreateExisting(t *testing.T) {
roBase := &ReadOnlyFs{source: base}
ufs := NewCopyOnWriteFs(roBase, &MemMapFs{})

base.MkdirAll("/home/test", 0777)
base.MkdirAll("/home/test", 0o777)
fh, _ := base.Create("/home/test/file.txt")
fh.WriteString("This is a test")
fh.Close()

fh, err := ufs.OpenFile("/home/test/file.txt", os.O_RDWR, 0666)
fh, err := ufs.OpenFile("/home/test/file.txt", os.O_RDWR, 0o666)
if err != nil {
t.Errorf("Failed to open file r/w: %s", err)
}
Expand Down Expand Up @@ -95,7 +95,6 @@ func TestUnionCreateExisting(t *testing.T) {
default:
t.Errorf("Create failed on existing file")
}

}

func TestUnionMergeReaddir(t *testing.T) {
Expand All @@ -104,7 +103,7 @@ func TestUnionMergeReaddir(t *testing.T) {

ufs := &CopyOnWriteFs{base: roBase, layer: &MemMapFs{}}

base.MkdirAll("/home/test", 0777)
base.MkdirAll("/home/test", 0o777)
fh, _ := base.Create("/home/test/file.txt")
fh.WriteString("This is a test")
fh.Close()
Expand All @@ -130,12 +129,12 @@ func TestExistingDirectoryCollisionReaddir(t *testing.T) {

ufs := &CopyOnWriteFs{base: roBase, layer: overlay}

base.MkdirAll("/home/test", 0777)
base.MkdirAll("/home/test", 0o777)
fh, _ := base.Create("/home/test/file.txt")
fh.WriteString("This is a test")
fh.Close()

overlay.MkdirAll("home/test", 0777)
overlay.MkdirAll("home/test", 0o777)
fh, _ = overlay.Create("/home/test/file2.txt")
fh.WriteString("This is a test")
fh.Close()
Expand Down Expand Up @@ -170,7 +169,7 @@ func TestNestedDirBaseReaddir(t *testing.T) {

ufs := &CopyOnWriteFs{base: roBase, layer: overlay}

base.MkdirAll("/home/test/foo/bar", 0777)
base.MkdirAll("/home/test/foo/bar", 0o777)
fh, _ := base.Create("/home/test/file.txt")
fh.WriteString("This is a test")
fh.Close()
Expand All @@ -182,7 +181,7 @@ func TestNestedDirBaseReaddir(t *testing.T) {
fh.WriteString("This is a test")
fh.Close()

overlay.MkdirAll("/", 0777)
overlay.MkdirAll("/", 0o777)

// Opening something only in the base
fh, _ = ufs.Open("/home/test/foo")
Expand All @@ -205,8 +204,8 @@ func TestNestedDirOverlayReaddir(t *testing.T) {

ufs := &CopyOnWriteFs{base: roBase, layer: overlay}

base.MkdirAll("/", 0777)
overlay.MkdirAll("/home/test/foo/bar", 0777)
base.MkdirAll("/", 0o777)
overlay.MkdirAll("/home/test/foo/bar", 0o777)
fh, _ := overlay.Create("/home/test/file.txt")
fh.WriteString("This is a test")
fh.Close()
Expand Down Expand Up @@ -239,8 +238,8 @@ func TestNestedDirOverlayOsFsReaddir(t *testing.T) {

ufs := &CopyOnWriteFs{base: roBase, layer: overlay}

base.MkdirAll("/", 0777)
overlay.MkdirAll("/home/test/foo/bar", 0777)
base.MkdirAll("/", 0o777)
overlay.MkdirAll("/home/test/foo/bar", 0o777)
fh, _ := overlay.Create("/home/test/file.txt")
fh.WriteString("This is a test")
fh.Close()
Expand Down Expand Up @@ -274,12 +273,12 @@ func TestCopyOnWriteFsWithOsFs(t *testing.T) {

ufs := &CopyOnWriteFs{base: roBase, layer: overlay}

base.MkdirAll("/home/test", 0777)
base.MkdirAll("/home/test", 0o777)
fh, _ := base.Create("/home/test/file.txt")
fh.WriteString("This is a test")
fh.Close()

overlay.MkdirAll("home/test", 0777)
overlay.MkdirAll("home/test", 0o777)
fh, _ = overlay.Create("/home/test/file2.txt")
fh.WriteString("This is a test")
fh.Close()
Expand Down Expand Up @@ -315,7 +314,7 @@ func TestUnionCacheWrite(t *testing.T) {

ufs := NewCacheOnReadFs(base, layer, 0)

base.Mkdir("/data", 0777)
base.Mkdir("/data", 0o777)

fh, err := ufs.Create("/data/file.txt")
if err != nil {
Expand Down Expand Up @@ -344,7 +343,7 @@ func TestUnionCacheExpire(t *testing.T) {
layer := &MemMapFs{}
ufs := &CacheOnReadFs{base: base, layer: layer, cacheTime: 1 * time.Second}

base.Mkdir("/data", 0777)
base.Mkdir("/data", 0o777)

fh, err := ufs.Create("/data/file.txt")
if err != nil {
Expand Down Expand Up @@ -449,7 +448,7 @@ func TestUnionFileReaddirDuplicateEmpty(t *testing.T) {

// Overlay shares same empty directory as base
overlay := NewMemMapFs()
err = overlay.Mkdir(dir, 0700)
err = overlay.Mkdir(dir, 0o700)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -479,7 +478,7 @@ func TestUnionFileReaddirAskForTooMany(t *testing.T) {

const testFiles = 5
for i := 0; i < testFiles; i++ {
WriteFile(base, fmt.Sprintf("file%d.txt", i), []byte("afero"), 0777)
WriteFile(base, fmt.Sprintf("file%d.txt", i), []byte("afero"), 0o777)
}

ufs := &CopyOnWriteFs{base: base, layer: overlay}
Expand Down
9 changes: 5 additions & 4 deletions copyOnWriteFs.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func (u *CopyOnWriteFs) OpenFile(name string, flag int, perm os.FileMode) (File,
return nil, err
}
if isaDir {
if err = u.layer.MkdirAll(dir, 0777); err != nil {
if err = u.layer.MkdirAll(dir, 0o777); err != nil {
return nil, err
}
return u.layer.OpenFile(name, flag, perm)
Expand All @@ -247,8 +247,9 @@ func (u *CopyOnWriteFs) OpenFile(name string, flag int, perm os.FileMode) (File,

// This function handles the 9 different possibilities caused
// by the union which are the intersection of the following...
// layer: doesn't exist, exists as a file, and exists as a directory
// base: doesn't exist, exists as a file, and exists as a directory
//
// layer: doesn't exist, exists as a file, and exists as a directory
// base: doesn't exist, exists as a file, and exists as a directory
func (u *CopyOnWriteFs) Open(name string) (File, error) {
// Since the overlay overrides the base we check that first
b, err := u.isBaseFile(name)
Expand Down Expand Up @@ -322,5 +323,5 @@ func (u *CopyOnWriteFs) MkdirAll(name string, perm os.FileMode) error {
}

func (u *CopyOnWriteFs) Create(name string) (File, error) {
return u.OpenFile(name, os.O_CREATE|os.O_TRUNC|os.O_RDWR, 0666)
return u.OpenFile(name, os.O_CREATE|os.O_TRUNC|os.O_RDWR, 0o666)
}
Loading