fix unit tests
This commit is contained in:
@@ -108,6 +108,36 @@ func (_m *GatewayClient) GetHome(ctx context.Context, in *providerv1beta1.GetHom
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetPath provides a mock function with given fields: ctx, in, opts
|
||||
func (_m *GatewayClient) GetPath(ctx context.Context, in *providerv1beta1.GetPathRequest, opts ...grpc.CallOption) (*providerv1beta1.GetPathResponse, error) {
|
||||
_va := make([]interface{}, len(opts))
|
||||
for _i := range opts {
|
||||
_va[_i] = opts[_i]
|
||||
}
|
||||
var _ca []interface{}
|
||||
_ca = append(_ca, ctx, in)
|
||||
_ca = append(_ca, _va...)
|
||||
ret := _m.Called(_ca...)
|
||||
|
||||
var r0 *providerv1beta1.GetPathResponse
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *providerv1beta1.GetPathRequest, ...grpc.CallOption) *providerv1beta1.GetPathResponse); ok {
|
||||
r0 = rf(ctx, in, opts...)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*providerv1beta1.GetPathResponse)
|
||||
}
|
||||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(context.Context, *providerv1beta1.GetPathRequest, ...grpc.CallOption) error); ok {
|
||||
r1 = rf(ctx, in, opts...)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// GetQuota provides a mock function with given fields: ctx, in, opts
|
||||
func (_m *GatewayClient) GetQuota(ctx context.Context, in *gatewayv1beta1.GetQuotaRequest, opts ...grpc.CallOption) (*providerv1beta1.GetQuotaResponse, error) {
|
||||
_va := make([]interface{}, len(opts))
|
||||
|
||||
@@ -191,13 +191,12 @@ func (g Graph) CreateDrive(w http.ResponseWriter, r *http.Request) {
|
||||
Quota: getQuota(drive.Quota, g.config.Spaces.DefaultQuota),
|
||||
}
|
||||
|
||||
spaceDescription := *drive.Description
|
||||
if spaceDescription != "" {
|
||||
if drive.Description != nil {
|
||||
csr.Opaque = &types.Opaque{
|
||||
Map: map[string]*types.OpaqueEntry{
|
||||
"permissions": {
|
||||
Decoder: "plain",
|
||||
Value: []byte(spaceDescription),
|
||||
Value: []byte(*drive.Description),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -2,12 +2,10 @@ package svc_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
|
||||
gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
|
||||
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
|
||||
@@ -18,17 +16,8 @@ import (
|
||||
"github.com/owncloud/ocis/graph/pkg/config"
|
||||
service "github.com/owncloud/ocis/graph/pkg/service/v0"
|
||||
"github.com/stretchr/testify/mock"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
var spaceYaml = strings.NewReader(`---
|
||||
version: "1.0"
|
||||
description: read from yaml
|
||||
special:
|
||||
readme: readme2.md
|
||||
image: .img/space.png
|
||||
`)
|
||||
|
||||
var _ = Describe("Graph", func() {
|
||||
var (
|
||||
svc service.Service
|
||||
@@ -109,148 +98,8 @@ var _ = Describe("Graph", func() {
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
`))
|
||||
})
|
||||
|
||||
It("can list a space with extended properties from a space.yaml", func() {
|
||||
gatewayClient.On("ListStorageSpaces", mock.Anything, mock.Anything).Return(&provider.ListStorageSpacesResponse{
|
||||
Status: status.NewOK(ctx),
|
||||
StorageSpaces: []*provider.StorageSpace{
|
||||
{
|
||||
Id: &provider.StorageSpaceId{OpaqueId: "aspaceid"},
|
||||
SpaceType: "aspacetype",
|
||||
Root: &provider.ResourceId{
|
||||
StorageId: "aspaceid",
|
||||
OpaqueId: "anopaqueid",
|
||||
},
|
||||
Name: "aspacename",
|
||||
},
|
||||
},
|
||||
}, nil)
|
||||
gatewayClient.On("InitiateFileDownload", mock.Anything, mock.Anything).Return(&gateway.InitiateFileDownloadResponse{
|
||||
Status: status.NewOK(ctx),
|
||||
Protocols: []*gateway.FileDownloadProtocol{
|
||||
{
|
||||
Protocol: "spaces",
|
||||
DownloadEndpoint: "ignored",
|
||||
},
|
||||
},
|
||||
}, nil)
|
||||
// mock space.yaml
|
||||
httpClient.On("Do", mock.Anything, mock.Anything).Return(&http.Response{
|
||||
StatusCode: http.StatusOK,
|
||||
Body: io.NopCloser(spaceYaml),
|
||||
}, nil)
|
||||
gatewayClient.On("GetQuota", mock.Anything, mock.Anything).Return(&provider.GetQuotaResponse{
|
||||
Status: status.NewUnimplemented(ctx, fmt.Errorf("not supported"), "not supported"),
|
||||
}, nil)
|
||||
gatewayClient.On("Stat", mock.Anything, mock.Anything).Return(
|
||||
func(_ context.Context, req *provider.StatRequest, _ ...grpc.CallOption) *provider.StatResponse {
|
||||
switch req.Ref.GetPath() {
|
||||
case "./readme2.md":
|
||||
return &provider.StatResponse{
|
||||
Status: status.NewOK(ctx),
|
||||
Info: &provider.ResourceInfo{
|
||||
Type: provider.ResourceType_RESOURCE_TYPE_FILE,
|
||||
Path: "readme2.md",
|
||||
Id: &provider.ResourceId{
|
||||
StorageId: "aspaceid",
|
||||
OpaqueId: "readmeid",
|
||||
},
|
||||
PermissionSet: &provider.ResourcePermissions{
|
||||
Stat: true,
|
||||
},
|
||||
Size: 10,
|
||||
},
|
||||
}
|
||||
case "./.img/space.png":
|
||||
return &provider.StatResponse{
|
||||
Status: status.NewOK(ctx),
|
||||
Info: &provider.ResourceInfo{
|
||||
Type: provider.ResourceType_RESOURCE_TYPE_FILE,
|
||||
Path: "space.png",
|
||||
Id: &provider.ResourceId{
|
||||
StorageId: "aspaceid",
|
||||
OpaqueId: "imageid",
|
||||
},
|
||||
PermissionSet: &provider.ResourcePermissions{
|
||||
Stat: true,
|
||||
},
|
||||
Size: 20,
|
||||
},
|
||||
}
|
||||
default:
|
||||
return &provider.StatResponse{
|
||||
Status: status.NewNotFound(ctx, "not found"),
|
||||
}
|
||||
}
|
||||
},
|
||||
nil)
|
||||
|
||||
r := httptest.NewRequest(http.MethodGet, "/graph/v1.0/me/drives", nil)
|
||||
rr := httptest.NewRecorder()
|
||||
svc.GetDrives(rr, r)
|
||||
|
||||
Expect(rr.Code).To(Equal(http.StatusOK))
|
||||
|
||||
type expectedJSON struct {
|
||||
Value []struct {
|
||||
DriveType string `json:"driveType"`
|
||||
ID string
|
||||
Name string
|
||||
Description string
|
||||
Root struct {
|
||||
ID string
|
||||
WebDavURL string
|
||||
}
|
||||
Special []struct {
|
||||
ID string
|
||||
Name string
|
||||
Size int
|
||||
SpecialFolder struct {
|
||||
Name string
|
||||
}
|
||||
WebDavURL string
|
||||
}
|
||||
}
|
||||
}
|
||||
body, _ := io.ReadAll(rr.Body)
|
||||
e := expectedJSON{}
|
||||
err := json.Unmarshal(body, &e)
|
||||
Expect(err).To(BeNil())
|
||||
|
||||
Expect(len(e.Value)).To(Equal(1))
|
||||
|
||||
v := e.Value[0]
|
||||
eq := func(actual string, expected string) {
|
||||
Expect(actual).To(Equal(expected))
|
||||
}
|
||||
eq(v.DriveType, "aspacetype")
|
||||
eq(v.ID, "aspaceid!anopaqueid")
|
||||
eq(v.Name, "aspacename")
|
||||
eq(v.Description, "read from yaml")
|
||||
eq(v.Root.ID, "aspaceid!anopaqueid")
|
||||
eq(v.Root.WebDavURL, "https://localhost:9200/dav/spaces/aspaceid!anopaqueid")
|
||||
|
||||
Expect(len(v.Special)).To(Equal(2))
|
||||
for _, s := range v.Special {
|
||||
switch s.ID {
|
||||
default:
|
||||
Fail("unexpected id" + s.ID)
|
||||
case "readmeid":
|
||||
eq(s.Name, "readme2.md")
|
||||
Expect(s.Size).To(Equal(10))
|
||||
eq(s.SpecialFolder.Name, "readme")
|
||||
eq(s.WebDavURL, "https://localhost:9200/dav/spaces/aspaceid/readme2.md")
|
||||
case "imageid":
|
||||
eq(s.Name, "space.png")
|
||||
Expect(s.Size).To(Equal(20))
|
||||
eq(s.SpecialFolder.Name, "image")
|
||||
eq(s.WebDavURL, "https://localhost:9200/dav/spaces/aspaceid/.img/space.png")
|
||||
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user