Skip to content

Commit

Permalink
add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
micbar committed Mar 8, 2022
1 parent 0bcfc33 commit 63eccf8
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ build-reva: imports
go build -ldflags ${BUILD_FLAGS} -o ./cmd/reva/reva ./cmd/reva

test: off
go test -coverprofile coverage.out -race $$(go list ./... | grep -v /tests/integration)
go test -v -coverprofile coverage.out -race $$(go list ./... | grep -v /tests/integration)

test-integration: build-ci
cd tests/integration && go test -race ./...
Expand Down
11 changes: 6 additions & 5 deletions pkg/storage/utils/decomposedfs/recycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,15 @@ var _ = Describe("Recycle", func() {
var err error
env, err = helpers.NewTestEnv()
Expect(err).ToNot(HaveOccurred())
env.Permissions.On("HasPermission").Return()
})

Context("with sufficient permissions", func() {
When("a user deletes files from the same space", func() {

BeforeEach(func() {
// in this scenario user "u-s-e-r-id" has this permissions:
registerPermissions(env.Permissions, "u-s-e-r-id", &provider.ResourcePermissions{
registerPermissions(env.Permissions, "25b69780-5f39-43be-a7ac-a9b9e9fe4230", &provider.ResourcePermissions{
InitiateFileUpload: true,
Delete: true,
ListRecycle: true,
Expand Down Expand Up @@ -133,7 +134,7 @@ var _ = Describe("Recycle", func() {
})

// in this scenario user "u-s-e-r-id" has this permissions:
registerPermissions(env.Permissions, "u-s-e-r-id", &provider.ResourcePermissions{
registerPermissions(env.Permissions, "25b69780-5f39-43be-a7ac-a9b9e9fe4230", &provider.ResourcePermissions{
InitiateFileUpload: true,
Delete: true,
ListRecycle: true,
Expand Down Expand Up @@ -246,7 +247,7 @@ var _ = Describe("Recycle", func() {
Expect(projectID).ToNot(BeNil())

// in this scenario user "u-s-e-r-id" has this permissions:
registerPermissions(env.Permissions, "u-s-e-r-id", &provider.ResourcePermissions{
registerPermissions(env.Permissions, "25b69780-5f39-43be-a7ac-a9b9e9fe4230", &provider.ResourcePermissions{
InitiateFileUpload: true,
Delete: true,
ListRecycle: true,
Expand Down Expand Up @@ -318,7 +319,7 @@ var _ = Describe("Recycle", func() {
})

// in this scenario user "u-s-e-r-id" has this permissions:
registerPermissions(env.Permissions, "u-s-e-r-id", &provider.ResourcePermissions{
registerPermissions(env.Permissions, "25b69780-5f39-43be-a7ac-a9b9e9fe4230", &provider.ResourcePermissions{
Delete: true,
ListRecycle: true,
PurgeRecycle: true,
Expand Down Expand Up @@ -403,7 +404,7 @@ var _ = Describe("Recycle", func() {
})

// in this scenario user "userid" has this permissions:
registerPermissions(env.Permissions, "u-s-e-r-id", &provider.ResourcePermissions{
registerPermissions(env.Permissions, "25b69780-5f39-43be-a7ac-a9b9e9fe4230", &provider.ResourcePermissions{
Delete: true,
ListRecycle: true,
PurgeRecycle: true,
Expand Down
58 changes: 58 additions & 0 deletions pkg/storage/utils/decomposedfs/spaces_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright 2018-2022 CERN
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// In applying this license, CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

package decomposedfs_test

import (
permissionsv1beta1 "github.com/cs3org/go-cs3apis/cs3/permissions/v1beta1"
rpcv1beta1 "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
helpers "github.com/cs3org/reva/v2/pkg/storage/utils/decomposedfs/testhelpers"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/stretchr/testify/mock"
)

var _ = Describe("Home is Created", func() {
var (
env *helpers.TestEnv
)

BeforeEach(func() {
var err error
env, err = helpers.NewTestEnv()
Expect(err).ToNot(HaveOccurred())
env.PermissionsClient.On("CheckPermission", mock.Anything, mock.Anything, mock.Anything).Return(&permissionsv1beta1.CheckPermissionResponse{Status: &rpcv1beta1.Status{Code: rpcv1beta1.Code_CODE_OK}}, nil)
})

AfterEach(func() {
if env != nil {
env.Cleanup()
}
})

Context("during login", func() {
It("space is created", func() {
resp, err := env.Fs.ListStorageSpaces(env.Ctx, nil)
Expect(err).ToNot(HaveOccurred())
Expect(len(resp)).To(Equal(1))
Expect(string(resp[0].Opaque.GetMap()["spaceAlias"].Value)).To(Equal("personal/username"))
Expect(resp[0].Name).To(Equal("username"))
Expect(resp[0].SpaceType).To(Equal("personal"))
})
})
})
2 changes: 1 addition & 1 deletion pkg/storage/utils/decomposedfs/testhelpers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func NewTestEnv() (*TestEnv, error) {
owner := &userpb.User{
Id: &userpb.UserId{
Idp: "idp",
OpaqueId: "u-s-e-r-id",
OpaqueId: "25b69780-5f39-43be-a7ac-a9b9e9fe4230",
Type: userpb.UserType_USER_TYPE_PRIMARY,
},
Username: "username",
Expand Down

0 comments on commit 63eccf8

Please sign in to comment.