diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dcdbfc3..e2834ec 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,31 +12,41 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-go@v5 with: - go-version: 1.19.x + go-version: 1.21.x - name: Lint run: make lint test: strategy: matrix: - platform: [ ubuntu-latest, windows-latest, macos-latest ] - version: [ v1.19.x ] - goarch: [ amd64, '386' ] - exclude: - - platform: macos-latest - goarch: '386' - - platform: windows-latest - goarch: '386' + platform: + - ubuntu-latest + go: + - 1.19.x + - 1.20.x + - 1.21.x + - 1.22.x + goarch: + - amd64 + include: + - platform: ubuntu-latest + go: 1.21.x + goarch: '386' # Verify fieldalignment on 32 bit platforms. + - platform: macos-latest + go: 1.21.x + goarch: amd64 + - platform: windows-latest + go: 1.21.x + goarch: amd64 runs-on: ${{ matrix.platform }} steps: - uses: actions/checkout@v4 - uses: actions/setup-go@v5 with: - go-version: ${{ matrix.version }} - architecture: ${{ matrix.goarch }} + go-version: ${{ matrix.go }} - name: Test run: make test env: GOARCH: ${{ matrix.goarch }} COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }} - COVERAGE_VERSION: '1.19' + COVERAGE_VERSION: '1.21' diff --git a/.golangci.yml b/.golangci.yml index 9a48dbf..0550d3c 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,8 +1,3 @@ -linters-settings: - govet: - enable: - - fieldalignment - linters: enable: # Default linters, plus these: @@ -16,6 +11,11 @@ linters: - paralleltest - revive +linters-settings: + govet: + enable: + - fieldalignment + issues: exclude: # Disable scopelint errors on table driven tests @@ -23,6 +23,11 @@ issues: # Disable documenting fstest Test functions - exported function Test\S* should have comment or be unexported - comment on exported function Test\S* should be of the form + exclude-rules: + - path: '(.+)_test\.go|^fstest/' # Disable some lint failures on test files and packages. + linters: + - govet + text: 'fieldalignment: struct with .* bytes could be .*' # Govet's fieldalignment memory size check on table-driven test case types requires field reordering to improve performance, which can lower readability without a meaningful impact to non-test code. include: # Re-enable default excluded rules - EXC0001 diff --git a/Makefile b/Makefile index 25827da..8ece4ef 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,13 @@ -BROWSERTEST_VERSION = v0.7 +BROWSERTEST_VERSION = v0.8 LINT_VERSION = 1.59.1 GO_BIN = $(shell printf '%s/bin' "$$(go env GOPATH)") SHELL = bash -ENABLE_RACE = true + +current_platform := $(shell go env GOOS)/$(shell go env GOARCH) +# Only use the race detector on supported architectures. +# Go's supported platforms pulled from 'go help build' under '-race'. +race_platforms := linux/amd64 freebsd/amd64 darwin/amd64 darwin/arm64 windows/amd64 linux/ppc64le linux/arm64 +RACE_ENABLED = $(if $(findstring ${current_platform},${race_platforms}),true,false) .PHONY: all all: lint test @@ -27,30 +32,19 @@ lint: lint-deps test-deps: @if [ ! -f "${GO_BIN}/go_js_wasm_exec" ]; then \ set -ex; \ - go install github.com/agnivade/wasmbrowsertest@${BROWSERTEST_VERSION}; \ + GOOS= GOARCH= go install github.com/agnivade/wasmbrowsertest@${BROWSERTEST_VERSION}; \ ln -s "${GO_BIN}/wasmbrowsertest" "${GO_BIN}/go_js_wasm_exec"; \ fi @go install github.com/mattn/goveralls@v0.0.9 -# only use the race detector on supported architectures -race_goarches := 'amd64' 'arm64' -ifeq (,$(findstring '$(GOARCH)',$(race_goarches))) -TEST_ARGS= -export CGO_ENABLED=0 -else -TEST_ARGS=-race -# the race detector needs cgo (at least on Linux and Windows, and macOS until Go 1.20) -export CGO_ENABLED=1 -endif - .PHONY: test test: test-deps go test . # Run library-level checks first, for more helpful build tag failure messages. - go test $(TEST_ARGS) -coverprofile=native-cover.out ./... + go test -race=${RACE_ENABLED} -coverprofile=native-cover.out ./... if [[ "$$CI" != true || $$(uname -s) == Linux ]]; then \ set -ex; \ GOOS=js GOARCH=wasm go test -coverprofile=js-cover.out -covermode=atomic ./...; \ - cd examples && go test $(TEST_ARGS) ./...; \ + cd examples && go test -race=${RACE_ENABLED} ./...; \ fi { echo 'mode: atomic'; cat *-cover.out | grep -v '^mode:'; } > cover.out && rm *-cover.out go tool cover -func cover.out | grep total: diff --git a/cache/fs.go b/cache/fs.go index 3ae2c87..19d30a4 100644 --- a/cache/fs.go +++ b/cache/fs.go @@ -89,7 +89,7 @@ func (fs *ReadOnlyFS) Open(name string) (hackpadfs.File, error) { func (fs *ReadOnlyFS) copyFile(name string, f hackpadfs.File, info hackpadfs.FileInfo) error { parentName := path.Dir(name) - if err := hackpadfs.MkdirAll(fs.cacheFS, parentName, 0700); err != nil { + if err := hackpadfs.MkdirAll(fs.cacheFS, parentName, 0o700); err != nil { return &hackpadfs.PathError{Op: "open", Path: parentName, Err: err} } destFile, err := fs.cacheFS.OpenFile(name, hackpadfs.FlagWriteOnly|hackpadfs.FlagCreate|hackpadfs.FlagTruncate, info.Mode()) diff --git a/fs.go b/fs.go index cbc5fa5..4cd87e3 100644 --- a/fs.go +++ b/fs.go @@ -170,7 +170,7 @@ func Create(fs FS, name string) (File, error) { if fs, ok := fs.(CreateFS); ok { return fs.Create(name) } - return OpenFile(fs, name, FlagReadWrite|FlagCreate|FlagTruncate, 0666) + return OpenFile(fs, name, FlagReadWrite|FlagCreate|FlagTruncate, 0o666) } // Mkdir creates a directory. Fails with a not implemented error if it's not a MkdirFS. diff --git a/fs_test.go b/fs_test.go index 4a1510b..b279d1d 100644 --- a/fs_test.go +++ b/fs_test.go @@ -57,7 +57,7 @@ func TestMkdirAll(t *testing.T) { t.Run("invalid path", func(t *testing.T) { t.Parallel() fs := makeSimplerFS(t) - err := hackpadfs.MkdirAll(fs, "foo/../bar", 0700) + err := hackpadfs.MkdirAll(fs, "foo/../bar", 0o700) if assert.IsType(t, &hackpadfs.PathError{}, err) { err := err.(*hackpadfs.PathError) assert.Equal(t, "mkdirall", err.Op) @@ -69,15 +69,15 @@ func TestMkdirAll(t *testing.T) { t.Run("make all", func(t *testing.T) { t.Parallel() fs := makeSimplerFS(t) - err := hackpadfs.MkdirAll(fs, "foo/bar", 0700) + err := hackpadfs.MkdirAll(fs, "foo/bar", 0o700) assert.NoError(t, err) }) t.Run("make once", func(t *testing.T) { t.Parallel() fs := makeSimplerFS(t) - assert.NoError(t, fs.simpler.Mkdir("foo", 0600)) - err := hackpadfs.MkdirAll(fs, "foo/bar", 0700) + assert.NoError(t, fs.simpler.Mkdir("foo", 0o600)) + err := hackpadfs.MkdirAll(fs, "foo/bar", 0o700) assert.NoError(t, err) }) @@ -87,7 +87,7 @@ func TestMkdirAll(t *testing.T) { f, err := hackpadfs.Create(fs.simpler, "foo") requireNoError(t, err) requireNoError(t, f.Close()) - err = hackpadfs.MkdirAll(fs, "foo/bar", 0700) + err = hackpadfs.MkdirAll(fs, "foo/bar", 0o700) if assert.IsType(t, &hackpadfs.PathError{}, err) { err := err.(*hackpadfs.PathError) assert.Equal(t, "mkdir", err.Op) @@ -112,7 +112,7 @@ func TestWriteFullFile(t *testing.T) { t.Parallel() fs := makeSimplerFS(t) - err := hackpadfs.WriteFullFile(fs, "foo", []byte("bar"), 0756) + err := hackpadfs.WriteFullFile(fs, "foo", []byte("bar"), 0o756) assert.NoError(t, err) contents, err := hackpadfs.ReadFile(fs, "foo") assert.NoError(t, err) @@ -123,8 +123,8 @@ func TestRemoveAll(t *testing.T) { t.Parallel() fs := makeSimplerFS(t) - assert.NoError(t, hackpadfs.MkdirAll(fs, "foo/bar", 0700)) - err := hackpadfs.WriteFullFile(fs, "foo/bar/baz", nil, 0700) + assert.NoError(t, hackpadfs.MkdirAll(fs, "foo/bar", 0o700)) + err := hackpadfs.WriteFullFile(fs, "foo/bar/baz", nil, 0o700) assert.NoError(t, err) err = hackpadfs.RemoveAll(fs, "foo") diff --git a/fstest/file.go b/fstest/file.go index a7726bb..c81bef1 100644 --- a/fstest/file.go +++ b/fstest/file.go @@ -87,11 +87,10 @@ func TestFileRead(tb testing.TB, o FSOptions) { }) } -//nolint:govet func TestFileReadAt(tb testing.TB, o FSOptions) { const fileContents = "hello world" setupFS, commit := o.Setup.FS(tb) - assert.NoError(tb, hackpadfs.WriteFullFile(setupFS, "foo", []byte(fileContents), 0666)) + assert.NoError(tb, hackpadfs.WriteFullFile(setupFS, "foo", []byte(fileContents), 0o666)) fs := commit() for _, tc := range []struct { @@ -245,7 +244,7 @@ func TestFileSeek(tb testing.TB, o FSOptions) { o.tbRun(tb, "seek current", func(tb testing.TB) { setupFS, commit := o.Setup.FS(tb) - assert.NoError(tb, hackpadfs.WriteFullFile(setupFS, "foo", []byte(fileContents), 0666)) + assert.NoError(tb, hackpadfs.WriteFullFile(setupFS, "foo", []byte(fileContents), 0o666)) fs := commit() file, err := fs.Open("foo") @@ -326,7 +325,7 @@ func testFileWrite(tb testing.TB, o FSOptions, writer func(hackpadfs.File, []byt o.tbRun(tb, "write-truncate-write-read", func(tb testing.TB) { const fileContents = "hello world" setupFS, commit := o.Setup.FS(tb) - assert.NoError(tb, hackpadfs.WriteFullFile(setupFS, "foo", []byte(fileContents), 0666)) + assert.NoError(tb, hackpadfs.WriteFullFile(setupFS, "foo", []byte(fileContents), 0o666)) fs := commit() file, err := hackpadfs.OpenFile(fs, "foo", hackpadfs.FlagReadWrite|hackpadfs.FlagTruncate, 0) @@ -469,7 +468,7 @@ func TestFileReadDir(tb testing.TB, o FSOptions) { if assert.NoError(tb, err) { assert.NoError(tb, file.Close()) } - assert.NoError(tb, setupFS.Mkdir("bar", 0700)) + assert.NoError(tb, setupFS.Mkdir("bar", 0o700)) fs := commit() file, err = fs.Open(".") @@ -482,8 +481,8 @@ func TestFileReadDir(tb testing.TB, o FSOptions) { return entries[a].Name() < entries[b].Name() }) o.assertSubsetQuickInfos(tb, []quickInfo{ - {Name: "bar", Mode: hackpadfs.ModeDir | 0700, IsDir: true}, - {Name: "foo", Mode: 0666}, + {Name: "bar", Mode: hackpadfs.ModeDir | 0o700, IsDir: true}, + {Name: "foo", Mode: 0o666}, }, asQuickDirInfos(tb, entries)) }) @@ -493,7 +492,7 @@ func TestFileReadDir(tb testing.TB, o FSOptions) { if assert.NoError(tb, err) { assert.NoError(tb, file.Close()) } - assert.NoError(tb, setupFS.Mkdir("bar", 0700)) + assert.NoError(tb, setupFS.Mkdir("bar", 0o700)) fs := commit() file, err = fs.Open(".") @@ -519,14 +518,14 @@ func TestFileReadDir(tb testing.TB, o FSOptions) { assert.Equal(tb, 2, len(entries)) o.assertSubsetQuickInfos(tb, asQuickDirInfos(tb, entries), asQuickDirInfos(tb, entriesAll)) o.assertSubsetQuickInfos(tb, []quickInfo{ - {Name: "bar", Mode: hackpadfs.ModeDir | 0700, IsDir: true}, - {Name: "foo", Mode: 0666}, + {Name: "bar", Mode: hackpadfs.ModeDir | 0o700, IsDir: true}, + {Name: "foo", Mode: 0o666}, }, asQuickDirInfos(tb, entriesAll)) }) o.tbRun(tb, "readdir high N", func(tb testing.TB) { setupFS, commit := o.Setup.FS(tb) - assert.NoError(tb, setupFS.Mkdir("bar", 0700)) + assert.NoError(tb, setupFS.Mkdir("bar", 0o700)) fs := commit() file, err := fs.Open(".") @@ -536,14 +535,14 @@ func TestFileReadDir(tb testing.TB, o FSOptions) { assert.NoError(tb, err) assert.NoError(tb, file.Close()) o.assertSubsetQuickInfos(tb, - []quickInfo{{Name: "bar", Mode: hackpadfs.ModeDir | 0700, IsDir: true}}, + []quickInfo{{Name: "bar", Mode: hackpadfs.ModeDir | 0o700, IsDir: true}}, asQuickDirInfos(tb, entries), ) }) o.tbRun(tb, "list empty subdirectory", func(tb testing.TB) { setupFS, commit := o.Setup.FS(tb) - assert.NoError(tb, setupFS.Mkdir("foo", 0700)) + assert.NoError(tb, setupFS.Mkdir("foo", 0o700)) fs := commit() file, err := fs.Open("foo") @@ -557,7 +556,7 @@ func TestFileReadDir(tb testing.TB, o FSOptions) { o.tbRun(tb, "list subdirectory", func(tb testing.TB) { setupFS, commit := o.Setup.FS(tb) - assert.NoError(tb, setupFS.Mkdir("foo", 0700)) + assert.NoError(tb, setupFS.Mkdir("foo", 0o700)) file, err := hackpadfs.Create(setupFS, "foo/bar") if assert.NoError(tb, err) { assert.NoError(tb, file.Close()) @@ -566,7 +565,7 @@ func TestFileReadDir(tb testing.TB, o FSOptions) { if assert.NoError(tb, err) { assert.NoError(tb, file.Close()) } - assert.NoError(tb, setupFS.Mkdir("foo/boo", 0700)) + assert.NoError(tb, setupFS.Mkdir("foo/boo", 0o700)) fs := commit() file, err = fs.Open("foo") @@ -579,9 +578,9 @@ func TestFileReadDir(tb testing.TB, o FSOptions) { return entries[a].Name() < entries[b].Name() }) o.assertEqualQuickInfos(tb, []quickInfo{ - {Name: "bar", Mode: 0666}, - {Name: "baz", Mode: 0666}, - {Name: "boo", Mode: hackpadfs.ModeDir | 0700, IsDir: true}, + {Name: "bar", Mode: 0o666}, + {Name: "baz", Mode: 0o666}, + {Name: "boo", Mode: hackpadfs.ModeDir | 0o700, IsDir: true}, }, asQuickDirInfos(tb, entries)) }) @@ -654,7 +653,6 @@ func TestFileSync(tb testing.TB, o FSOptions) { assert.NoError(tb, file.Close()) } -//nolint:govet func TestFileTruncate(tb testing.TB, o FSOptions) { const fileContents = "hello world" for _, tc := range []struct { @@ -704,12 +702,12 @@ func TestFileTruncate(tb testing.TB, o FSOptions) { Err: tc.expectErrKind, }, err) o.tryAssertEqualFS(tb, map[string]fsEntry{ - "foo": {Mode: 0666, Size: int64(len(fileContents))}, + "foo": {Mode: 0o666, Size: int64(len(fileContents))}, }, fs) } else { assert.NoError(tb, err) o.tryAssertEqualFS(tb, map[string]fsEntry{ - "foo": {Mode: 0666, Size: tc.size}, + "foo": {Mode: 0o666, Size: tc.size}, }, fs) } }) diff --git a/fstest/file_concurrent.go b/fstest/file_concurrent.go index e634d9f..b16f637 100644 --- a/fstest/file_concurrent.go +++ b/fstest/file_concurrent.go @@ -11,7 +11,7 @@ import ( func TestConcurrentFileRead(tb testing.TB, o FSOptions) { o.tbRun(tb, "same file path", func(tb testing.TB) { setupFS, commit := o.Setup.FS(tb) - assert.NoError(tb, hackpadfs.WriteFullFile(setupFS, "foo", []byte("hello world"), 0666)) + assert.NoError(tb, hackpadfs.WriteFullFile(setupFS, "foo", []byte("hello world"), 0o666)) fs := commit() concurrentTasks(0, func(_ int) { f, err := fs.Open("foo") @@ -30,7 +30,7 @@ func TestConcurrentFileRead(tb testing.TB, o FSOptions) { setupFS, commit := o.Setup.FS(tb) const fileCount = 10 for i := 0; i < fileCount; i++ { - assert.NoError(tb, hackpadfs.WriteFullFile(setupFS, fmt.Sprintf("foo-%d", i), []byte("hello world"), 0666)) + assert.NoError(tb, hackpadfs.WriteFullFile(setupFS, fmt.Sprintf("foo-%d", i), []byte("hello world"), 0o666)) } fs := commit() concurrentTasks(fileCount, func(i int) { @@ -102,7 +102,7 @@ func TestConcurrentFileStat(tb testing.TB, o FSOptions) { assert.NoError(tb, err) assert.Equal(tb, quickInfo{ Name: "foo", - Mode: 0666, + Mode: 0o666, }, asQuickInfo(info)) assert.NoError(tb, f.Close()) } diff --git a/fstest/fs.go b/fstest/fs.go index 48f1760..129e2fd 100644 --- a/fstest/fs.go +++ b/fstest/fs.go @@ -27,7 +27,7 @@ func TestBaseCreate(tb testing.TB, o FSOptions) { func TestBaseMkdir(tb testing.TB, o FSOptions) { _, commit := o.Setup.FS(tb) fs := commit() - err := hackpadfs.Mkdir(fs, "foo", 0600) + err := hackpadfs.Mkdir(fs, "foo", 0o600) skipNotImplemented(tb, err) assert.NoError(tb, err) } @@ -40,7 +40,7 @@ func TestBaseChmod(tb testing.TB, o FSOptions) { } fs := commit() - err = hackpadfs.Chmod(fs, "foo", 0755) + err = hackpadfs.Chmod(fs, "foo", 0o755) skipNotImplemented(tb, err) assert.NoError(tb, err) } @@ -90,7 +90,7 @@ func asQuickInfo(info hackpadfs.FileInfo) quickInfo { // // Create creates or truncates the named file. // If the file already exists, it is truncated. -// If the file does not exist, it is created with mode 0666 (before umask). +// If the file does not exist, it is created with mode 0o666 (before umask). // If successful, methods on the returned File can be used for I/O; the associated file descriptor has mode O_RDWR. // If there is an error, it will be of type *PathError. func TestCreate(tb testing.TB, o FSOptions) { @@ -121,7 +121,7 @@ func testCreate(tb testing.TB, o FSOptions, createFn func(hackpadfs.FS, string) o.assertEqualQuickInfo(tb, quickInfo{ Name: "foo", - Mode: hackpadfs.FileMode(0666), + Mode: hackpadfs.FileMode(0o666), }, asQuickInfo(info)) }) @@ -129,7 +129,7 @@ func testCreate(tb testing.TB, o FSOptions, createFn func(hackpadfs.FS, string) const fileContents = `hello world` setupFS, commit := o.Setup.FS(tb) - file, err := setupFS.OpenFile("foo", hackpadfs.FlagReadWrite|hackpadfs.FlagCreate, 0755) + file, err := setupFS.OpenFile("foo", hackpadfs.FlagReadWrite|hackpadfs.FlagCreate, 0o755) if assert.NoError(tb, err) { _, err = hackpadfs.WriteFile(file, []byte(fileContents)) assert.NoError(tb, err) @@ -146,13 +146,13 @@ func testCreate(tb testing.TB, o FSOptions, createFn func(hackpadfs.FS, string) o.assertEqualQuickInfo(tb, quickInfo{ Name: "foo", - Mode: 0755, + Mode: 0o755, }, asQuickInfo(info)) }) o.tbRun(tb, "existing directory", func(tb testing.TB) { setupFS, commit := o.Setup.FS(tb) - assert.NoError(tb, setupFS.Mkdir("foo", 0700)) + assert.NoError(tb, setupFS.Mkdir("foo", 0o700)) fs := commit() _, err := createFn(fs, "foo") o.assertEqualPathErr(tb, &hackpadfs.PathError{ @@ -209,17 +209,17 @@ func TestMkdir(tb testing.TB, o FSOptions) { o.tbRun(tb, "fail dir exists", func(tb testing.TB) { _, commit := o.Setup.FS(tb) fs := commit() - err := hackpadfs.Mkdir(fs, "foo", 0600) + err := hackpadfs.Mkdir(fs, "foo", 0o600) skipNotImplemented(tb, err) assert.NoError(tb, err) - err = hackpadfs.Mkdir(fs, "foo", 0600) + err = hackpadfs.Mkdir(fs, "foo", 0o600) o.assertEqualPathErr(tb, &hackpadfs.PathError{ Op: "mkdir", Path: "foo", Err: hackpadfs.ErrExist, }, err) o.tryAssertEqualFS(tb, map[string]fsEntry{ - "foo": {Mode: hackpadfs.ModeDir | 0600, IsDir: true}, + "foo": {Mode: hackpadfs.ModeDir | 0o600, IsDir: true}, }, fs) }) @@ -231,7 +231,7 @@ func TestMkdir(tb testing.TB, o FSOptions) { } fs := commit() - err = hackpadfs.Mkdir(fs, "foo", 0600) + err = hackpadfs.Mkdir(fs, "foo", 0o600) skipNotImplemented(tb, err) o.assertEqualPathErr(tb, &hackpadfs.PathError{ Op: "mkdir", @@ -239,41 +239,41 @@ func TestMkdir(tb testing.TB, o FSOptions) { Err: hackpadfs.ErrExist, }, err) o.tryAssertEqualFS(tb, map[string]fsEntry{ - "foo": {Mode: 0666}, + "foo": {Mode: 0o666}, }, fs) }) o.tbRun(tb, "create sub dir", func(tb testing.TB) { _, commit := o.Setup.FS(tb) fs := commit() - err := hackpadfs.Mkdir(fs, "foo", 0700) + err := hackpadfs.Mkdir(fs, "foo", 0o700) skipNotImplemented(tb, err) assert.NoError(tb, err) - err = hackpadfs.Mkdir(fs, "foo/bar", 0600) + err = hackpadfs.Mkdir(fs, "foo/bar", 0o600) assert.NoError(tb, err) o.tryAssertEqualFS(tb, map[string]fsEntry{ - "foo": {Mode: hackpadfs.ModeDir | 0700, IsDir: true}, - "foo/bar": {Mode: hackpadfs.ModeDir | 0600, IsDir: true}, + "foo": {Mode: hackpadfs.ModeDir | 0o700, IsDir: true}, + "foo/bar": {Mode: hackpadfs.ModeDir | 0o600, IsDir: true}, }, fs) }) o.tbRun(tb, "only permission bits allowed", func(tb testing.TB) { _, commit := o.Setup.FS(tb) fs := commit() - err := hackpadfs.Mkdir(fs, "foo", hackpadfs.ModeSocket|0755) + err := hackpadfs.Mkdir(fs, "foo", hackpadfs.ModeSocket|0o755) skipNotImplemented(tb, err) assert.NoError(tb, err) o.tryAssertEqualFS(tb, map[string]fsEntry{ - "foo": {Mode: hackpadfs.ModeDir | 0755, IsDir: true}, + "foo": {Mode: hackpadfs.ModeDir | 0o755, IsDir: true}, }, fs) }) o.tbRun(tb, "parent directory must exist", func(tb testing.TB) { _, commit := o.Setup.FS(tb) fs := commit() - err := hackpadfs.Mkdir(fs, "foo/bar", 0755) + err := hackpadfs.Mkdir(fs, "foo/bar", 0o755) skipNotImplemented(tb, err) o.assertEqualPathErr(tb, &hackpadfs.PathError{ Op: "mkdir", @@ -284,45 +284,45 @@ func TestMkdir(tb testing.TB, o FSOptions) { }) } -// MkdirAll creates a directory named path, along with any necessary parents, and returns nil, or else returns an error. +// TestMkdirAll tests MkdirAll. MkdirAll creates a directory named path, along with any necessary parents, and returns nil, or else returns an error. // The permission bits perm (before umask) are used for all directories that MkdirAll creates. // If path is already a directory, MkdirAll does nothing and returns nil. func TestMkdirAll(tb testing.TB, o FSOptions) { o.tbRun(tb, "create one directory", func(tb testing.TB) { _, commit := o.Setup.FS(tb) fs := commit() - err := hackpadfs.MkdirAll(fs, "foo", 0700) + err := hackpadfs.MkdirAll(fs, "foo", 0o700) skipNotImplemented(tb, err) assert.NoError(tb, err) o.tryAssertEqualFS(tb, map[string]fsEntry{ - "foo": {Mode: hackpadfs.ModeDir | 0700, IsDir: true}, + "foo": {Mode: hackpadfs.ModeDir | 0o700, IsDir: true}, }, fs) }) o.tbRun(tb, "create multiple directories", func(tb testing.TB) { _, commit := o.Setup.FS(tb) fs := commit() - err := hackpadfs.MkdirAll(fs, "foo/bar", 0700) + err := hackpadfs.MkdirAll(fs, "foo/bar", 0o700) skipNotImplemented(tb, err) assert.NoError(tb, err) o.tryAssertEqualFS(tb, map[string]fsEntry{ - "foo": {Mode: hackpadfs.ModeDir | 0700, IsDir: true}, - "foo/bar": {Mode: hackpadfs.ModeDir | 0700, IsDir: true}, + "foo": {Mode: hackpadfs.ModeDir | 0o700, IsDir: true}, + "foo/bar": {Mode: hackpadfs.ModeDir | 0o700, IsDir: true}, }, fs) }) o.tbRun(tb, "all directories exist", func(tb testing.TB) { setupFS, commit := o.Setup.FS(tb) - assert.NoError(tb, setupFS.Mkdir("foo", 0700)) - assert.NoError(tb, setupFS.Mkdir("foo/bar", 0644)) + assert.NoError(tb, setupFS.Mkdir("foo", 0o700)) + assert.NoError(tb, setupFS.Mkdir("foo/bar", 0o644)) fs := commit() - err := hackpadfs.MkdirAll(fs, "foo/bar", 0600) + err := hackpadfs.MkdirAll(fs, "foo/bar", 0o600) skipNotImplemented(tb, err) assert.NoError(tb, err) o.tryAssertEqualFS(tb, map[string]fsEntry{ - "foo": {Mode: hackpadfs.ModeDir | 0700, IsDir: true}, - "foo/bar": {Mode: hackpadfs.ModeDir | 0644, IsDir: true}, + "foo": {Mode: hackpadfs.ModeDir | 0o700, IsDir: true}, + "foo/bar": {Mode: hackpadfs.ModeDir | 0o644, IsDir: true}, }, fs) }) @@ -334,7 +334,7 @@ func TestMkdirAll(tb testing.TB, o FSOptions) { } fs := commit() - err = hackpadfs.MkdirAll(fs, "foo/bar", 0700) + err = hackpadfs.MkdirAll(fs, "foo/bar", 0o700) skipNotImplemented(tb, err) o.assertEqualPathErr(tb, &hackpadfs.PathError{ Op: "mkdir", @@ -342,24 +342,24 @@ func TestMkdirAll(tb testing.TB, o FSOptions) { Err: hackpadfs.ErrNotDir, }, err) o.tryAssertEqualFS(tb, map[string]fsEntry{ - "foo": {Mode: 0666}, + "foo": {Mode: 0o666}, }, fs) }) o.tbRun(tb, "illegal permission bits", func(tb testing.TB) { _, commit := o.Setup.FS(tb) fs := commit() - err := hackpadfs.MkdirAll(fs, "foo/bar", hackpadfs.ModeSocket|0777) + err := hackpadfs.MkdirAll(fs, "foo/bar", hackpadfs.ModeSocket|0o777) skipNotImplemented(tb, err) assert.NoError(tb, err) o.tryAssertEqualFS(tb, map[string]fsEntry{ - "foo": {Mode: hackpadfs.ModeDir | 0777, IsDir: true}, - "foo/bar": {Mode: hackpadfs.ModeDir | 0777, IsDir: true}, + "foo": {Mode: hackpadfs.ModeDir | 0o777, IsDir: true}, + "foo/bar": {Mode: hackpadfs.ModeDir | 0o777, IsDir: true}, }, fs) }) } -// Open opens the named file for reading. +// TestOpen tests Open. Open opens the named file for reading. // If successful, methods on the returned file can be used for reading; the associated file descriptor has mode O_RDONLY. // If there is an error, it will be of type *PathError. func TestOpen(tb testing.TB, o FSOptions) { @@ -447,7 +447,7 @@ func testOpen(tb testing.TB, o FSOptions, openFn func(hackpadfs.FS, string) (hac }) } -// OpenFile is the generalized open call; most users will use Open or Create instead. +// TestOpenFile tests OpenFile. OpenFile is the generalized open call; most users will use Open or Create instead. // It opens the named file with specified flag (O_RDONLY etc.). // If the file does not exist, and the O_CREATE flag is passed, it is created with mode perm (before umask). // If successful, methods on the returned File can be used for I/O. @@ -455,7 +455,7 @@ func testOpen(tb testing.TB, o FSOptions, openFn func(hackpadfs.FS, string) (hac func TestOpenFile(tb testing.TB, o FSOptions) { o.tbRun(tb, "read-only", func(tb testing.TB) { testOpen(tb, o, func(fs hackpadfs.FS, name string) (hackpadfs.File, error) { - file, err := hackpadfs.OpenFile(fs, name, hackpadfs.FlagReadOnly, 0777) + file, err := hackpadfs.OpenFile(fs, name, hackpadfs.FlagReadOnly, 0o777) skipNotImplemented(tb, err) return file, err }) @@ -463,7 +463,7 @@ func TestOpenFile(tb testing.TB, o FSOptions) { o.tbRun(tb, "create", func(tb testing.TB) { testCreate(tb, o, func(fs hackpadfs.FS, name string) (hackpadfs.File, error) { - file, err := hackpadfs.OpenFile(fs, name, hackpadfs.FlagReadWrite|hackpadfs.FlagCreate|hackpadfs.FlagTruncate, 0666) + file, err := hackpadfs.OpenFile(fs, name, hackpadfs.FlagReadWrite|hackpadfs.FlagCreate|hackpadfs.FlagTruncate, 0o666) skipNotImplemented(tb, err) return file, err }) @@ -472,13 +472,13 @@ func TestOpenFile(tb testing.TB, o FSOptions) { o.tbRun(tb, "create illegal perms", func(tb testing.TB) { _, commit := o.Setup.FS(tb) fs := commit() - f, err := hackpadfs.OpenFile(fs, "foo", hackpadfs.FlagReadOnly|hackpadfs.FlagCreate, hackpadfs.ModeSocket|0777) + f, err := hackpadfs.OpenFile(fs, "foo", hackpadfs.FlagReadOnly|hackpadfs.FlagCreate, hackpadfs.ModeSocket|0o777) skipNotImplemented(tb, err) if assert.NoError(tb, err) { assert.NoError(tb, f.Close()) } o.tryAssertEqualFS(tb, map[string]fsEntry{ - "foo": {Mode: 0777}, + "foo": {Mode: 0o777}, }, fs) }) @@ -493,20 +493,20 @@ func TestOpenFile(tb testing.TB, o FSOptions) { } fs := commit() - f, err = hackpadfs.OpenFile(fs, "foo", hackpadfs.FlagTruncate|hackpadfs.FlagWriteOnly, 0700) + f, err = hackpadfs.OpenFile(fs, "foo", hackpadfs.FlagTruncate|hackpadfs.FlagWriteOnly, 0o700) skipNotImplemented(tb, err) if assert.NoError(tb, err) { assert.NoError(tb, f.Close()) } o.tryAssertEqualFS(tb, map[string]fsEntry{ - "foo": {Mode: 0666}, + "foo": {Mode: 0o666}, }, fs) }) o.tbRun(tb, "truncate on non-existent file", func(tb testing.TB) { _, commit := o.Setup.FS(tb) fs := commit() - _, err := hackpadfs.OpenFile(fs, "foo", hackpadfs.FlagTruncate|hackpadfs.FlagWriteOnly, 0700) + _, err := hackpadfs.OpenFile(fs, "foo", hackpadfs.FlagTruncate|hackpadfs.FlagWriteOnly, 0o700) skipNotImplemented(tb, err) o.assertEqualPathErr(tb, &hackpadfs.PathError{ Op: "open", @@ -517,9 +517,9 @@ func TestOpenFile(tb testing.TB, o FSOptions) { o.tbRun(tb, "truncate on existing dir", func(tb testing.TB) { setupFS, commit := o.Setup.FS(tb) - assert.NoError(tb, setupFS.Mkdir("foo", 0700)) + assert.NoError(tb, setupFS.Mkdir("foo", 0o700)) fs := commit() - _, err := hackpadfs.OpenFile(fs, "foo", hackpadfs.FlagTruncate|hackpadfs.FlagWriteOnly, 0700) + _, err := hackpadfs.OpenFile(fs, "foo", hackpadfs.FlagTruncate|hackpadfs.FlagWriteOnly, 0o700) skipNotImplemented(tb, err) o.assertEqualPathErr(tb, &hackpadfs.PathError{ Op: "open", @@ -543,7 +543,7 @@ func TestOpenFile(tb testing.TB, o FSOptions) { } fs := commit() - f, err = hackpadfs.OpenFile(fs, "foo", hackpadfs.FlagReadWrite|hackpadfs.FlagAppend, 0700) + f, err = hackpadfs.OpenFile(fs, "foo", hackpadfs.FlagReadWrite|hackpadfs.FlagAppend, 0o700) skipNotImplemented(tb, err) if assert.NoError(tb, err) { _, err = hackpadfs.WriteFile(f, []byte(fileContents2)) @@ -551,12 +551,12 @@ func TestOpenFile(tb testing.TB, o FSOptions) { assert.NoError(tb, f.Close()) } o.tryAssertEqualFS(tb, map[string]fsEntry{ - "foo": {Mode: 0666, Size: int64(len(fileContents1) + len(fileContents2))}, + "foo": {Mode: 0o666, Size: int64(len(fileContents1) + len(fileContents2))}, }, fs) }) } -// Remove removes the named file or (empty) directory. If there is an error, it will be of type *PathError. +// TestRemove tests Remove. Remove removes the named file or (empty) directory. If there is an error, it will be of type *PathError. func TestRemove(tb testing.TB, o FSOptions) { o.tbRun(tb, "remove file", func(tb testing.TB) { setupFS, commit := o.Setup.FS(tb) @@ -574,7 +574,7 @@ func TestRemove(tb testing.TB, o FSOptions) { o.tbRun(tb, "remove empty dir", func(tb testing.TB) { setupFS, commit := o.Setup.FS(tb) - assert.NoError(tb, setupFS.Mkdir("foo", 0700)) + assert.NoError(tb, setupFS.Mkdir("foo", 0o700)) fs := commit() err := hackpadfs.Remove(fs, "foo") @@ -597,7 +597,7 @@ func TestRemove(tb testing.TB, o FSOptions) { o.tbRun(tb, "remove non-empty dir", func(tb testing.TB) { setupFS, commit := o.Setup.FS(tb) - assert.NoError(tb, setupFS.Mkdir("foo", 0700)) + assert.NoError(tb, setupFS.Mkdir("foo", 0o700)) f, err := hackpadfs.Create(setupFS, "foo/bar") if assert.NoError(tb, err) { assert.NoError(tb, f.Close()) @@ -612,13 +612,13 @@ func TestRemove(tb testing.TB, o FSOptions) { Err: hackpadfs.ErrNotEmpty, }, err) o.tryAssertEqualFS(tb, map[string]fsEntry{ - "foo": {Mode: hackpadfs.ModeDir | 0700, IsDir: true}, - "foo/bar": {Mode: 0666}, + "foo": {Mode: hackpadfs.ModeDir | 0o700, IsDir: true}, + "foo/bar": {Mode: 0o666}, }, fs) }) } -// RemoveAll removes path and any children it contains. +// TestRemoveAll tests RemoveAll. RemoveAll removes path and any children it contains. // It removes everything it can but returns the first error it encounters. // If the path does not exist, RemoveAll returns nil (no error). // If there is an error, it will be of type *PathError. @@ -639,7 +639,7 @@ func TestRemoveAll(tb testing.TB, o FSOptions) { o.tbRun(tb, "remove empty dir", func(tb testing.TB) { setupFS, commit := o.Setup.FS(tb) - assert.NoError(tb, setupFS.Mkdir("foo", 0700)) + assert.NoError(tb, setupFS.Mkdir("foo", 0o700)) fs := commit() err := hackpadfs.RemoveAll(fs, "foo") @@ -659,7 +659,7 @@ func TestRemoveAll(tb testing.TB, o FSOptions) { o.tbRun(tb, "remove non-empty dir", func(tb testing.TB) { setupFS, commit := o.Setup.FS(tb) - assert.NoError(tb, setupFS.Mkdir("foo", 0700)) + assert.NoError(tb, setupFS.Mkdir("foo", 0o700)) f, err := hackpadfs.Create(setupFS, "foo/bar") if assert.NoError(tb, err) { assert.NoError(tb, f.Close()) @@ -695,7 +695,7 @@ func TestRename(tb testing.TB, o FSOptions) { o.tbRun(tb, "inside same directory", func(tb testing.TB) { setupFS, commit := o.Setup.FS(tb) - assert.NoError(tb, setupFS.Mkdir("foo", 0700)) + assert.NoError(tb, setupFS.Mkdir("foo", 0o700)) f, err := hackpadfs.Create(setupFS, "foo/bar") if assert.NoError(tb, err) { assert.NoError(tb, f.Close()) @@ -706,8 +706,8 @@ func TestRename(tb testing.TB, o FSOptions) { skipNotImplemented(tb, err) assert.NoError(tb, err) o.tryAssertEqualFS(tb, map[string]fsEntry{ - "foo": {Mode: hackpadfs.ModeDir | 0700, IsDir: true}, - "foo/baz": {Mode: 0666}, + "foo": {Mode: hackpadfs.ModeDir | 0o700, IsDir: true}, + "foo/baz": {Mode: 0o666}, }, fs) }) @@ -723,29 +723,29 @@ func TestRename(tb testing.TB, o FSOptions) { skipNotImplemented(tb, err) assert.NoError(tb, err) o.tryAssertEqualFS(tb, map[string]fsEntry{ - "baz": {Mode: 0666}, + "baz": {Mode: 0o666}, }, fs) }) o.tbRun(tb, "same file", func(tb testing.TB) { const fileContents = `hello world` setupFS, commit := o.Setup.FS(tb) - assert.NoError(tb, setupFS.Mkdir("foo", 0700)) - assert.NoError(tb, hackpadfs.WriteFullFile(setupFS, "foo/bar", []byte(fileContents), 0666)) + assert.NoError(tb, setupFS.Mkdir("foo", 0o700)) + assert.NoError(tb, hackpadfs.WriteFullFile(setupFS, "foo/bar", []byte(fileContents), 0o666)) fs := commit() err := hackpadfs.Rename(fs, "foo/bar", "foo/bar") skipNotImplemented(tb, err) assert.NoError(tb, err) o.tryAssertEqualFS(tb, map[string]fsEntry{ - "foo": {Mode: hackpadfs.ModeDir | 0700, IsDir: true}, - "foo/bar": {Mode: 0666, Size: int64(len(fileContents))}, + "foo": {Mode: hackpadfs.ModeDir | 0o700, IsDir: true}, + "foo/bar": {Mode: 0o666, Size: int64(len(fileContents))}, }, fs) }) o.tbRun(tb, "same directory", func(tb testing.TB) { setupFS, commit := o.Setup.FS(tb) - assert.NoError(tb, setupFS.Mkdir("foo", 0700)) + assert.NoError(tb, setupFS.Mkdir("foo", 0o700)) fs := commit() err := hackpadfs.Rename(fs, "foo", "foo") @@ -767,14 +767,14 @@ func TestRename(tb testing.TB, o FSOptions) { } } o.tryAssertEqualFS(tb, map[string]fsEntry{ - "foo": {Mode: hackpadfs.ModeDir | 0700, IsDir: true}, + "foo": {Mode: hackpadfs.ModeDir | 0o700, IsDir: true}, }, fs) }) o.tbRun(tb, "newpath is directory", func(tb testing.TB) { setupFS, commit := o.Setup.FS(tb) - assert.NoError(tb, setupFS.Mkdir("foo", 0700)) - assert.NoError(tb, setupFS.Mkdir("bar", 0700)) + assert.NoError(tb, setupFS.Mkdir("foo", 0o700)) + assert.NoError(tb, setupFS.Mkdir("bar", 0o700)) fs := commit() err := hackpadfs.Rename(fs, "foo", "bar") @@ -795,61 +795,61 @@ func TestRename(tb testing.TB, o FSOptions) { } } o.tryAssertEqualFS(tb, map[string]fsEntry{ - "foo": {Mode: hackpadfs.ModeDir | 0700, IsDir: true}, - "bar": {Mode: hackpadfs.ModeDir | 0700, IsDir: true}, + "foo": {Mode: hackpadfs.ModeDir | 0o700, IsDir: true}, + "bar": {Mode: hackpadfs.ModeDir | 0o700, IsDir: true}, }, fs) }) o.tbRun(tb, "newpath in root", func(tb testing.TB) { const fileContents = `hello world` setupFS, commit := o.Setup.FS(tb) - assert.NoError(tb, setupFS.Mkdir("foo", 0700)) - assert.NoError(tb, hackpadfs.WriteFullFile(setupFS, "foo/bar", []byte(fileContents), 0666)) + assert.NoError(tb, setupFS.Mkdir("foo", 0o700)) + assert.NoError(tb, hackpadfs.WriteFullFile(setupFS, "foo/bar", []byte(fileContents), 0o666)) fs := commit() err := hackpadfs.Rename(fs, "foo/bar", "baz") skipNotImplemented(tb, err) assert.NoError(tb, err) o.tryAssertEqualFS(tb, map[string]fsEntry{ - "foo": {Mode: hackpadfs.ModeDir | 0700, IsDir: true}, - "baz": {Mode: 0666, Size: int64(len(fileContents))}, + "foo": {Mode: hackpadfs.ModeDir | 0o700, IsDir: true}, + "baz": {Mode: 0o666, Size: int64(len(fileContents))}, }, fs) }) o.tbRun(tb, "newpath in subdirectory", func(tb testing.TB) { const fileContents = `hello world` setupFS, commit := o.Setup.FS(tb) - assert.NoError(tb, setupFS.Mkdir("foo", 0700)) - assert.NoError(tb, hackpadfs.WriteFullFile(setupFS, "bar", []byte(fileContents), 0666)) + assert.NoError(tb, setupFS.Mkdir("foo", 0o700)) + assert.NoError(tb, hackpadfs.WriteFullFile(setupFS, "bar", []byte(fileContents), 0o666)) fs := commit() err := hackpadfs.Rename(fs, "bar", "foo/baz") skipNotImplemented(tb, err) assert.NoError(tb, err) o.tryAssertEqualFS(tb, map[string]fsEntry{ - "foo": {Mode: hackpadfs.ModeDir | 0700, IsDir: true}, - "foo/baz": {Mode: 0666, Size: int64(len(fileContents))}, + "foo": {Mode: hackpadfs.ModeDir | 0o700, IsDir: true}, + "foo/baz": {Mode: 0o666, Size: int64(len(fileContents))}, }, fs) }) o.tbRun(tb, "non-empty directory", func(tb testing.TB) { const fileContents = `hello world` setupFS, commit := o.Setup.FS(tb) - assert.NoError(tb, setupFS.Mkdir("foo", 0700)) - assert.NoError(tb, hackpadfs.WriteFullFile(setupFS, "foo/bar", []byte(fileContents), 0666)) + assert.NoError(tb, setupFS.Mkdir("foo", 0o700)) + assert.NoError(tb, hackpadfs.WriteFullFile(setupFS, "foo/bar", []byte(fileContents), 0o666)) fs := commit() err := hackpadfs.Rename(fs, "foo", "baz") skipNotImplemented(tb, err) assert.NoError(tb, err) o.tryAssertEqualFS(tb, map[string]fsEntry{ - "baz": {Mode: hackpadfs.ModeDir | 0700, IsDir: true}, - "baz/bar": {Mode: 0666, Size: int64(len(fileContents))}, + "baz": {Mode: hackpadfs.ModeDir | 0o700, IsDir: true}, + "baz/bar": {Mode: 0o666, Size: int64(len(fileContents))}, }, fs) }) } -// Stat returns a FileInfo describing the named file. If there is an error, it will be of type *PathError. +// TestStat tests Stat. Stat returns a FileInfo describing the named file. If there is an error, it will be of type *PathError. func TestStat(tb testing.TB, o FSOptions) { testStat(tb, o, func(tb testing.TB, fs hackpadfs.FS, path string) (hackpadfs.FileInfo, error) { info, err := hackpadfs.Stat(fs, path) @@ -885,14 +885,14 @@ func testStat(tb testing.TB, o FSOptions, stater func(testing.TB, hackpadfs.FS, if assert.NoError(tb, err) { assert.NoError(tb, f.Close()) } - assert.NoError(tb, hackpadfs.Chmod(setupFS, "foo", 0755)) + assert.NoError(tb, hackpadfs.Chmod(setupFS, "foo", 0o755)) fs := commit() info, err := stater(tb, fs, "foo") assert.NoError(tb, err) o.assertEqualQuickInfo(tb, quickInfo{ Name: "foo", - Mode: 0755, + Mode: 0o755, }, asQuickInfo(info)) assert.NotPanics(tb, func() { _ = info.Sys() @@ -901,7 +901,7 @@ func testStat(tb testing.TB, o FSOptions, stater func(testing.TB, hackpadfs.FS, o.tbRun(tb, "stat a directory", func(tb testing.TB) { setupFS, commit := o.Setup.FS(tb) - err := setupFS.Mkdir("foo", 0755) + err := setupFS.Mkdir("foo", 0o755) assert.NoError(tb, err) fs := commit() @@ -909,16 +909,16 @@ func testStat(tb testing.TB, o FSOptions, stater func(testing.TB, hackpadfs.FS, assert.NoError(tb, err) o.assertEqualQuickInfo(tb, quickInfo{ Name: "foo", - Mode: hackpadfs.ModeDir | 0755, + Mode: hackpadfs.ModeDir | 0o755, IsDir: true, }, asQuickInfo(info)) }) o.tbRun(tb, "stat nested files", func(tb testing.TB) { setupFS, commit := o.Setup.FS(tb) - err := setupFS.Mkdir("foo", 0755) + err := setupFS.Mkdir("foo", 0o755) assert.NoError(tb, err) - err = setupFS.Mkdir("foo/bar", 0755) + err = setupFS.Mkdir("foo/bar", 0o755) assert.NoError(tb, err) f, err := hackpadfs.Create(setupFS, "foo/bar/baz") if assert.NoError(tb, err) { @@ -932,17 +932,17 @@ func testStat(tb testing.TB, o FSOptions, stater func(testing.TB, hackpadfs.FS, assert.NoError(tb, err) o.assertEqualQuickInfo(tb, quickInfo{ Name: "bar", - Mode: hackpadfs.ModeDir | 0755, + Mode: hackpadfs.ModeDir | 0o755, IsDir: true, }, asQuickInfo(info1)) o.assertEqualQuickInfo(tb, quickInfo{ Name: "baz", - Mode: 0666, + Mode: 0o666, }, asQuickInfo(info2)) }) } -// Chmod changes the mode of the named file to mode. +// TestChmod tests Chmod. Chmod changes the mode of the named file to mode. // If the file is a symbolic link, it changes the mode of the link's target. // If there is an error, it will be of type *PathError. // @@ -958,14 +958,14 @@ func TestChmod(tb testing.TB, o FSOptions) { } fs := commit() - err = hackpadfs.Chmod(fs, "foo", 0755) + err = hackpadfs.Chmod(fs, "foo", 0o755) skipNotImplemented(tb, err) assert.NoError(tb, err) info, err := hackpadfs.Stat(fs, "foo") assert.NoError(tb, err) o.assertEqualQuickInfo(tb, quickInfo{ Name: "foo", - Mode: 0755, + Mode: 0o755, }, asQuickInfo(info)) }) @@ -981,7 +981,7 @@ func TestChmod(tb testing.TB, o FSOptions) { assert.NoError(tb, hackpadfs.Symlink(setupFS, "foo", "bar")) fs := commit() - err = hackpadfs.Chmod(fs, "foo", 0755) + err = hackpadfs.Chmod(fs, "foo", 0o755) skipNotImplemented(tb, err) assert.NoError(tb, err) linkInfo, err := hackpadfs.Stat(fs, "foo") @@ -990,16 +990,16 @@ func TestChmod(tb testing.TB, o FSOptions) { assert.NoError(tb, err) o.assertEqualQuickInfo(tb, quickInfo{ Name: "foo", - Mode: 0755, + Mode: 0o755, }, asQuickInfo(linkInfo)) o.assertEqualQuickInfo(tb, quickInfo{ Name: "bar", - Mode: 0755, + Mode: 0o755, }, asQuickInfo(info)) }) } -// Chtimes changes the access and modification times of the named file, similar to the Unix utime() or utimes() functions. +// TestChtimes tests Chtimes. Chtimes changes the access and modification times of the named file, similar to the Unix utime() or utimes() functions. // // The underlying filesystem may truncate or round the values to a less precise time unit. If there is an error, it will be of type *PathError. func TestChtimes(tb testing.TB, o FSOptions) { @@ -1035,7 +1035,7 @@ func TestChtimes(tb testing.TB, o FSOptions) { assert.NoError(tb, err) if o.assertEqualQuickInfo(tb, quickInfo{ Name: "foo", - Mode: 0666, + Mode: 0o666, }, asQuickInfo(info)) { assert.Equal(tb, modifyTime.Format(time.RFC3339), info.ModTime().Local().Format(time.RFC3339)) } @@ -1058,7 +1058,7 @@ func TestReadFile(tb testing.TB, o FSOptions) { o.tbRun(tb, "exists", func(tb testing.TB) { setupFS, commit := o.Setup.FS(tb) const contents = "hello" - assert.NoError(tb, hackpadfs.WriteFullFile(setupFS, "foo", []byte(contents), 0666)) + assert.NoError(tb, hackpadfs.WriteFullFile(setupFS, "foo", []byte(contents), 0o666)) fs := commit() buf, err := hackpadfs.ReadFile(fs, "foo") @@ -1071,7 +1071,7 @@ func TestReadFile(tb testing.TB, o FSOptions) { func TestReadDir(tb testing.TB, o FSOptions) { o.tbRun(tb, "exists", func(tb testing.TB) { setupFS, commit := o.Setup.FS(tb) - err := hackpadfs.MkdirAll(setupFS, "foo/bar", 0777) + err := hackpadfs.MkdirAll(setupFS, "foo/bar", 0o777) assert.NoError(tb, err) f, err := hackpadfs.Create(setupFS, "foo/baz") if assert.NoError(tb, err) { @@ -1095,7 +1095,7 @@ func TestReadDir(tb testing.TB, o FSOptions) { assert.NoError(tb, err) assert.Equal(tb, quickInfo{ Name: "bar", - Mode: hackpadfs.ModeDir | 0777, + Mode: hackpadfs.ModeDir | 0o777, IsDir: true, }, asQuickInfo(info)) assert.Equal(tb, true, dir[0].IsDir()) @@ -1107,7 +1107,7 @@ func TestReadDir(tb testing.TB, o FSOptions) { assert.NoError(tb, err) assert.Equal(tb, quickInfo{ Name: "baz", - Mode: 0666, + Mode: 0o666, IsDir: false, }, asQuickInfo(info)) assert.Equal(tb, false, dir[1].IsDir()) @@ -1119,7 +1119,7 @@ func TestReadDir(tb testing.TB, o FSOptions) { assert.NoError(tb, err) assert.Equal(tb, quickInfo{ Name: "biff", - Mode: 0666, + Mode: 0o666, IsDir: false, }, asQuickInfo(info)) assert.Equal(tb, false, dir[2].IsDir()) @@ -1168,12 +1168,12 @@ func TestWriteFile(tb testing.TB, o FSOptions) { o.tbRun(tb, "not exists", func(tb testing.TB) { _, commit := o.Setup.FS(tb) fs := commit() - err := hackpadfs.WriteFullFile(fs, "foo", []byte("bar"), 0765) + err := hackpadfs.WriteFullFile(fs, "foo", []byte("bar"), 0o765) skipNotImplemented(tb, err) assert.NoError(tb, err) o.tryAssertEqualFS(tb, map[string]fsEntry{ - "foo": {Size: 3, Mode: 0765}, + "foo": {Size: 3, Mode: 0o765}, }, fs) contents, err := hackpadfs.ReadFile(fs, "foo") assert.NoError(tb, err) @@ -1184,7 +1184,7 @@ func TestWriteFile(tb testing.TB, o FSOptions) { setupFS, commit := o.Setup.FS(tb) const ( contents = "bar" - perm = 0666 + perm = 0o666 ) f, err := setupFS.OpenFile("foo", hackpadfs.FlagWriteOnly|hackpadfs.FlagCreate, perm) if assert.NoError(tb, err) { @@ -1196,7 +1196,7 @@ func TestWriteFile(tb testing.TB, o FSOptions) { fs := commit() const ( newContents = "baz" - newPerm = 0765 + newPerm = 0o765 ) err = hackpadfs.WriteFullFile(fs, "foo", []byte(newContents), newPerm) skipNotImplemented(tb, err) @@ -1212,11 +1212,11 @@ func TestWriteFile(tb testing.TB, o FSOptions) { o.tbRun(tb, "dir exists", func(tb testing.TB) { setupFS, commit := o.Setup.FS(tb) - err := setupFS.Mkdir("foo", 0700) + err := setupFS.Mkdir("foo", 0o700) assert.NoError(tb, err) fs := commit() - err = hackpadfs.WriteFullFile(fs, "foo", []byte("bar"), 0765) + err = hackpadfs.WriteFullFile(fs, "foo", []byte("bar"), 0o765) skipNotImplemented(tb, err) o.assertEqualPathErr(tb, &hackpadfs.PathError{ Op: "open", @@ -1225,7 +1225,7 @@ func TestWriteFile(tb testing.TB, o FSOptions) { }, err) o.tryAssertEqualFS(tb, map[string]fsEntry{ - "foo": {Mode: 0700, IsDir: true}, + "foo": {Mode: 0o700, IsDir: true}, }, fs) }) } diff --git a/fstest/fs_concurrent.go b/fstest/fs_concurrent.go index a7a4fce..78ae7c8 100644 --- a/fstest/fs_concurrent.go +++ b/fstest/fs_concurrent.go @@ -61,7 +61,7 @@ func TestConcurrentOpenFileCreate(tb testing.TB, o FSOptions) { _, commit := o.Setup.FS(tb) fs := commit() concurrentTasks(0, func(_ int) { - f, err := hackpadfs.OpenFile(fs, "foo", hackpadfs.FlagReadWrite|hackpadfs.FlagCreate|hackpadfs.FlagTruncate, 0666) + f, err := hackpadfs.OpenFile(fs, "foo", hackpadfs.FlagReadWrite|hackpadfs.FlagCreate|hackpadfs.FlagTruncate, 0o666) skipNotImplemented(tb, err) if assert.NoError(tb, err) { assert.NoError(tb, f.Close()) @@ -73,7 +73,7 @@ func TestConcurrentOpenFileCreate(tb testing.TB, o FSOptions) { _, commit := o.Setup.FS(tb) fs := commit() concurrentTasks(0, func(i int) { - f, err := hackpadfs.OpenFile(fs, fmt.Sprintf("foo-%d", i), hackpadfs.FlagReadWrite|hackpadfs.FlagCreate|hackpadfs.FlagTruncate, 0666) + f, err := hackpadfs.OpenFile(fs, fmt.Sprintf("foo-%d", i), hackpadfs.FlagReadWrite|hackpadfs.FlagCreate|hackpadfs.FlagTruncate, 0o666) skipNotImplemented(tb, err) if assert.NoError(tb, err) { assert.NoError(tb, f.Close()) @@ -120,7 +120,7 @@ func TestConcurrentMkdir(tb testing.TB, o FSOptions) { _, commit := o.Setup.FS(tb) fs := commit() concurrentTasks(0, func(_ int) { - err := hackpadfs.Mkdir(fs, "foo", 0777) + err := hackpadfs.Mkdir(fs, "foo", 0o777) skipNotImplemented(tb, err) assert.Equal(tb, true, err == nil || errors.Is(err, hackpadfs.ErrExist)) }) @@ -130,7 +130,7 @@ func TestConcurrentMkdir(tb testing.TB, o FSOptions) { _, commit := o.Setup.FS(tb) fs := commit() concurrentTasks(0, func(i int) { - err := hackpadfs.Mkdir(fs, fmt.Sprintf("foo-%d", i), 0777) + err := hackpadfs.Mkdir(fs, fmt.Sprintf("foo-%d", i), 0o777) skipNotImplemented(tb, err) assert.NoError(tb, err) }) @@ -142,7 +142,7 @@ func TestConcurrentMkdirAll(tb testing.TB, o FSOptions) { _, commit := o.Setup.FS(tb) fs := commit() concurrentTasks(0, func(_ int) { - err := hackpadfs.MkdirAll(fs, "foo", 0777) + err := hackpadfs.MkdirAll(fs, "foo", 0o777) skipNotImplemented(tb, err) assert.NoError(tb, err) }) @@ -152,7 +152,7 @@ func TestConcurrentMkdirAll(tb testing.TB, o FSOptions) { _, commit := o.Setup.FS(tb) fs := commit() concurrentTasks(0, func(i int) { - err := hackpadfs.MkdirAll(fs, fmt.Sprintf("foo-%d", i), 0777) + err := hackpadfs.MkdirAll(fs, fmt.Sprintf("foo-%d", i), 0o777) skipNotImplemented(tb, err) assert.NoError(tb, err) }) diff --git a/indexeddb/fs.go b/indexeddb/fs.go index fe9165a..afb928a 100644 --- a/indexeddb/fs.go +++ b/indexeddb/fs.go @@ -94,7 +94,7 @@ func (fs *FS) Clear(ctx context.Context) error { if err != nil { return err } - return fs.Mkdir(".", 0666) + return fs.Mkdir(".", 0o666) } // Open implements hackpadfs.FS diff --git a/indexeddb/store_test.go b/indexeddb/store_test.go index 031e5df..40eb02c 100644 --- a/indexeddb/store_test.go +++ b/indexeddb/store_test.go @@ -30,7 +30,7 @@ func testFile(contents string) (keyvalue.FileRecord, blob.Blob) { return keyvalue.NewBaseFileRecord( int64(len(data)), nowTruncated(), - 0600, + 0o600, nil, func() (blob.Blob, error) { return blob.NewBytes(data), nil diff --git a/keyvalue/fs.go b/keyvalue/fs.go index d9641e0..6a6a299 100644 --- a/keyvalue/fs.go +++ b/keyvalue/fs.go @@ -22,7 +22,7 @@ func NewFS(store Store) (*FS, error) { fs := &FS{ store: newFSTransactioner(store), } - err := fs.Mkdir(".", 0666) + err := fs.Mkdir(".", 0o666) return fs, ignoreErrExist(err) } diff --git a/mount/fs_test.go b/mount/fs_test.go index 9f39aa5..771831b 100644 --- a/mount/fs_test.go +++ b/mount/fs_test.go @@ -40,7 +40,7 @@ func TestFS(t *testing.T) { TestFS: func(tb testing.TB) fstest.SetupFS { memRoot, err := mem.NewFS() requireNoError(tb, err) - requireNoError(tb, memRoot.Mkdir("unused", 0666)) + requireNoError(tb, memRoot.Mkdir("unused", 0o666)) memUnused, err := mem.NewFS() requireNoError(tb, err) fs, err := mount.NewFS(memRoot) @@ -105,7 +105,7 @@ func TestAddMount(t *testing.T) { fs := newFS(t) memFoo, err := mem.NewFS() assert.NoError(t, err) - assert.NoError(t, hackpadfs.Mkdir(fs, "foo", 0700)) + assert.NoError(t, hackpadfs.Mkdir(fs, "foo", 0o700)) err = fs.AddMount("foo", memFoo) assert.NoError(t, err) @@ -122,7 +122,7 @@ func TestAddMount(t *testing.T) { fs := newFS(t) memFoo, err := mem.NewFS() assert.NoError(t, err) - assert.NoError(t, hackpadfs.Mkdir(fs, "foo", 0700)) + assert.NoError(t, hackpadfs.Mkdir(fs, "foo", 0o700)) var wg sync.WaitGroup const maxAttempts = 3 @@ -155,7 +155,7 @@ func TestMount(t *testing.T) { assert.NoError(t, err) fs, err := mount.NewFS(memRoot) assert.NoError(t, err) - assert.NoError(t, hackpadfs.Mkdir(fs, "foo", 0700)) + assert.NoError(t, hackpadfs.Mkdir(fs, "foo", 0o700)) { memFoo, err := mem.NewFS() @@ -163,10 +163,10 @@ func TestMount(t *testing.T) { assert.NoError(t, fs.AddMount("foo", memFoo)) } - assert.NoError(t, hackpadfs.Mkdir(fs, "foo/bar", 0700)) + assert.NoError(t, hackpadfs.Mkdir(fs, "foo/bar", 0o700)) info, err := hackpadfs.Stat(fs, "foo/bar") if assert.NoError(t, err) { assert.Equal(t, true, info.IsDir()) - assert.Equal(t, hackpadfs.FileMode(hackpadfs.ModeDir|0700), info.Mode()) + assert.Equal(t, hackpadfs.FileMode(hackpadfs.ModeDir|0o700), info.Mode()) } } diff --git a/mount_test.go b/mount_test.go index 7562b96..fe2df35 100644 --- a/mount_test.go +++ b/mount_test.go @@ -8,7 +8,6 @@ import ( "github.com/hack-pad/hackpadfs/internal/assert" ) -//nolint:govet func TestStripErrPathPrefix(t *testing.T) { t.Parallel() someError := errors.New("some error") diff --git a/os/fs_test.go b/os/fs_test.go index 4446b2e..0a0bca2 100644 --- a/os/fs_test.go +++ b/os/fs_test.go @@ -45,7 +45,7 @@ func TestFSTest(t *testing.T) { } var skipFacets []fstest.Facets if runtime.GOOS == goosWindows { - options.Constraints.FileModeMask = 0200 // Windows does not support the typical file permission bits. Only the "owner writable" bit is supported. + options.Constraints.FileModeMask = 0o200 // Windows does not support the typical file permission bits. Only the "owner writable" bit is supported. skipFacets = []fstest.Facets{ {Name: "TestFSTest/osfs.FS_File/file.Seek/seek_unknown_start"}, // Windows ignores invalid 'whence' values in Seek() calls. {Name: "TestFSTest/osfs.FS_FS/fs.Rename/same_directory"}, // Windows does not return an error for renaming a directory to itself. diff --git a/sub_test.go b/sub_test.go index 8fdf014..6720c53 100644 --- a/sub_test.go +++ b/sub_test.go @@ -31,7 +31,7 @@ func setupSubFS(tb testing.TB) (fstest.SetupFS, func() hackpadfs.FS) { requireNoError(tb, err) return memRoot, func() hackpadfs.FS { const subDir = "subfs-subdir" - requireNoError(tb, memRoot.Mkdir(subDir, 0700)) + requireNoError(tb, memRoot.Mkdir(subDir, 0o700)) dirEntries, err := hackpadfs.ReadDir(memRoot, ".") requireNoError(tb, err) for _, entry := range dirEntries { diff --git a/tar/fs.go b/tar/fs.go index 2755da8..c990f18 100644 --- a/tar/fs.go +++ b/tar/fs.go @@ -191,7 +191,7 @@ func (fs *ReaderFS) readProcessFile( info := header.FileInfo() dir := path.Dir(p) - err := mkdirAll(dir, 0700) + err := mkdirAll(dir, 0o700) if err != nil { return fserrors.WithMessage(err, "prepping base dir") } diff --git a/tar/fs_test.go b/tar/fs_test.go index e402d21..a3688b7 100644 --- a/tar/fs_test.go +++ b/tar/fs_test.go @@ -88,7 +88,6 @@ func copyTarWalk(src hackpadfs.FS, archive *tar.Writer) hackpadfs.WalkDirFunc { } // TestNewTarFromFS is a sanity check on the constructor we use in fstest. Just make sure it behaves normally for simple cases. -// nolint:govet func TestNewTarFromFS(t *testing.T) { t.Parallel() for _, tc := range []struct { @@ -111,7 +110,7 @@ func TestNewTarFromFS(t *testing.T) { { description: "one dir", do: func(t *testing.T, fs hackpadfs.FS) { - err := hackpadfs.Mkdir(fs, "foo", 0700) + err := hackpadfs.Mkdir(fs, "foo", 0o700) if !assert.NoError(t, err) { t.FailNow() } @@ -120,7 +119,7 @@ func TestNewTarFromFS(t *testing.T) { { description: "dir with one nested file", do: func(t *testing.T, fs hackpadfs.FS) { - err := hackpadfs.Mkdir(fs, "foo", 0700) + err := hackpadfs.Mkdir(fs, "foo", 0o700) if !assert.NoError(t, err) { t.FailNow() }