From afdafb1105cbff49f07ee88bcdd238694e395c86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Wed, 16 Feb 2022 21:24:50 +0000 Subject: [PATCH] fix tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jörn Friedrich Dreyer --- pkg/storage/utils/decomposedfs/lookup/lookup.go | 7 ------- pkg/storage/utils/decomposedfs/spaces.go | 2 +- .../utils/decomposedfs/testhelpers/helpers.go | 12 +++++++----- pkg/storage/utils/decomposedfs/tree/tree_test.go | 9 +++++---- 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/pkg/storage/utils/decomposedfs/lookup/lookup.go b/pkg/storage/utils/decomposedfs/lookup/lookup.go index 5be3fadf43b..6fa1488a749 100644 --- a/pkg/storage/utils/decomposedfs/lookup/lookup.go +++ b/pkg/storage/utils/decomposedfs/lookup/lookup.go @@ -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 @@ -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 diff --git a/pkg/storage/utils/decomposedfs/spaces.go b/pkg/storage/utils/decomposedfs/spaces.go index 59c383d56a9..4a23b53ebd2 100644 --- a/pkg/storage/utils/decomposedfs/spaces.go +++ b/pkg/storage/utils/decomposedfs/spaces.go @@ -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 } diff --git a/pkg/storage/utils/decomposedfs/testhelpers/helpers.go b/pkg/storage/utils/decomposedfs/testhelpers/helpers.go index 3da0b6e3768..2dd210b9675 100644 --- a/pkg/storage/utils/decomposedfs/testhelpers/helpers.go +++ b/pkg/storage/utils/decomposedfs/testhelpers/helpers.go @@ -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", @@ -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 } @@ -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 } @@ -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 } diff --git a/pkg/storage/utils/decomposedfs/tree/tree_test.go b/pkg/storage/utils/decomposedfs/tree/tree_test.go index 75fe4460d42..72e61dcdacd 100644 --- a/pkg/storage/utils/decomposedfs/tree/tree_test.go +++ b/pkg/storage/utils/decomposedfs/tree/tree_test.go @@ -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" @@ -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()) }) @@ -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")) @@ -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()) }) @@ -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()) })