Merge pull request #136 from spf13/memfs-fixes

Memfs fixes
This commit is contained in:
Martin Bertschler 2017-10-04 08:48:03 +02:00 committed by GitHub
commit 3de492c3cd
7 changed files with 52 additions and 31 deletions

View File

@ -16,5 +16,6 @@ matrix:
fast_finish: true
script:
- go test -race -v ./...
- go build
- go test -race -v ./...

View File

@ -12,4 +12,4 @@ build_script:
go build github.com/spf13/afero
test_script:
- cmd: go test --race -v github.com/spf13/afero
- cmd: go test -race -v github.com/spf13/afero/...

View File

@ -368,7 +368,7 @@ func TestUnionCacheExpire(t *testing.T) {
}
}
func TestCacheOnReadFs_Open_NotInLayer(t *testing.T) {
func TestCacheOnReadFsNotInLayer(t *testing.T) {
base := NewMemMapFs()
layer := NewMemMapFs()
fs := NewCacheOnReadFs(base, layer, 0)

View File

@ -5,7 +5,7 @@ import (
"time"
)
func Test_FileData_Name_withConcurrence(t *testing.T) {
func TestFileDataNameRace(t *testing.T) {
t.Parallel()
const someName = "someName"
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()
someTime := time.Now()
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()
const someMode = 0777
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()
d := FileData{
@ -118,7 +118,7 @@ func Test_FileData_IsDir_withConcurrence(t *testing.T) {
t.Logf("Value is %v", s.IsDir())
}
func Test_FileData_Size_withConcurrence(t *testing.T) {
func TestFileDataSizeRace(t *testing.T) {
t.Parallel()
const someData = "Hello"

View File

@ -141,7 +141,7 @@ func (m *MemMapFs) Mkdir(name string, perm os.FileMode) error {
m.registerWithParent(item)
m.mu.Unlock()
m.Chmod(name, perm)
m.Chmod(name, perm|os.ModeDir)
return nil
}
@ -151,9 +151,8 @@ func (m *MemMapFs) MkdirAll(path string, perm os.FileMode) error {
if err != nil {
if err.(*os.PathError).Err == ErrFileExists {
return nil
} else {
return err
}
return err
}
return nil
}

View File

@ -110,6 +110,8 @@ func TestPermSet(t *testing.T) {
const dirPathAll = "/my/path/to/dir"
const fileMode = os.FileMode(0765)
// directories will also have the directory bit set
const dirMode = fileMode | os.ModeDir
fs := NewMemMapFs()
@ -132,7 +134,7 @@ func TestPermSet(t *testing.T) {
}
// Test Mkdir
err = fs.Mkdir(dirPath, fileMode)
err = fs.Mkdir(dirPath, dirMode)
if err != nil {
t.Errorf("MkDir Create failed: %s", err)
return
@ -142,13 +144,14 @@ func TestPermSet(t *testing.T) {
t.Errorf("Stat failed: %s", err)
return
}
if s.Mode().String() != fileMode.String() {
t.Errorf("Permissions Incorrect: %s != %s", s.Mode().String(), fileMode.String())
// sets File
if s.Mode().String() != dirMode.String() {
t.Errorf("Permissions Incorrect: %s != %s", s.Mode().String(), dirMode.String())
return
}
// Test MkdirAll
err = fs.MkdirAll(dirPathAll, fileMode)
err = fs.MkdirAll(dirPathAll, dirMode)
if err != nil {
t.Errorf("MkDir Create failed: %s", err)
return
@ -158,8 +161,8 @@ func TestPermSet(t *testing.T) {
t.Errorf("Stat failed: %s", err)
return
}
if s.Mode().String() != fileMode.String() {
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
}
}
@ -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")
}
}

View File

@ -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