Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Sep 7, 2021
1 parent b00c435 commit 14a8846
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 21 deletions.
31 changes: 22 additions & 9 deletions pkg/storage/fs/nextcloud/nextcloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ func (nc *StorageDriver) GetMD(ctx context.Context, ref *provider.Reference, mdK
md := &provider.ResourceInfo{
Opaque: &types.Opaque{},
Type: provider.ResourceType_RESOURCE_TYPE_FILE,
Id: &provider.ResourceId{OpaqueId: "fileid-" + url.QueryEscape(ref.Path)},
Id: &provider.ResourceId{OpaqueId: "fileid-" + url.QueryEscape(respMap["path"].(string))},
Checksum: &provider.ResourceChecksum{},
Etag: respMap["etag"].(string),
MimeType: respMap["mimetype"].(string),
Expand All @@ -286,7 +286,15 @@ func (nc *StorageDriver) GetMD(ctx context.Context, ref *provider.Reference, mdK

// ListFolder as defined in the storage.FS interface
func (nc *StorageDriver) ListFolder(ctx context.Context, ref *provider.Reference, mdKeys []string) ([]*provider.ResourceInfo, error) {
bodyStr, err := json.Marshal(ref)
type paramsObj struct {
Ref provider.Reference `json:"ref"`
MdKeys []string `json:"mdKeys"`
}
bodyObj := &paramsObj{
Ref: *ref,
MdKeys: mdKeys,
}
bodyStr, err := json.Marshal(bodyObj)
log := appctx.GetLogger(ctx)
log.Info().Msgf("LisfFolder %s", bodyStr)
if err != nil {
Expand All @@ -299,17 +307,22 @@ func (nc *StorageDriver) ListFolder(ctx context.Context, ref *provider.Reference
if status == 404 {
return nil, errtypes.NotFound("")
}
var bodyArr []string
err = json.Unmarshal(body, &bodyArr)
var infos = make([]*provider.ResourceInfo, len(bodyArr))
for i := 0; i < len(bodyArr); i++ {

var respMapArr []interface{}
err = json.Unmarshal(body, &respMapArr)
if err != nil {
return nil, err
}
var infos = make([]*provider.ResourceInfo, len(respMapArr))
for i := 0; i < len(respMapArr); i++ {
respMap := respMapArr[i].(map[string]interface{})
infos[i] = &provider.ResourceInfo{
Opaque: &types.Opaque{},
Type: provider.ResourceType_RESOURCE_TYPE_CONTAINER,
Id: &provider.ResourceId{OpaqueId: "fileid-" + url.QueryEscape(bodyArr[i])},
Id: &provider.ResourceId{OpaqueId: "fileid-" + url.QueryEscape(respMap["path"].(string))},
Checksum: &provider.ResourceChecksum{},
Etag: "some-etag",
MimeType: "application/octet-stream",
Etag: respMap["etag"].(string),
MimeType: respMap["mimetype"].(string),
Mtime: &types.Timestamp{Seconds: 1234567890},
Path: "/subdir", // FIXME: bodyArr[i],
PermissionSet: &provider.ResourcePermissions{},
Expand Down
5 changes: 2 additions & 3 deletions pkg/storage/fs/nextcloud/nextcloud_server_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,8 @@ var responses = map[string]Response{
`POST /apps/sciencemesh/~tester/api/CreateDir {"resource_id":{"storage_id":"storage-id","opaque_id":"opaque-id"},"path":"/some/path"}`: {201, ``, serverStateEmpty},
`POST /apps/sciencemesh/~tester/api/Delete {"resource_id":{"storage_id":"storage-id","opaque_id":"opaque-id"},"path":"/some/path"}`: {200, ``, serverStateEmpty},
`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, "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, "metadata": { "foo": "bar" }, "etag": "in-json-etag", "mimetype": "in-json-mimetype" }]`, serverStateEmpty},
`POST /apps/sciencemesh/~tester/api/ListFolder {"resource_id":{"storage_id":"storage-id","opaque_id":"opaque-id"},"path":"/some/path"}`: {200, `["hoo"]`, 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},
}

// GetNextcloudServerMock returns a handler that pretends to be a remote Nextcloud server
Expand Down
12 changes: 3 additions & 9 deletions pkg/storage/fs/nextcloud/nextcloud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,6 @@ var _ = Describe("Nextcloud", func() {

// ListFolder(ctx context.Context, ref *provider.Reference, mdKeys []string) ([]*provider.ResourceInfo, error)
Describe("ListFolder", func() {
// FIXME: this test is testing the current incorrect behavior of ListFolder,
// see https://github.com/pondersource/sciencemesh-nextcloud/issues/24
It("calls the ListFolder endpoint", func() {
nc, _ := nextcloud.NewStorageDriver(&nextcloud.StorageDriverConfig{
EndPoint: "http://mock.com/apps/sciencemesh/",
Expand All @@ -277,15 +275,11 @@ var _ = Describe("Nextcloud", func() {
mdKeys := []string{"val1", "val2", "val3"}
results, err := nc.ListFolder(ctx, ref, mdKeys)
Expect(len(results)).To(Equal(1))
Expect(results[0].Etag).To(Equal("some-etag"))
Expect(results[0].MimeType).To(Equal("application/octet-stream"))
// resultJson, err := json.Marshal(results[0].ArbitraryMetadata)
// Expect(err).ToNot(HaveOccurred())
// Expect(string(resultJson)).To(Equal("{\"metadata\":{\"foo\":\"bar\"}}"))
Expect(results[0].Etag).To(Equal("in-json-etag"))
Expect(results[0].MimeType).To(Equal("in-json-mimetype"))
Expect(err).ToNot(HaveOccurred())
Expect(len(called)).To(Equal(1))
// Expect(called[0]).To(Equal("POST /apps/sciencemesh/~tester/api/ListFolder {\"ref\":{\"resource_id\":{\"storage_id\":\"storage-id\",\"opaque_id\":\"opaque-id\"},\"path\":\"/some/path\"},\"mdKeys\":[\"val1\",\"val2\",\"val3\"]}"))
Expect(called[0]).To(Equal("POST /apps/sciencemesh/~tester/api/ListFolder {\"resource_id\":{\"storage_id\":\"storage-id\",\"opaque_id\":\"opaque-id\"},\"path\":\"/some/path\"}"))
Expect(called[0]).To(Equal("POST /apps/sciencemesh/~tester/api/ListFolder {\"ref\":{\"resource_id\":{\"storage_id\":\"storage-id\",\"opaque_id\":\"opaque-id\"},\"path\":\"/some/path\"},\"mdKeys\":[\"val1\",\"val2\",\"val3\"]}"))
})
})

Expand Down

0 comments on commit 14a8846

Please sign in to comment.