From 4ff2163215cd2f90094bccf392ad7523da61f521 Mon Sep 17 00:00:00 2001 From: Willy Kloucek <34452982+wkloucek@users.noreply.github.com> Date: Thu, 3 Mar 2022 11:10:10 +0100 Subject: [PATCH] fix archiver test by fixing the mock (#2605) --- .../archiver/manager/archiver_test.go | 4 ++-- pkg/storage/utils/walker/mock/walker_mock.go | 22 ++++++++++++------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/internal/http/services/archiver/manager/archiver_test.go b/internal/http/services/archiver/manager/archiver_test.go index c1323edff6..1574ae7fb0 100644 --- a/internal/http/services/archiver/manager/archiver_test.go +++ b/internal/http/services/archiver/manager/archiver_test.go @@ -417,7 +417,7 @@ func TestCreateTar(t *testing.T) { resources = append(resources, &provider.ResourceId{OpaqueId: path.Join(tmpdir, f)}) } - w := walkerMock.NewWalker() + w := walkerMock.NewWalker(tmpdir) d := downMock.NewDownloader() arch, err := NewArchiver(resources, w, d, tt.config) @@ -865,7 +865,7 @@ func TestCreateZip(t *testing.T) { resources = append(resources, &provider.ResourceId{OpaqueId: path.Join(tmpdir, f)}) } - w := walkerMock.NewWalker() + w := walkerMock.NewWalker(tmpdir) d := downMock.NewDownloader() arch, err := NewArchiver(resources, w, d, tt.config) diff --git a/pkg/storage/utils/walker/mock/walker_mock.go b/pkg/storage/utils/walker/mock/walker_mock.go index d537f3428a..7cc877747b 100644 --- a/pkg/storage/utils/walker/mock/walker_mock.go +++ b/pkg/storage/utils/walker/mock/walker_mock.go @@ -25,16 +25,19 @@ import ( provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" typesv1beta1 "github.com/cs3org/go-cs3apis/cs3/types/v1beta1" - "github.com/cs3org/reva/pkg/rhttp/router" "github.com/cs3org/reva/pkg/storage/utils/walker" ) -type mockWalker struct{} +type mockWalker struct { + tmpDir string +} // NewWalker creates a mock walker that implements the Walk interface // supposed to be used for testing -func NewWalker() walker.Walker { - return &mockWalker{} +func NewWalker(tmpDir string) walker.Walker { + return &mockWalker{ + tmpDir: tmpDir, + } } // converts a FileInfo to a reva ResourceInfo @@ -58,15 +61,18 @@ func convertFileInfoToResourceInfo(path string, f fs.FileInfo) *provider.Resourc } } -func mockWalkFunc(fn walker.WalkFunc) filepath.WalkFunc { +func mockWalkFunc(fn walker.WalkFunc, tmpDir string) filepath.WalkFunc { return func(path string, info fs.FileInfo, err error) error { - _, relativePath := router.ShiftPath(path) - _, relativePath = router.ShiftPath(relativePath) + relativePath, relErr := filepath.Rel(tmpDir, path) + if relErr != nil { + return relErr + } + relativePath = filepath.Join("/", relativePath) return fn(filepath.Dir(relativePath), convertFileInfoToResourceInfo(path, info), err) } } // Walk walks into the local file system using the built-in filepath.Walk go function func (m *mockWalker) Walk(_ context.Context, root *provider.ResourceId, fn walker.WalkFunc) error { - return filepath.Walk(root.OpaqueId, mockWalkFunc(fn)) + return filepath.Walk(root.OpaqueId, mockWalkFunc(fn, m.tmpDir)) }