aboutsummaryrefslogtreecommitdiffstats
path: root/utils/fs/test/fs_suite.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2016-11-04 12:29:00 +0100
committerGitHub <noreply@github.com>2016-11-04 12:29:00 +0100
commit3a85c05bcf82ac4a6d48165bd644d81622fae80a (patch)
tree05f3d41ca6aa6d170dd61298f1d2fd047412ca78 /utils/fs/test/fs_suite.go
parent3f7fbc6c49e50eb22e3de8a5143817fa7c0c54dd (diff)
downloadgo-git-3a85c05bcf82ac4a6d48165bd644d81622fae80a.tar.gz
utils: fs, new memory filesystem (#108)
* utils: fs, new memory filesystem * utils: fs, renamed os.NewOS to os.New * utils: fs, memory changes requested by @alcortes
Diffstat (limited to 'utils/fs/test/fs_suite.go')
-rw-r--r--utils/fs/test/fs_suite.go43
1 files changed, 43 insertions, 0 deletions
diff --git a/utils/fs/test/fs_suite.go b/utils/fs/test/fs_suite.go
index 4c0fd09..74301f5 100644
--- a/utils/fs/test/fs_suite.go
+++ b/utils/fs/test/fs_suite.go
@@ -2,6 +2,7 @@ package test
import (
"fmt"
+ "io"
"io/ioutil"
"os"
"strings"
@@ -184,6 +185,32 @@ func (s *FilesystemSuite) testReadClose(c *C, f File, content string) {
c.Assert(f.Close(), IsNil)
}
+func (s *FilesystemSuite) TestFileReadSeek(c *C) {
+ f, err := s.Fs.Create("foo")
+ c.Assert(err, IsNil)
+
+ n, err := f.Write([]byte("0123456789abcdefghijklmnopqrstuvwxyz"))
+ c.Assert(err, IsNil)
+ c.Assert(n, Equals, 36)
+
+ p, err := f.Seek(10, io.SeekStart)
+ c.Assert(err, IsNil)
+ c.Assert(int(p), Equals, 10)
+
+ all, err := ioutil.ReadAll(f)
+ c.Assert(err, IsNil)
+ c.Assert(string(all), Equals, "abcdefghijklmnopqrstuvwxyz")
+ c.Assert(f.Close(), IsNil)
+}
+
+func (s *FilesystemSuite) TestFileCloseTwice(c *C) {
+ f, err := s.Fs.Create("foo")
+ c.Assert(err, IsNil)
+
+ c.Assert(f.Close(), IsNil)
+ c.Assert(f.Close(), NotNil)
+}
+
func (s *FilesystemSuite) TestReadDirAndDir(c *C) {
files := []string{"foo", "bar", "qux/baz", "qux/qux"}
for _, name := range files {
@@ -268,6 +295,20 @@ func (s *FilesystemSuite) TestTempFileFullWithPath(c *C) {
c.Assert(strings.HasPrefix(f.Filename(), s.Fs.Join("foo", "bar")), Equals, true)
}
+func (s *FilesystemSuite) TestOpenAndWrite(c *C) {
+ f, err := s.Fs.Create("foo")
+ c.Assert(err, IsNil)
+ c.Assert(f.Close(), IsNil)
+
+ foo, err := s.Fs.Open("foo")
+ c.Assert(foo, NotNil)
+ c.Assert(err, IsNil)
+
+ n, err := foo.Write([]byte("foo"))
+ c.Assert(err, NotNil)
+ c.Assert(n, Equals, 0)
+}
+
func (s *FilesystemSuite) TestOpenAndStat(c *C) {
f, err := s.Fs.Create("foo")
c.Assert(err, IsNil)
@@ -299,6 +340,8 @@ func (s *FilesystemSuite) TestRemoveNonExisting(c *C) {
func (s *FilesystemSuite) TestRemoveTempFile(c *C) {
f, err := s.Fs.TempFile("test-dir", "test-prefix")
+ c.Assert(err, IsNil)
+
fn := f.Filename()
c.Assert(err, IsNil)
c.Assert(f.Close(), IsNil)