Skip to content

Commit

Permalink
With pending test for download
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Sep 7, 2021
1 parent 5d49308 commit f41f660
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/storage/fs/nextcloud/nextcloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion pkg/storage/fs/nextcloud/nextcloud_server_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
}


Expand Down
31 changes: 30 additions & 1 deletion pkg/storage/fs/nextcloud/nextcloud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f41f660

Please sign in to comment.