diff --git a/pkg/storage/fs/nextcloud/nextcloud.go b/pkg/storage/fs/nextcloud/nextcloud.go index 4910ad5193..772026dda7 100644 --- a/pkg/storage/fs/nextcloud/nextcloud.go +++ b/pkg/storage/fs/nextcloud/nextcloud.go @@ -341,7 +341,17 @@ func (nc *StorageDriver) ListFolder(ctx context.Context, ref *provider.Reference // InitiateUpload as defined in the storage.FS interface func (nc *StorageDriver) InitiateUpload(ctx context.Context, ref *provider.Reference, uploadLength int64, metadata map[string]string) (map[string]string, error) { - bodyStr, _ := json.Marshal(ref) + type paramsObj struct { + Ref provider.Reference `json:"ref"` + UploadLength int64 `json:"uploadLength"` + Metadata map[string]string `json:"metadata"` + } + bodyObj := ¶msObj{ + Ref: *ref, + UploadLength: uploadLength, + Metadata: metadata, + } + bodyStr, _ := json.Marshal(bodyObj) log := appctx.GetLogger(ctx) log.Info().Msgf("InitiateUpload %s", bodyStr) diff --git a/pkg/storage/fs/nextcloud/nextcloud_server_mock.go b/pkg/storage/fs/nextcloud/nextcloud_server_mock.go index 652aeabea4..f86a9be7a1 100644 --- a/pkg/storage/fs/nextcloud/nextcloud_server_mock.go +++ b/pkg/storage/fs/nextcloud/nextcloud_server_mock.go @@ -140,6 +140,7 @@ var responses = map[string]Response{ `POST /apps/sciencemesh/~tester/api/Move {"from":{"resource_id":{"storage_id":"storage-id-1","opaque_id":"opaque-id-1"},"path":"/some/old/path"},"to":{"resource_id":{"storage_id":"storage-id-2","opaque_id":"opaque-id-2"},"path":"/some/new/path"}}`: {200, ``, serverStateEmpty}, `POST /apps/sciencemesh/~tester/api/GetMD {"ref":{"resource_id":{"storage_id":"storage-id","opaque_id":"opaque-id"},"path":"/some/path"},"mdKeys":["val1","val2","val3"]}`: {200, `{ "size": 1, "path":"/some/path", "metadata": { "foo": "bar" }, "etag": "in-json-etag", "mimetype": "in-json-mimetype" }`, serverStateEmpty}, `POST /apps/sciencemesh/~tester/api/ListFolder {"ref":{"resource_id":{"storage_id":"storage-id","opaque_id":"opaque-id"},"path":"/some/path"},"mdKeys":["val1","val2","val3"]}`: {200, `[{ "size": 1, "path":"/some/path", "metadata": { "foo": "bar" }, "etag": "in-json-etag", "mimetype": "in-json-mimetype" }]`, serverStateEmpty}, + `POST /apps/sciencemesh/~tester/api/InitiateUpload {"ref":{"resource_id":{"storage_id":"storage-id","opaque_id":"opaque-id"},"path":"/some/path"},"uploadLength":12345,"metadata":{"key1":"val1","key2":"val2","key3":"val3"}}`: {200, `{ "not":"sure", "what": "should be", "returned": "here" }`, serverStateEmpty}, } // GetNextcloudServerMock returns a handler that pretends to be a remote Nextcloud server diff --git a/pkg/storage/fs/nextcloud/nextcloud_test.go b/pkg/storage/fs/nextcloud/nextcloud_test.go index bd08a3c400..0d4d7d8863 100644 --- a/pkg/storage/fs/nextcloud/nextcloud_test.go +++ b/pkg/storage/fs/nextcloud/nextcloud_test.go @@ -284,6 +284,42 @@ var _ = Describe("Nextcloud", func() { }) // InitiateUpload(ctx context.Context, ref *provider.Reference, uploadLength int64, metadata map[string]string) (map[string]string, error) + Describe("InitiateUpload", func() { + It("calls the ListFolder endpoint", func() { + nc, _ := nextcloud.NewStorageDriver(&nextcloud.StorageDriverConfig{ + EndPoint: "http://mock.com/apps/sciencemesh/", + MockHTTP: true, + }) + called := make([]string, 0) + h := nextcloud.GetNextcloudServerMock(&called) + mock, teardown := nextcloud.TestingHTTPClient(h) + defer teardown() + nc.SetHTTPClient(mock) + // https://github.com/cs3org/go-cs3apis/blob/970eec3/cs3/storage/provider/v1beta1/resources.pb.go#L550-L561 + ref := &provider.Reference{ + ResourceId: &provider.ResourceId{ + StorageId: "storage-id", + OpaqueId: "opaque-id", + }, + Path: "/some/path", + } + uploadLength := int64(12345) + metadata := map[string]string{ + "key1": "val1", + "key2": "val2", + "key3": "val3", + } + results, err := nc.InitiateUpload(ctx, ref, uploadLength, metadata) + Expect(err).ToNot(HaveOccurred()) + Expect(results).To(Equal(map[string]string{ + "not": "sure", + "what": "should be", + "returned": "here", + })) + Expect(called[0]).To(Equal("POST /apps/sciencemesh/~tester/api/InitiateUpload {\"ref\":{\"resource_id\":{\"storage_id\":\"storage-id\",\"opaque_id\":\"opaque-id\"},\"path\":\"/some/path\"},\"uploadLength\":12345,\"metadata\":{\"key1\":\"val1\",\"key2\":\"val2\",\"key3\":\"val3\"}}")) + }) + }) + // Upload(ctx context.Context, ref *provider.Reference, r io.ReadCloser) error // Download(ctx context.Context, ref *provider.Reference) (io.ReadCloser, error) // ListRevisions(ctx context.Context, ref *provider.Reference) ([]*provider.FileVersion, error)