Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Jörn Friedrich Dreyer <[email protected]>
  • Loading branch information
butonic committed Feb 16, 2022
1 parent 7498a59 commit afdafb1
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 17 deletions.
7 changes: 0 additions & 7 deletions pkg/storage/utils/decomposedfs/lookup/lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@ import (

provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
"github.com/cs3org/reva/pkg/appctx"
ctxpkg "github.com/cs3org/reva/pkg/ctx"
"github.com/cs3org/reva/pkg/errtypes"
"github.com/cs3org/reva/pkg/storage/utils/decomposedfs/node"
"github.com/cs3org/reva/pkg/storage/utils/decomposedfs/options"
"github.com/cs3org/reva/pkg/storage/utils/decomposedfs/xattrs"
"github.com/cs3org/reva/pkg/storage/utils/templates"
)

// Lookup implements transformations from filepath to node and back
Expand Down Expand Up @@ -187,11 +185,6 @@ func (lu *Lookup) InternalPath(spaceID, nodeID string) string {
return filepath.Join(lu.Options.Root, "spaces", Pathify(spaceID, 1, 2), "nodes", Pathify(nodeID, 4, 2))
}

func (lu *Lookup) mustGetUserLayout(ctx context.Context) string {
u := ctxpkg.ContextMustGetUser(ctx)
return templates.WithUser(u, lu.Options.UserLayout)
}

// ShareFolder returns the internal storage root directory
func (lu *Lookup) ShareFolder() string {
return lu.Options.ShareFolder
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/utils/decomposedfs/spaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func (fs *Decomposedfs) CreateStorageSpace(ctx context.Context, req *provider.Cr
return nil, err
}

space, err := fs.storageSpaceFromNode(ctx, root, "*", root.InternalPath(), false)
space, err := fs.storageSpaceFromNode(ctx, root, req.Type, root.InternalPath(), false)
if err != nil {
return nil, err
}
Expand Down
12 changes: 7 additions & 5 deletions pkg/storage/utils/decomposedfs/testhelpers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func NewTestEnv() (*TestEnv, error) {
owner := &userpb.User{
Id: &userpb.UserId{
Idp: "idp",
OpaqueId: "userid",
OpaqueId: "u-s-e-r-id",
Type: userpb.UserType_USER_TYPE_PRIMARY,
},
Username: "username",
Expand Down Expand Up @@ -149,7 +149,9 @@ func (t *TestEnv) CreateTestFile(name, blobID, parentID, spaceID string, blobSiz
nil,
t.Lookup,
)
_, err := os.OpenFile(n.InternalPath(), os.O_CREATE, 0700)
nodePath := n.InternalPath()
os.MkdirAll(filepath.Dir(nodePath), 0700)
_, err := os.OpenFile(nodePath, os.O_CREATE, 0700)
if err != nil {
return nil, err
}
Expand All @@ -159,10 +161,11 @@ func (t *TestEnv) CreateTestFile(name, blobID, parentID, spaceID string, blobSiz
}
// Link in parent
childNameLink := filepath.Join(n.ParentInternalPath(), n.Name)
err = os.Symlink("../"+n.ID, childNameLink)
err = os.Symlink("../../../../../"+lookup.Pathify(n.ID, 4, 2), childNameLink)
if err != nil {
return nil, err
}
n.FindStorageSpaceRoot()

return n, err
}
Expand All @@ -187,8 +190,7 @@ func (t *TestEnv) CreateTestStorageSpace(typ string, quota *providerv1beta1.Quot
ref := buildRef(space.StorageSpace.Id.OpaqueId, "")

// the space name attribute is the stop condition in the lookup
// Since we want to lookup the space node itself we do not provide a spaceID.
h, err := node.ReadNode(t.Ctx, t.Lookup, node.NoSpaceID, space.StorageSpace.Id.OpaqueId)
h, err := node.ReadNode(t.Ctx, t.Lookup, space.StorageSpace.Id.OpaqueId, space.StorageSpace.Id.OpaqueId)
if err != nil {
return nil, err
}
Expand Down
9 changes: 5 additions & 4 deletions pkg/storage/utils/decomposedfs/tree/tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"path"

provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
"github.com/cs3org/reva/pkg/storage/utils/decomposedfs/lookup"
"github.com/cs3org/reva/pkg/storage/utils/decomposedfs/node"
helpers "github.com/cs3org/reva/pkg/storage/utils/decomposedfs/testhelpers"
"github.com/cs3org/reva/pkg/storage/utils/decomposedfs/tree"
Expand Down Expand Up @@ -106,7 +107,7 @@ var _ = Describe("Tree", func() {
})

It("moves the file to the trash", func() {
trashPath := path.Join(env.Root, "trash", n.SpaceRoot.ID, n.ID)
trashPath := path.Join(env.Root, "spaces", lookup.Pathify(n.SpaceRoot.ID, 1, 2), "trash", lookup.Pathify(n.ID, 4, 2))
_, err := os.Stat(trashPath)
Expect(err).ToNot(HaveOccurred())
})
Expand All @@ -117,7 +118,7 @@ var _ = Describe("Tree", func() {
})

It("sets the trash origin xattr", func() {
trashPath := path.Join(env.Root, "trash", n.SpaceRoot.ID, n.ID)
trashPath := path.Join(env.Root, "spaces", lookup.Pathify(n.SpaceRoot.ID, 1, 2), "trash", lookup.Pathify(n.ID, 4, 2))
attr, err := xattr.Get(trashPath, xattrs.TrashOriginAttr)
Expect(err).ToNot(HaveOccurred())
Expect(string(attr)).To(Equal("/dir1/file1"))
Expand All @@ -136,7 +137,7 @@ var _ = Describe("Tree", func() {

JustBeforeEach(func() {
env.Blobstore.On("Delete", n.BlobID).Return(nil)
trashPath = path.Join(env.Root, "trash", n.SpaceRoot.ID, n.ID)
trashPath = path.Join(env.Root, "spaces", lookup.Pathify(n.SpaceRoot.ID, 1, 2), "trash", lookup.Pathify(n.ID, 4, 2))
Expect(t.Delete(env.Ctx, n)).To(Succeed())
})

Expand Down Expand Up @@ -238,7 +239,7 @@ var _ = Describe("Tree", func() {
)

JustBeforeEach(func() {
trashPath = path.Join(env.Root, "trash", n.SpaceRoot.ID, n.ID)
trashPath = path.Join(env.Root, "spaces", lookup.Pathify(n.SpaceRoot.ID, 1, 2), "trash", lookup.Pathify(n.ID, 4, 2))
Expect(t.Delete(env.Ctx, n)).To(Succeed())
})

Expand Down

0 comments on commit afdafb1

Please sign in to comment.