aboutsummaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
authorSantiago M. Mola <santi@mola.io>2016-10-24 15:22:17 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2016-10-24 15:22:17 +0200
commitcad256efb13b9067c2664001d5713507694bc411 (patch)
treeb0b9c0653432865483c69e2cbc78c1f51718228b /utils
parentd45eb0402b2f3dace2ed1f91ee53e2c591a7ba3c (diff)
downloadgo-git-cad256efb13b9067c2664001d5713507694bc411.tar.gz
utils/fs: add Remove(). (#94)
Diffstat (limited to 'utils')
-rw-r--r--utils/fs/fs.go1
-rw-r--r--utils/fs/os/os.go5
-rw-r--r--utils/fs/test/fs_suite.go22
3 files changed, 28 insertions, 0 deletions
diff --git a/utils/fs/fs.go b/utils/fs/fs.go
index 4eaad15..463425c 100644
--- a/utils/fs/fs.go
+++ b/utils/fs/fs.go
@@ -22,6 +22,7 @@ type Filesystem interface {
ReadDir(path string) ([]FileInfo, error)
TempFile(dir, prefix string) (File, error)
Rename(from, to string) error
+ Remove(filename string) error
Join(elem ...string) string
Dir(path string) Filesystem
Base() string
diff --git a/utils/fs/os/os.go b/utils/fs/os/os.go
index 0b0173f..800bd41 100644
--- a/utils/fs/os/os.go
+++ b/utils/fs/os/os.go
@@ -100,6 +100,11 @@ func (fs *OS) Stat(filename string) (FileInfo, error) {
return os.Stat(fullpath)
}
+func (fs *OS) Remove(filename string) error {
+ fullpath := fs.Join(fs.base, filename)
+ return os.Remove(fullpath)
+}
+
func (fs *OS) TempFile(dir, prefix string) (File, error) {
fullpath := fs.Join(fs.base, dir)
if err := fs.createDir(fullpath + string(os.PathSeparator)); err != nil {
diff --git a/utils/fs/test/fs_suite.go b/utils/fs/test/fs_suite.go
index 109311f..055839e 100644
--- a/utils/fs/test/fs_suite.go
+++ b/utils/fs/test/fs_suite.go
@@ -149,6 +149,28 @@ func (s *FilesystemSuite) TestOpenAndStat(c *C) {
c.Assert(stat.Name(), Equals, "foo")
}
+func (s *FilesystemSuite) TestRemove(c *C) {
+ f, err := s.Fs.Create("foo")
+ c.Assert(err, IsNil)
+ c.Assert(f.Close(), IsNil)
+
+ err = s.Fs.Remove("foo")
+ c.Assert(err, IsNil)
+}
+
+func (s *FilesystemSuite) TestRemoveNonExisting(c *C) {
+ c.Assert(s.Fs.Remove("NON-EXISTING"), NotNil)
+}
+
+func (s *FilesystemSuite) TestRemoveTempFile(c *C) {
+ f, err := s.Fs.TempFile("test-dir", "test-prefix")
+ fn := f.Filename()
+ c.Assert(err, IsNil)
+ c.Assert(f.Close(), IsNil)
+
+ c.Assert(s.Fs.Remove(fn), IsNil)
+}
+
func (s *FilesystemSuite) TestJoin(c *C) {
c.Assert(s.Fs.Join("foo", "bar"), Equals, "foo/bar")
}