mirror of https://github.com/spf13/afero.git
Make MemMapFs.Remove() error for non-existent file
So that it's consistent with the os package.
This commit is contained in:
parent
a269144fd6
commit
6ced24dbe1
10
fs_test.go
10
fs_test.go
|
@ -122,12 +122,20 @@ func TestRemove(t *testing.T) {
|
||||||
|
|
||||||
err := fs.Remove(path)
|
err := fs.Remove(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("%v: Remove() failed: %v", fs.Name(), err)
|
t.Errorf("%v: Remove() failed: %v", fs.Name(), err)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = fs.Stat(path)
|
_, err = fs.Stat(path)
|
||||||
if !os.IsNotExist(err) {
|
if !os.IsNotExist(err) {
|
||||||
t.Errorf("%v: Remove() didn't remove file", fs.Name())
|
t.Errorf("%v: Remove() didn't remove file", fs.Name())
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deleting non-existent file should raise error
|
||||||
|
err = fs.Remove(path)
|
||||||
|
if !os.IsNotExist(err) {
|
||||||
|
t.Errorf("%v: Remove() didn't raise error for non-existent file", fs.Name())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -178,6 +178,8 @@ func (m *MemMapFs) Remove(name string) error {
|
||||||
|
|
||||||
if _, ok := m.getData()[name]; ok {
|
if _, ok := m.getData()[name]; ok {
|
||||||
delete(m.getData(), name)
|
delete(m.getData(), name)
|
||||||
|
} else {
|
||||||
|
return &os.PathError{"remove", name, os.ErrNotExist}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue