Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Build-deps]: Fix archiver test mocks #2605

Merged
merged 1 commit into from
Mar 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions internal/http/services/archiver/manager/archiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
22 changes: 14 additions & 8 deletions pkg/storage/utils/walker/mock/walker_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
}