Make MemMapFs.Remove() error for non-existent file

So that it's consistent with the os package.
This commit is contained in:
Alex Tomlins 2015-08-08 22:55:14 +01:00 committed by spf13
parent a269144fd6
commit 6ced24dbe1
2 changed files with 11 additions and 1 deletions

View File

@ -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())
} }
} }
} }

View File

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