Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
micbar committed Apr 29, 2023
1 parent 6b27a7b commit df4aa3c
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions pkg/storage/utils/decomposedfs/decomposedfs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package decomposedfs_test

import (
"github.com/cs3org/reva/v2/pkg/errtypes"
"github.com/stretchr/testify/mock"

provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
Expand Down Expand Up @@ -64,6 +65,73 @@ var _ = Describe("Decomposed", func() {
})
})

Describe("CreateDir", func() {
Context("Existing and non existing parent folders", func() {
It("CreateDir succeeds", func() {
dir2 := &provider.Reference{
ResourceId: env.SpaceRootRes,
Path: "/dir2",
}
env.Permissions.On("AssemblePermissions", mock.Anything, mock.Anything, mock.Anything).Return(provider.ResourcePermissions{CreateContainer: true, Stat: true}, nil)
err := env.Fs.CreateDir(env.Ctx, dir2)
Expect(err).ToNot(HaveOccurred())
ri, err := env.Fs.GetMD(env.Ctx, dir2, []string{}, []string{})
Expect(err).ToNot(HaveOccurred())
Expect(ri.Path).To(Equal(dir2.Path))
})
It("CreateDir succeeds in subdir", func() {
dir2 := &provider.Reference{
ResourceId: env.SpaceRootRes,
Path: "/dir1/dir2",
}
env.Permissions.On("AssemblePermissions", mock.Anything, mock.Anything, mock.Anything).Return(provider.ResourcePermissions{CreateContainer: true, Stat: true}, nil)
err := env.Fs.CreateDir(env.Ctx, dir2)
Expect(err).ToNot(HaveOccurred())
ri, err := env.Fs.GetMD(env.Ctx, dir2, []string{}, []string{})
Expect(err).ToNot(HaveOccurred())
Expect(ri.Path).To(Equal(dir2.Path))
})
It("dir already exists", func() {
env.Permissions.On("AssemblePermissions", mock.Anything, mock.Anything, mock.Anything).Return(provider.ResourcePermissions{CreateContainer: true}, nil)
err := env.Fs.CreateDir(env.Ctx, ref)
Expect(err).To(HaveOccurred())
Expect(err).Should(MatchError(errtypes.AlreadyExists("/dir1")))
})
It("dir already exists in subdir", func() {
dir3 := &provider.Reference{
ResourceId: env.SpaceRootRes,
Path: "/dir1/dir3",
}
env.Permissions.On("AssemblePermissions", mock.Anything, mock.Anything, mock.Anything).Return(provider.ResourcePermissions{CreateContainer: true}, nil)
err := env.Fs.CreateDir(env.Ctx, dir3)
Expect(err).ToNot(HaveOccurred())
err = env.Fs.CreateDir(env.Ctx, dir3)
Expect(err).To(HaveOccurred())
Expect(err).Should(MatchError(errtypes.AlreadyExists("/dir1/dir3")))
})
It("CreateDir fails in subdir", func() {
dir2 := &provider.Reference{
ResourceId: env.SpaceRootRes,
Path: "/dir1/dir2/dir3",
}
env.Permissions.On("AssemblePermissions", mock.Anything, mock.Anything, mock.Anything).Return(provider.ResourcePermissions{CreateContainer: true}, nil)
err := env.Fs.CreateDir(env.Ctx, dir2)
Expect(err).To(HaveOccurred())
Expect(err).Should(MatchError(errtypes.PreconditionFailed("/dir1/dir2")))
})
It("CreateDir fails in non existing sub subbdir", func() {
dir2 := &provider.Reference{
ResourceId: env.SpaceRootRes,
Path: "/dir1/dir2/dir3/dir4",
}
env.Permissions.On("AssemblePermissions", mock.Anything, mock.Anything, mock.Anything).Return(provider.ResourcePermissions{CreateContainer: true}, nil)
err := env.Fs.CreateDir(env.Ctx, dir2)
Expect(err).To(HaveOccurred())
Expect(err).Should(MatchError(errtypes.PreconditionFailed("error: not found: dir2")))
})
})
})

Describe("Delete", func() {
Context("with no permissions", func() {
It("returns an error", func() {
Expand Down

0 comments on commit df4aa3c

Please sign in to comment.