mirror of https://github.com/spf13/afero.git
commit
3de492c3cd
|
@ -16,5 +16,6 @@ matrix:
|
||||||
fast_finish: true
|
fast_finish: true
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- go test -race -v ./...
|
|
||||||
- go build
|
- go build
|
||||||
|
- go test -race -v ./...
|
||||||
|
|
||||||
|
|
|
@ -12,4 +12,4 @@ build_script:
|
||||||
|
|
||||||
go build github.com/spf13/afero
|
go build github.com/spf13/afero
|
||||||
test_script:
|
test_script:
|
||||||
- cmd: go test --race -v github.com/spf13/afero
|
- cmd: go test -race -v github.com/spf13/afero/...
|
||||||
|
|
|
@ -368,7 +368,7 @@ func TestUnionCacheExpire(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCacheOnReadFs_Open_NotInLayer(t *testing.T) {
|
func TestCacheOnReadFsNotInLayer(t *testing.T) {
|
||||||
base := NewMemMapFs()
|
base := NewMemMapFs()
|
||||||
layer := NewMemMapFs()
|
layer := NewMemMapFs()
|
||||||
fs := NewCacheOnReadFs(base, layer, 0)
|
fs := NewCacheOnReadFs(base, layer, 0)
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_FileData_Name_withConcurrence(t *testing.T) {
|
func TestFileDataNameRace(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
const someName = "someName"
|
const someName = "someName"
|
||||||
const someOtherName = "someOtherName"
|
const someOtherName = "someOtherName"
|
||||||
|
@ -31,7 +31,7 @@ func Test_FileData_Name_withConcurrence(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_FileData_ModTime_withConcurrence(t *testing.T) {
|
func TestFileDataModTimeRace(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
someTime := time.Now()
|
someTime := time.Now()
|
||||||
someOtherTime := someTime.Add(1 * time.Minute)
|
someOtherTime := someTime.Add(1 * time.Minute)
|
||||||
|
@ -62,7 +62,7 @@ func Test_FileData_ModTime_withConcurrence(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_FileData_Mode_withConcurrence(t *testing.T) {
|
func TestFileDataModeRace(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
const someMode = 0777
|
const someMode = 0777
|
||||||
const someOtherMode = 0660
|
const someOtherMode = 0660
|
||||||
|
@ -93,7 +93,7 @@ func Test_FileData_Mode_withConcurrence(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_FileData_IsDir_withConcurrence(t *testing.T) {
|
func TestFileDataIsDirRace(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
d := FileData{
|
d := FileData{
|
||||||
|
@ -118,7 +118,7 @@ func Test_FileData_IsDir_withConcurrence(t *testing.T) {
|
||||||
t.Logf("Value is %v", s.IsDir())
|
t.Logf("Value is %v", s.IsDir())
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_FileData_Size_withConcurrence(t *testing.T) {
|
func TestFileDataSizeRace(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
const someData = "Hello"
|
const someData = "Hello"
|
||||||
|
|
|
@ -141,7 +141,7 @@ func (m *MemMapFs) Mkdir(name string, perm os.FileMode) error {
|
||||||
m.registerWithParent(item)
|
m.registerWithParent(item)
|
||||||
m.mu.Unlock()
|
m.mu.Unlock()
|
||||||
|
|
||||||
m.Chmod(name, perm)
|
m.Chmod(name, perm|os.ModeDir)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -151,9 +151,8 @@ func (m *MemMapFs) MkdirAll(path string, perm os.FileMode) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err.(*os.PathError).Err == ErrFileExists {
|
if err.(*os.PathError).Err == ErrFileExists {
|
||||||
return nil
|
return nil
|
||||||
} else {
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,6 +110,8 @@ func TestPermSet(t *testing.T) {
|
||||||
const dirPathAll = "/my/path/to/dir"
|
const dirPathAll = "/my/path/to/dir"
|
||||||
|
|
||||||
const fileMode = os.FileMode(0765)
|
const fileMode = os.FileMode(0765)
|
||||||
|
// directories will also have the directory bit set
|
||||||
|
const dirMode = fileMode | os.ModeDir
|
||||||
|
|
||||||
fs := NewMemMapFs()
|
fs := NewMemMapFs()
|
||||||
|
|
||||||
|
@ -132,7 +134,7 @@ func TestPermSet(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test Mkdir
|
// Test Mkdir
|
||||||
err = fs.Mkdir(dirPath, fileMode)
|
err = fs.Mkdir(dirPath, dirMode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("MkDir Create failed: %s", err)
|
t.Errorf("MkDir Create failed: %s", err)
|
||||||
return
|
return
|
||||||
|
@ -142,13 +144,14 @@ func TestPermSet(t *testing.T) {
|
||||||
t.Errorf("Stat failed: %s", err)
|
t.Errorf("Stat failed: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if s.Mode().String() != fileMode.String() {
|
// sets File
|
||||||
t.Errorf("Permissions Incorrect: %s != %s", s.Mode().String(), fileMode.String())
|
if s.Mode().String() != dirMode.String() {
|
||||||
|
t.Errorf("Permissions Incorrect: %s != %s", s.Mode().String(), dirMode.String())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test MkdirAll
|
// Test MkdirAll
|
||||||
err = fs.MkdirAll(dirPathAll, fileMode)
|
err = fs.MkdirAll(dirPathAll, dirMode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("MkDir Create failed: %s", err)
|
t.Errorf("MkDir Create failed: %s", err)
|
||||||
return
|
return
|
||||||
|
@ -158,8 +161,8 @@ func TestPermSet(t *testing.T) {
|
||||||
t.Errorf("Stat failed: %s", err)
|
t.Errorf("Stat failed: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if s.Mode().String() != fileMode.String() {
|
if s.Mode().String() != dirMode.String() {
|
||||||
t.Errorf("Permissions Incorrect: %s != %s", s.Mode().String(), fileMode.String())
|
t.Errorf("Permissions Incorrect: %s != %s", s.Mode().String(), dirMode.String())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -384,3 +387,35 @@ loop:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMemFsDirMode(t *testing.T) {
|
||||||
|
fs := NewMemMapFs()
|
||||||
|
err := fs.Mkdir("/testDir1", 0644)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
err = fs.MkdirAll("/sub/testDir2", 0644)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
info, err := fs.Stat("/testDir1")
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
if !info.IsDir() {
|
||||||
|
t.Error("should be a directory")
|
||||||
|
}
|
||||||
|
if !info.Mode().IsDir() {
|
||||||
|
t.Error("FileMode is not directory")
|
||||||
|
}
|
||||||
|
info, err = fs.Stat("/sub/testDir2")
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
if !info.IsDir() {
|
||||||
|
t.Error("should be a directory")
|
||||||
|
}
|
||||||
|
if !info.Mode().IsDir() {
|
||||||
|
t.Error("FileMode is not directory")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
14
memradix.go
14
memradix.go
|
@ -1,14 +0,0 @@
|
||||||
// Copyright © 2014 Steve Francia <spf@spf13.com>.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package afero
|
|
Loading…
Reference in New Issue