Skip to content

Commit

Permalink
Merge branch 'staging' into fix/blobber-conductor-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cnlangzi authored Jun 23, 2022
2 parents 13eff51 + 784fb36 commit e578113
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 12 deletions.
12 changes: 10 additions & 2 deletions code/go/0chain.net/blobbercore/handler/helper_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,16 @@ VALUES ('exampleId' ,'` + allocationTx + `','exampleOwnerId','` + pubkey + `',`
}

_, err = tx.Exec(`
INSERT INTO reference_objects (id, allocation_id, path_hash,lookup_hash,type,name,path,hash,custom_meta,content_hash,merkle_root,actual_file_hash,mimetype,write_marker,thumbnail_hash, actual_thumbnail_hash)
VALUES (1234,'exampleId','exampleId:examplePath','exampleId:examplePath','f','filename','examplePath','someHash','customMeta','contentHash','merkleRoot','actualFileHash','mimetype','writeMarker','thumbnailHash','actualThumbnailHash');
INSERT INTO reference_objects (id, allocation_id, path_hash,lookup_hash,type,name,path,parent_path,hash,custom_meta,content_hash,merkle_root,actual_file_hash,mimetype,write_marker,thumbnail_hash, actual_thumbnail_hash)
VALUES (1234,'exampleId','exampleId:exampleDir','exampleId:exampleDir','d','filename','/exampleDir','','someHash','customMeta','contentHash','merkleRoot','actualFileHash','mimetype','writeMarker','thumbnailHash','actualThumbnailHash');
`)
if err != nil {
return err
}

_, err = tx.Exec(`
INSERT INTO reference_objects (id, allocation_id, path_hash,lookup_hash,type,name,path,parent_path,hash,custom_meta,content_hash,merkle_root,actual_file_hash,mimetype,write_marker,thumbnail_hash, actual_thumbnail_hash)
VALUES (1235,'exampleId','exampleId:examplePath','exampleId:examplePath','f','filename','/exampleDir/examplePath','/exampleDir','someHash','customMeta','contentHash','merkleRoot','actualFileHash','mimetype','writeMarker','thumbnailHash','actualThumbnailHash');
`)
if err != nil {
return err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,33 @@ func TestBlobberGRPCService_ListEntities(t *testing.T) {
expectingError bool
}{
{
name: "Success",
name: "Success for directory",
context: metadata.New(map[string]string{
common.ClientHeader: "exampleOwnerId",
common.ClientSignatureHeader: clientSignature,
}),
input: &blobbergrpc.ListEntitiesRequest{
Path: "examplePath",
Path: "/exampleDir",
PathHash: "exampleId:exampleDir",
AuthToken: "",
Allocation: allocationTx,
},
expectedPath: "/exampleDir",
expectingError: false,
},
{
name: "Success for file",
context: metadata.New(map[string]string{
common.ClientHeader: "exampleOwnerId",
common.ClientSignatureHeader: clientSignature,
}),
input: &blobbergrpc.ListEntitiesRequest{
Path: "/exampleDir/examplePath",
PathHash: "exampleId:examplePath",
AuthToken: "",
Allocation: allocationTx,
},
expectedPath: "examplePath",
expectedPath: "/exampleDir",
expectingError: false,
},
{
Expand Down Expand Up @@ -86,7 +101,7 @@ func TestBlobberGRPCService_ListEntities(t *testing.T) {
t.Fatal("expected error")
}

if listEntitiesResp.MetaData.DirMetaData.Path != tc.expectedPath {
if listEntitiesResp.GetMetaData().GetDirMetaData().GetPath() != tc.expectedPath {
t.Fatal("unexpected path from ListEntities rpc")
}
}
Expand Down
27 changes: 24 additions & 3 deletions code/go/0chain.net/blobbercore/handler/storage_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,9 +500,30 @@ func (fsh *StorageHandler) ListEntities(ctx context.Context, r *http.Request) (*
} else if path != "/" {
return nil, common.NewError("invalid_parameters", "Invalid path: ref not found ")
}
dirref, err := reference.GetRefWithChildren(ctx, allocationID, filePath)
if err != nil {
return nil, common.NewError("invalid_parameters", "Invalid path. "+err.Error())

// If the reference is a file, build result with the file and parent dir.
var dirref *reference.Ref
if fileref != nil && fileref.Type == reference.FILE {
r, err := reference.GetReference(ctx, allocationID, filePath)
if err != nil {
return nil, common.NewError("invalid_parameters", "Invalid path. "+err.Error())
}

parent, err := reference.GetReference(ctx, allocationID, r.ParentPath)
if err != nil {
return nil, common.NewError("invalid_parameters", "Invalid path. Parent dir of file not found. "+err.Error())
}

parent.Children = append(parent.Children, r)

dirref = parent
} else {
r, err := reference.GetRefWithChildren(ctx, allocationID, filePath)
if err != nil {
return nil, common.NewError("invalid_parameters", "Invalid path. "+err.Error())
}

dirref = r
}

var result blobberhttp.ListResult
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.18

require (
github.com/0chain/errors v1.0.3
github.com/0chain/gosdk v1.8.5-0.20220620000245-6735bde55d68
github.com/0chain/gosdk v1.8.5-0.20220621050346-46a06e095a63
github.com/DATA-DOG/go-sqlmock v1.5.0
github.com/didip/tollbooth/v6 v6.1.2
github.com/gorilla/handlers v1.5.1
Expand Down
10 changes: 8 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,14 @@ collectd.org v0.3.0/go.mod h1:A/8DzQBkF6abtvrT2j/AU/4tiBgJWYyh0y/oB/4MlWE=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
github.com/0chain/errors v1.0.3 h1:QQZPFxTfnMcRdt32DXbzRQIfGWmBsKoEdszKQDb0rRM=
github.com/0chain/errors v1.0.3/go.mod h1:xymD6nVgrbgttWwkpSCfLLEJbFO6iHGQwk/yeSuYkIc=
github.com/0chain/gosdk v1.8.5-0.20220620000245-6735bde55d68 h1:PtoCiCNUunmrgVh6TdMMA2cj4fV6b2EmPJkcOK/CQVM=
github.com/0chain/gosdk v1.8.5-0.20220620000245-6735bde55d68/go.mod h1:2paTmVrhhLCuhpXUbol9wLYbXl6RxcisrixIf45nFSA=
github.com/0chain/gosdk v1.8.5-0.20220615000522-eb3ca6c70dea h1:HC7yfcjPHr2r4no/Fybt7kqtU9lE2/6mryUVYjGCr/s=
github.com/0chain/gosdk v1.8.5-0.20220615000522-eb3ca6c70dea/go.mod h1:2paTmVrhhLCuhpXUbol9wLYbXl6RxcisrixIf45nFSA=
github.com/0chain/gosdk v1.8.5-0.20220616142527-4950deef2e5b h1:iyNzc0FRLs54Sg9KdAm+2xjfYOkpQ+1qKtnF8l3hLlU=
github.com/0chain/gosdk v1.8.5-0.20220616142527-4950deef2e5b/go.mod h1:2paTmVrhhLCuhpXUbol9wLYbXl6RxcisrixIf45nFSA=
github.com/0chain/gosdk v1.8.5-0.20220619050724-50af00ab41a8 h1:DUh4BsI601V4HhKi+EK3V0A8aCAOnUFhlqDkEdmP4g4=
github.com/0chain/gosdk v1.8.5-0.20220619050724-50af00ab41a8/go.mod h1:2paTmVrhhLCuhpXUbol9wLYbXl6RxcisrixIf45nFSA=
github.com/0chain/gosdk v1.8.5-0.20220621050346-46a06e095a63 h1:ZVe47jDteanYbm9R9+lX7RG5mzBrn0TRjKk33R9XGRU=
github.com/0chain/gosdk v1.8.5-0.20220621050346-46a06e095a63/go.mod h1:2paTmVrhhLCuhpXUbol9wLYbXl6RxcisrixIf45nFSA=
github.com/Azure/azure-sdk-for-go/sdk/azcore v0.19.0/go.mod h1:h6H6c8enJmmocHUbLiiGY6sx7f9i+X3m1CHdd5c6Rdw=
github.com/Azure/azure-sdk-for-go/sdk/azcore v0.21.1/go.mod h1:fBF9PQNqB8scdgpZ3ufzaLntG0AG7C1WjPMsiFOmfHM=
github.com/Azure/azure-sdk-for-go/sdk/azidentity v0.11.0/go.mod h1:HcM1YX14R7CJcghJGOYCgdezslRSVzqwLf/q+4Y2r/0=
Expand Down

0 comments on commit e578113

Please sign in to comment.