Skip to content

Commit

Permalink
[local] improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alice-sawatzky committed Nov 18, 2020
1 parent 8f0f3c0 commit 2b4d04f
Showing 1 changed file with 37 additions and 8 deletions.
45 changes: 37 additions & 8 deletions local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,35 +27,64 @@ import (

type LocalTestSuite struct {
suite.Suite
BrokenLocalFilesytemBackend *LocalFilesystemBackend
BrokenTempDirectory string
LocalFilesystemBackend *LocalFilesystemBackend
BrokenTempDirectory string
TempDirectory string
}

func (suite *LocalTestSuite) SetupSuite() {
timestamp := time.Now().Format("20060102150405")
suite.BrokenTempDirectory = fmt.Sprintf("../../.test/storage-local/%s-broken", timestamp)
suite.BrokenTempDirectory = fmt.Sprintf(".test/storage-local/%s-broken", timestamp)
defer os.RemoveAll(suite.BrokenTempDirectory)
backend := NewLocalFilesystemBackend(suite.BrokenTempDirectory)
suite.LocalFilesystemBackend = backend
suite.TempDirectory = fmt.Sprintf(".test/storage-local/%s", timestamp)
suite.BrokenLocalFilesytemBackend = NewLocalFilesystemBackend(suite.BrokenTempDirectory)
suite.LocalFilesystemBackend = NewLocalFilesystemBackend(suite.TempDirectory)
data := []byte("some object")
err := suite.LocalFilesystemBackend.PutObject("deleteme.txt", data)
suite.Nil(err, "no error putting deleteme.txt using Local backend")
err = suite.LocalFilesystemBackend.PutObject("testdir/deleteme.txt", data)
suite.Nil(err, "no error putting testdir/deleteme.txt using Local backend")
}

//func (suite *LocalTestSuite) TeardownSuite() {
// err := suite.LocalFilesystemBackend.DeleteObject("deleteme.txt")
// suite.Nil(err, "no error deleting deleteme.txt using Local backend")
// err = suite.LocalFilesystemBackend.DeleteObject("testdir/deleteme.txt")
// suite.Nil(err, "no error deleting testdir/deleteme.txt using Local backend")
// os.RemoveAll(suite.BrokenTempDirectory)
// os.RemoveAll(suite.TempDirectory)
//}

func (suite *LocalTestSuite) TestListObjects() {
_, err := suite.LocalFilesystemBackend.ListObjects("")
_, err := suite.BrokenLocalFilesytemBackend.ListObjects("")
suite.Nil(err, "list objects does not return error if dir does not exist")

objs, err := suite.LocalFilesystemBackend.ListObjects("")
suite.Nil(err, "can list objects with good dir")
suite.Equal(len(objs), 1, "able to list objects")
}

func (suite *LocalTestSuite) TestListFolders() {
_, err := suite.LocalFilesystemBackend.ListFolders("")
_, err := suite.BrokenLocalFilesytemBackend.ListFolders("")
suite.Nil(err, "list folders does not return error if dir does not exist")

folders, err := suite.LocalFilesystemBackend.ListFolders("")
suite.Nil(err, "can list folders with good dir")
suite.Equal(len(folders), 1, "able to list folders")
}

func (suite *LocalTestSuite) TestGetObject() {
_, err := suite.LocalFilesystemBackend.GetObject("this-file-cannot-possibly-exist.tgz")
_, err := suite.BrokenLocalFilesytemBackend.GetObject("this-file-cannot-possibly-exist.tgz")
suite.NotNil(err, "cannot get objects with bad path")

obj, err := suite.LocalFilesystemBackend.GetObject("deleteme.txt")
suite.Nil(err, "can get objects with good dir")
suite.Equal([]byte("some object"), obj.Content, "able to get object with local")
}

func (suite *LocalTestSuite) TestPutObjectWithNonExistentPath() {
err := suite.LocalFilesystemBackend.PutObject("testdir/test/test.tgz", []byte("test content"))
err := suite.BrokenLocalFilesytemBackend.PutObject("testdir/test/test.tgz", []byte("test content"))
suite.Nil(err)
}

Expand Down

0 comments on commit 2b4d04f

Please sign in to comment.