From f41f66028f2ac81754a4a446bd279c1dba161f11 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 7 Sep 2021 14:51:21 +0000 Subject: [PATCH] With pending test for download --- pkg/storage/fs/nextcloud/nextcloud.go | 2 +- .../fs/nextcloud/nextcloud_server_mock.go | 3 +- pkg/storage/fs/nextcloud/nextcloud_test.go | 31 ++++++++++++++++++- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/pkg/storage/fs/nextcloud/nextcloud.go b/pkg/storage/fs/nextcloud/nextcloud.go index 3e90adeb10..51a7d80b3b 100644 --- a/pkg/storage/fs/nextcloud/nextcloud.go +++ b/pkg/storage/fs/nextcloud/nextcloud.go @@ -118,7 +118,7 @@ func (nc *StorageDriver) doUpload(ctx context.Context, filePath string, r io.Rea if err != nil { return err } - url := nc.endPoint + "~" + user.Username + "/api/Upload/" + filePath + url := nc.endPoint + "~" + user.Username + "/files/" + filePath req, err := http.NewRequest(http.MethodPut, url, r) if err != nil { panic(err) diff --git a/pkg/storage/fs/nextcloud/nextcloud_server_mock.go b/pkg/storage/fs/nextcloud/nextcloud_server_mock.go index 1f7cd1793b..6bcb5a661e 100644 --- a/pkg/storage/fs/nextcloud/nextcloud_server_mock.go +++ b/pkg/storage/fs/nextcloud/nextcloud_server_mock.go @@ -142,7 +142,8 @@ var responses = map[string]Response{ `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}, `POST /apps/sciencemesh/~tester/api/Upload {"resource_id":{"storage_id":"storage-id","opaque_id":"opaque-id"},"path":"/some/path"}`: {200, ``, serverStateEmpty}, - `PUT /apps/sciencemesh/~tester/api/Upload/some/file/path.txt shiny!`: {200, ``, serverStateEmpty}, + `PUT /apps/sciencemesh/~tester/files/some/file/path.txt shiny!`: {200, ``, serverStateEmpty}, + `GET /apps/sciencemesh/~tester/files/some/file/path.txt `: {200, `the contents of the file`, serverStateEmpty}, } diff --git a/pkg/storage/fs/nextcloud/nextcloud_test.go b/pkg/storage/fs/nextcloud/nextcloud_test.go index 03b9d9b00d..d787cd8f52 100644 --- a/pkg/storage/fs/nextcloud/nextcloud_test.go +++ b/pkg/storage/fs/nextcloud/nextcloud_test.go @@ -345,10 +345,39 @@ var _ = Describe("Nextcloud", func() { stringReadCloser := io.NopCloser(stringReader) err := nc.Upload(ctx, ref, stringReadCloser) Expect(err).ToNot(HaveOccurred()) - Expect(called[0]).To(Equal("PUT /apps/sciencemesh/~tester/api/Upload/some/file/path.txt shiny!")) + Expect(called[0]).To(Equal("PUT /apps/sciencemesh/~tester/files/some/file/path.txt shiny!")) }) }) // Download(ctx context.Context, ref *provider.Reference) (io.ReadCloser, error) + PDescribe("Download", func() { + It("calls the files API with GET", 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/file/path.txt", + } + reader, err := nc.Download(ctx, ref) + Expect(err).ToNot(HaveOccurred()) + Expect(called[0]).To(Equal("GET /apps/sciencemesh/~tester/files/some/file/path.txt !")) + buf := new(strings.Builder) + _, err = io.Copy(buf, reader) + Expect(err).ToNot(HaveOccurred()) + Expect(buf.String()).To(Equal("the contents of the file")) + }) + }) + // ListRevisions(ctx context.Context, ref *provider.Reference) ([]*provider.FileVersion, error) // DownloadRevision(ctx context.Context, ref *provider.Reference, key string) (io.ReadCloser, error) // RestoreRevision(ctx context.Context, ref *provider.Reference, key string) error