From 2b4d04fd70031aeb7d45911ad980c2983e364e45 Mon Sep 17 00:00:00 2001 From: Alice Sawatzky Date: Mon, 10 Aug 2020 16:45:12 -0500 Subject: [PATCH] [local] improve tests --- local_test.go | 45 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/local_test.go b/local_test.go index 0e203f9c..dc16127a 100644 --- a/local_test.go +++ b/local_test.go @@ -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) }