mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-02-25 11:37:03 -05:00
Merge pull request #5165 from aduffeck/graph-test-coverage-driveitems
Graph test coverage driveitems
This commit is contained in:
@@ -215,8 +215,8 @@ func (g Graph) getPathForResource(ctx context.Context, id storageprovider.Resour
|
||||
return res.Path, err
|
||||
}
|
||||
|
||||
// GetExtendedSpaceProperties reads properties from the opaque and transforms them into driveItems
|
||||
func (g Graph) GetExtendedSpaceProperties(ctx context.Context, baseURL *url.URL, space *storageprovider.StorageSpace) []libregraph.DriveItem {
|
||||
// getExtendedSpaceProperties reads properties from the opaque and transforms them into driveItems
|
||||
func (g Graph) getExtendedSpaceProperties(ctx context.Context, baseURL *url.URL, space *storageprovider.StorageSpace) []libregraph.DriveItem {
|
||||
var spaceItems []libregraph.DriveItem
|
||||
if space.Opaque == nil {
|
||||
return nil
|
||||
|
||||
130
services/graph/pkg/service/v0/driveitems_test.go
Normal file
130
services/graph/pkg/service/v0/driveitems_test.go
Normal file
@@ -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"))
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -469,7 +469,7 @@ func (g Graph) formatDrives(ctx context.Context, baseURL *url.URL, storageSpaces
|
||||
|
||||
// can't access disabled space
|
||||
if utils.ReadPlainFromOpaque(storageSpace.Opaque, "trashed") != "trashed" {
|
||||
res.Special = g.GetExtendedSpaceProperties(ctx, baseURL, storageSpace)
|
||||
res.Special = g.getExtendedSpaceProperties(ctx, baseURL, storageSpace)
|
||||
res.Quota, err = g.getDriveQuota(ctx, storageSpace)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -872,6 +872,69 @@ var _ = Describe("Graph", func() {
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
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() {
|
||||
|
||||
@@ -54,6 +54,7 @@ var _ = Describe("Groups", func() {
|
||||
eventsPublisher.On("Publish", mock.Anything, mock.Anything, mock.Anything).Return(nil)
|
||||
|
||||
identityBackend = &identitymocks.Backend{}
|
||||
gatewayClient = &mocks.GatewayClient{}
|
||||
newGroup = libregraph.NewGroup()
|
||||
newGroup.SetMembersodataBind([]string{"/users/user1"})
|
||||
newGroup.SetId("group1")
|
||||
|
||||
@@ -128,3 +128,8 @@ func (i instrument) GetAllDrives(w http.ResponseWriter, r *http.Request) {
|
||||
func (i instrument) CreateDrive(w http.ResponseWriter, r *http.Request) {
|
||||
i.next.CreateDrive(w, r)
|
||||
}
|
||||
|
||||
// GetRootDriveChildren implements the Service interface.
|
||||
func (i instrument) GetRootDriveChildren(w http.ResponseWriter, r *http.Request) {
|
||||
i.next.GetRootDriveChildren(w, r)
|
||||
}
|
||||
|
||||
@@ -128,3 +128,8 @@ func (l logging) GetAllDrives(w http.ResponseWriter, r *http.Request) {
|
||||
func (l logging) CreateDrive(w http.ResponseWriter, r *http.Request) {
|
||||
l.next.CreateDrive(w, r)
|
||||
}
|
||||
|
||||
// GetRootDriveChildren implements the Service interface.
|
||||
func (l logging) GetRootDriveChildren(w http.ResponseWriter, r *http.Request) {
|
||||
l.next.GetRootDriveChildren(w, r)
|
||||
}
|
||||
|
||||
@@ -50,6 +50,7 @@ type Service interface {
|
||||
GetDrives(w http.ResponseWriter, r *http.Request)
|
||||
GetSingleDrive(w http.ResponseWriter, r *http.Request)
|
||||
GetAllDrives(w http.ResponseWriter, r *http.Request)
|
||||
GetRootDriveChildren(w http.ResponseWriter, r *http.Request)
|
||||
CreateDrive(w http.ResponseWriter, r *http.Request)
|
||||
UpdateDrive(w http.ResponseWriter, r *http.Request)
|
||||
DeleteDrive(w http.ResponseWriter, r *http.Request)
|
||||
|
||||
@@ -124,3 +124,8 @@ func (t tracing) GetAllDrives(w http.ResponseWriter, r *http.Request) {
|
||||
func (t tracing) CreateDrive(w http.ResponseWriter, r *http.Request) {
|
||||
t.next.CreateDrive(w, r)
|
||||
}
|
||||
|
||||
// GetRootDriveChildren implements the Service interface.
|
||||
func (t tracing) GetRootDriveChildren(w http.ResponseWriter, r *http.Request) {
|
||||
t.next.GetRootDriveChildren(w, r)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user