From 6ced24dbe1566cf2b7793528f2ca24370669d2c6 Mon Sep 17 00:00:00 2001 From: Alex Tomlins Date: Sat, 8 Aug 2015 22:55:14 +0100 Subject: [PATCH] Make MemMapFs.Remove() error for non-existent file So that it's consistent with the os package. --- fs_test.go | 10 +++++++++- memmap.go | 2 ++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/fs_test.go b/fs_test.go index 36925e6..ec8e235 100644 --- a/fs_test.go +++ b/fs_test.go @@ -122,12 +122,20 @@ func TestRemove(t *testing.T) { err := fs.Remove(path) 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) if !os.IsNotExist(err) { 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()) } } } diff --git a/memmap.go b/memmap.go index b12969c..4513b15 100644 --- a/memmap.go +++ b/memmap.go @@ -178,6 +178,8 @@ func (m *MemMapFs) Remove(name string) error { if _, ok := m.getData()[name]; ok { delete(m.getData(), name) + } else { + return &os.PathError{"remove", name, os.ErrNotExist} } return nil }