From 473997e41882cb62918fc6634e444f7d8ef1e9e5 Mon Sep 17 00:00:00 2001 From: Martin Bertschler Date: Tue, 3 Oct 2017 23:17:35 +0200 Subject: [PATCH] add test that shows a bug with FileMode not being set for MemMapFs directories, clean up tests --- .travis.yml | 3 ++- appveyor.yml | 2 +- composite_test.go | 2 +- mem/file_test.go | 10 +++++----- memmap_test.go | 32 ++++++++++++++++++++++++++++++++ 5 files changed, 41 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index 40d0789..618159a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,5 +16,6 @@ matrix: fast_finish: true script: - - go test -race -v ./... - go build + - go test -race -v ./... + diff --git a/appveyor.yml b/appveyor.yml index 98ac35c..a633ad5 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -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/... diff --git a/composite_test.go b/composite_test.go index c2e3c9c..8e44611 100644 --- a/composite_test.go +++ b/composite_test.go @@ -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) diff --git a/mem/file_test.go b/mem/file_test.go index 1aeea23..5769067 100644 --- a/mem/file_test.go +++ b/mem/file_test.go @@ -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" diff --git a/memmap_test.go b/memmap_test.go index d28e912..23a8881 100644 --- a/memmap_test.go +++ b/memmap_test.go @@ -384,3 +384,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()&os.ModeDir == 0 { + 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()&os.ModeDir == 0 { + t.Error("FileMode is not directory") + } +}