Increase test coverage
This commit is contained in:
1 parent
e87eff95e6
commit
d1958a0802
3 files changed
+194
No files matched your search
@@ -0,0 +1,130 @@
|
|||||||
|
package svc_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
|
||||||
|
"github.com/cs3org/reva/v2/pkg/rgrpc/status"
|
||||||
|
"github.com/cs3org/reva/v2/pkg/utils"
|
||||||
|
. "github.com/onsi/ginkgo/v2"
|
||||||
|
. "github.com/onsi/gomega"
|
||||||
|
"github.com/stretchr/testify/mock"
|
||||||
|
|
||||||
|
libregraph "github.com/owncloud/libre-graph-api-go"
|
||||||
|
ogrpc "github.com/owncloud/ocis/v2/ocis-pkg/service/grpc"
|
||||||
|
"github.com/owncloud/ocis/v2/ocis-pkg/shared"
|
||||||
|
"github.com/owncloud/ocis/v2/services/graph/mocks"
|
||||||
|
"github.com/owncloud/ocis/v2/services/graph/pkg/config"
|
||||||
|
"github.com/owncloud/ocis/v2/services/graph/pkg/config/defaults"
|
||||||
|
identitymocks "github.com/owncloud/ocis/v2/services/graph/pkg/identity/mocks"
|
||||||
|
service "github.com/owncloud/ocis/v2/services/graph/pkg/service/v0"
|
||||||
|
)
|
||||||
|
|
||||||
|
type itemsList struct {
|
||||||
|
Value []*libregraph.DriveItem
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ = Describe("Driveitems", func() {
|
||||||
|
var (
|
||||||
|
svc service.Service
|
||||||
|
ctx context.Context
|
||||||
|
cfg *config.Config
|
||||||
|
gatewayClient *mocks.GatewayClient
|
||||||
|
eventsPublisher mocks.Publisher
|
||||||
|
identityBackend *identitymocks.Backend
|
||||||
|
|
||||||
|
rr *httptest.ResponseRecorder
|
||||||
|
|
||||||
|
newGroup *libregraph.Group
|
||||||
|
)
|
||||||
|
|
||||||
|
BeforeEach(func() {
|
||||||
|
eventsPublisher.On("Publish", mock.Anything, mock.Anything, mock.Anything).Return(nil)
|
||||||
|
|
||||||
|
rr = httptest.NewRecorder()
|
||||||
|
|
||||||
|
identityBackend = &identitymocks.Backend{}
|
||||||
|
gatewayClient = &mocks.GatewayClient{}
|
||||||
|
newGroup = libregraph.NewGroup()
|
||||||
|
newGroup.SetMembersodataBind([]string{"/users/user1"})
|
||||||
|
newGroup.SetId("group1")
|
||||||
|
|
||||||
|
rr = httptest.NewRecorder()
|
||||||
|
ctx = context.Background()
|
||||||
|
|
||||||
|
cfg = defaults.FullDefaultConfig()
|
||||||
|
cfg.Identity.LDAP.CACert = "" // skip the startup checks, we don't use LDAP at all in this tests
|
||||||
|
cfg.TokenManager.JWTSecret = "loremipsum"
|
||||||
|
cfg.Commons = &shared.Commons{}
|
||||||
|
cfg.GRPCClientTLS = &shared.GRPCClientTLS{}
|
||||||
|
|
||||||
|
_ = ogrpc.Configure(ogrpc.GetClientOptions(cfg.GRPCClientTLS)...)
|
||||||
|
svc = service.NewService(
|
||||||
|
service.Config(cfg),
|
||||||
|
service.WithGatewayClient(gatewayClient),
|
||||||
|
service.EventsPublisher(&eventsPublisher),
|
||||||
|
service.WithIdentityBackend(identityBackend),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
Describe("GetRootDriveChildren", func() {
|
||||||
|
It("handles failing GetHome", func() {
|
||||||
|
gatewayClient.On("GetHome", mock.Anything, mock.Anything).Return(&provider.GetHomeResponse{
|
||||||
|
Status: status.NewNotFound(ctx, "not found"),
|
||||||
|
}, nil)
|
||||||
|
|
||||||
|
r := httptest.NewRequest(http.MethodGet, "/graph/v1.0/me/drive/root/children", nil)
|
||||||
|
svc.GetRootDriveChildren(rr, r)
|
||||||
|
Expect(rr.Code).To(Equal(http.StatusNotFound))
|
||||||
|
})
|
||||||
|
|
||||||
|
It("handles failing GetHome", func() {
|
||||||
|
gatewayClient.On("GetHome", mock.Anything, mock.Anything).Return(&provider.GetHomeResponse{
|
||||||
|
Status: status.NewInternal(ctx, "not found"),
|
||||||
|
}, nil)
|
||||||
|
|
||||||
|
r := httptest.NewRequest(http.MethodGet, "/graph/v1.0/me/drive/root/children", nil)
|
||||||
|
svc.GetRootDriveChildren(rr, r)
|
||||||
|
Expect(rr.Code).To(Equal(http.StatusInternalServerError))
|
||||||
|
})
|
||||||
|
|
||||||
|
It("succeeds", func() {
|
||||||
|
mtime := time.Now()
|
||||||
|
gatewayClient.On("GetHome", mock.Anything, mock.Anything).Return(&provider.GetHomeResponse{
|
||||||
|
Status: status.NewOK(ctx),
|
||||||
|
Path: "/",
|
||||||
|
}, nil)
|
||||||
|
gatewayClient.On("ListContainer", mock.Anything, mock.Anything).Return(&provider.ListContainerResponse{
|
||||||
|
Status: status.NewOK(ctx),
|
||||||
|
Infos: []*provider.ResourceInfo{
|
||||||
|
{
|
||||||
|
Type: provider.ResourceType_RESOURCE_TYPE_FILE,
|
||||||
|
Id: &provider.ResourceId{StorageId: "storageid", SpaceId: "spaceid", OpaqueId: "opaqueid"},
|
||||||
|
Etag: "etag",
|
||||||
|
Mtime: utils.TimeToTS(mtime),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}, nil)
|
||||||
|
r := httptest.NewRequest(http.MethodGet, "/graph/v1.0/me/drive/root/children", nil)
|
||||||
|
svc.GetRootDriveChildren(rr, r)
|
||||||
|
Expect(rr.Code).To(Equal(http.StatusOK))
|
||||||
|
data, err := ioutil.ReadAll(rr.Body)
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
|
res := itemsList{}
|
||||||
|
|
||||||
|
err = json.Unmarshal(data, &res)
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
|
Expect(len(res.Value)).To(Equal(1))
|
||||||
|
Expect(res.Value[0].GetLastModifiedDateTime().Equal(mtime)).To(BeTrue())
|
||||||
|
Expect(res.Value[0].GetETag()).To(Equal("etag"))
|
||||||
|
Expect(res.Value[0].GetId()).To(Equal("storageid$spaceid!opaqueid"))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -872,6 +872,69 @@ var _ = Describe("Graph", func() {
|
|||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(*drive.GetQuota().Total).To(Equal(int64(500)))
|
Expect(*drive.GetQuota().Total).To(Equal(int64(500)))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("gets the special drive items", func() {
|
||||||
|
gatewayClient.On("GetPath", mock.Anything, mock.Anything).Return(&provider.GetPathResponse{
|
||||||
|
Status: status.NewOK(ctx),
|
||||||
|
Path: "thepath",
|
||||||
|
}, nil)
|
||||||
|
gatewayClient.On("Stat", mock.Anything, mock.Anything).Return(&provider.StatResponse{
|
||||||
|
Status: status.NewOK(ctx),
|
||||||
|
Info: &provider.ResourceInfo{
|
||||||
|
Id: &provider.ResourceId{
|
||||||
|
StorageId: "pro-1",
|
||||||
|
SpaceId: "spaceID",
|
||||||
|
OpaqueId: "specialID",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}, nil)
|
||||||
|
gatewayClient.On("ListStorageSpaces",
|
||||||
|
mock.Anything,
|
||||||
|
mock.MatchedBy(
|
||||||
|
func(req *provider.ListStorageSpacesRequest) bool {
|
||||||
|
return len(req.Filters) == 1 && req.Filters[0].Term.(*provider.ListStorageSpacesRequest_Filter_Id).Id.OpaqueId == "spaceid"
|
||||||
|
})).
|
||||||
|
Return(&provider.ListStorageSpacesResponse{
|
||||||
|
Status: status.NewOK(ctx),
|
||||||
|
StorageSpaces: []*provider.StorageSpace{
|
||||||
|
{
|
||||||
|
Opaque: &typesv1beta1.Opaque{
|
||||||
|
Map: map[string]*typesv1beta1.OpaqueEntry{
|
||||||
|
service.ReadmeSpecialFolderName: {
|
||||||
|
Decoder: "plain",
|
||||||
|
Value: []byte("readme"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Id: &provider.StorageSpaceId{OpaqueId: "spaceid"},
|
||||||
|
SpaceType: "aspacetype",
|
||||||
|
Root: &provider.ResourceId{
|
||||||
|
StorageId: "pro-1",
|
||||||
|
SpaceId: "sameID",
|
||||||
|
OpaqueId: "sameID",
|
||||||
|
},
|
||||||
|
Name: "aspacename",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}, nil)
|
||||||
|
|
||||||
|
r := httptest.NewRequest(http.MethodGet, "/graph/v1.0/me/drives/{driveID}/", nil)
|
||||||
|
rctx := chi.NewRouteContext()
|
||||||
|
rctx.URLParams.Add("driveID", "spaceid")
|
||||||
|
r = r.WithContext(context.WithValue(ctxpkg.ContextSetUser(ctx, nil), chi.RouteCtxKey, rctx))
|
||||||
|
svc.GetSingleDrive(rr, r)
|
||||||
|
Expect(rr.Code).To(Equal(http.StatusOK))
|
||||||
|
|
||||||
|
data, err := ioutil.ReadAll(rr.Body)
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
|
drive := libregraph.Drive{}
|
||||||
|
err = json.Unmarshal(data, &drive)
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
Expect(*drive.GetQuota().Total).To(Equal(int64(500)))
|
||||||
|
Expect(len(drive.GetSpecial())).To(Equal(1))
|
||||||
|
Expect(drive.GetSpecial()[0].GetId()).To(Equal("pro-1$spaceID!specialID"))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
Describe("Update a drive", func() {
|
Describe("Update a drive", func() {
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ var _ = Describe("Groups", func() {
|
|||||||
eventsPublisher.On("Publish", mock.Anything, mock.Anything, mock.Anything).Return(nil)
|
eventsPublisher.On("Publish", mock.Anything, mock.Anything, mock.Anything).Return(nil)
|
||||||
|
|
||||||
identityBackend = &identitymocks.Backend{}
|
identityBackend = &identitymocks.Backend{}
|
||||||
|
gatewayClient = &mocks.GatewayClient{}
|
||||||
newGroup = libregraph.NewGroup()
|
newGroup = libregraph.NewGroup()
|
||||||
newGroup.SetMembersodataBind([]string{"/users/user1"})
|
newGroup.SetMembersodataBind([]string{"/users/user1"})
|
||||||
newGroup.SetId("group1")
|
newGroup.SetId("group1")
|
||||||
|
|||||||
Reference in new issue
Block a user