aboutsummaryrefslogtreecommitdiffstats
path: root/utils/fs/os_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'utils/fs/os_test.go')
-rw-r--r--utils/fs/os_test.go153
1 files changed, 29 insertions, 124 deletions
diff --git a/utils/fs/os_test.go b/utils/fs/os_test.go
index b6c00c6..c148265 100644
--- a/utils/fs/os_test.go
+++ b/utils/fs/os_test.go
@@ -5,147 +5,52 @@ import (
"os"
"testing"
- "github.com/alcortesm/tgz"
. "gopkg.in/check.v1"
)
func Test(t *testing.T) { TestingT(t) }
-type FSImplSuite struct {
- dir string
-}
+type WritersSuite struct{}
-var _ = Suite(&FSImplSuite{})
+var _ = Suite(&WritersSuite{})
-func (s *FSImplSuite) SetUpSuite(c *C) {
- dir, err := tgz.Extract("../../storage/filesystem/internal/dotgit/fixtures/spinnaker-gc.tgz")
- c.Assert(err, IsNil)
- s.dir = dir
-}
+func (s *WritersSuite) TestOSClient_Create(c *C) {
+ path := getTempDir()
+ client := NewOSClient(path)
-func (s *FSImplSuite) TearDownSuite(c *C) {
- err := os.RemoveAll(s.dir)
+ f, err := client.Create("foo")
c.Assert(err, IsNil)
+ c.Assert(f.(*OSFile).file.Name(), Equals, f.GetFilename())
}
-func (s *FSImplSuite) TestJoin(c *C) {
- fs := NewOS()
- for i, test := range [...]struct {
- input []string
- expected string
- }{
- {
- input: []string{},
- expected: "",
- }, {
- input: []string{"a"},
- expected: "a",
- }, {
- input: []string{"a", "b"},
- expected: "a/b",
- }, {
- input: []string{"a", "b", "c"},
- expected: "a/b/c",
- },
- } {
- obtained := fs.Join(test.input...)
- com := Commentf("test %d:\n\tinput = %v", i, test.input)
- c.Assert(obtained, Equals, test.expected, com)
- }
-}
-
-func (s *FSImplSuite) TestStat(c *C) {
- fs := NewOS()
- for i, path := range [...]string{
- ".git/index",
- ".git/info/refs",
- ".git/objects/pack/pack-584416f86235cac0d54bfabbdc399fb2b09a5269.pack",
- } {
- path := fs.Join(s.dir, path)
- com := Commentf("test %d", i)
-
- real, err := os.Open(path)
- c.Assert(err, IsNil, com)
-
- expected, err := real.Stat()
- c.Assert(err, IsNil, com)
-
- obtained, err := fs.Stat(path)
- c.Assert(err, IsNil, com)
-
- c.Assert(obtained, DeepEquals, expected, com)
+func (s *WritersSuite) TestOSClient_Write(c *C) {
+ path := getTempDir()
+ client := NewOSClient(path)
- err = real.Close()
- c.Assert(err, IsNil, com)
- }
-}
+ f, err := client.Create("foo")
+ c.Assert(err, IsNil)
+ l, err := f.Write([]byte("foo"))
+ c.Assert(l, Equals, 3)
+ c.Assert(err, IsNil)
-func (s *FSImplSuite) TestStatErrors(c *C) {
- fs := NewOS()
- for i, test := range [...]struct {
- input string
- errRegExp string
- }{
- {
- input: "bla",
- errRegExp: ".*bla: no such file or directory",
- }, {
- input: "bla/foo",
- errRegExp: ".*bla/foo: no such file or directory",
- },
- } {
- com := Commentf("test %d", i)
- _, err := fs.Stat(test.input)
- c.Assert(err, ErrorMatches, test.errRegExp, com)
- }
+ wrote, _ := ioutil.ReadFile(f.(*OSFile).file.Name())
+ c.Assert(wrote, DeepEquals, []byte("foo"))
}
-func (s *FSImplSuite) TestOpen(c *C) {
- fs := NewOS()
- for i, test := range [...]string{
- ".git/index",
- ".git/info/refs",
- ".git/objects/pack/pack-584416f86235cac0d54bfabbdc399fb2b09a5269.pack",
- } {
- com := Commentf("test %d", i)
- path := fs.Join(s.dir, test)
-
- real, err := os.Open(path)
- c.Assert(err, IsNil, com)
- realData, err := ioutil.ReadAll(real)
- c.Assert(err, IsNil, com)
- err = real.Close()
- c.Assert(err, IsNil, com)
+func (s *WritersSuite) TestOSClient_Close(c *C) {
+ path := getTempDir()
+ client := NewOSClient(path)
- obtained, err := fs.Open(path)
- c.Assert(err, IsNil, com)
- obtainedData, err := ioutil.ReadAll(obtained)
- c.Assert(err, IsNil, com)
- err = obtained.Close()
- c.Assert(err, IsNil, com)
+ f, err := client.Create("foo")
+ c.Assert(err, IsNil)
+ f.Write([]byte("foo"))
+ c.Assert(f.Close(), IsNil)
- c.Assert(obtainedData, DeepEquals, realData, com)
- }
+ wrote, _ := ioutil.ReadFile(f.GetFilename())
+ c.Assert(wrote, DeepEquals, []byte("foo"))
}
-func (s *FSImplSuite) TestReadDir(c *C) {
- fs := NewOS()
- for i, test := range [...]string{
- ".git/info",
- ".",
- "",
- ".git/objects",
- ".git/objects/pack",
- } {
- com := Commentf("test %d", i)
- path := fs.Join(s.dir, test)
-
- expected, err := ioutil.ReadDir(path)
- c.Assert(err, IsNil, com)
-
- obtained, err := fs.ReadDir(path)
- c.Assert(err, IsNil, com)
-
- c.Assert(obtained, DeepEquals, expected, com)
- }
+func getTempDir() string {
+ dir, _ := ioutil.TempDir(os.TempDir(), "--OSClientTest--")
+ return dir
}