Skip to content

Commit

Permalink
fix archiver test by fixing the mock (#2605)
Browse files Browse the repository at this point in the history
  • Loading branch information
wkloucek authored Mar 3, 2022
1 parent 27ada71 commit 4ff2163
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
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))
}

0 comments on commit 4ff2163

Please sign in to comment.