From 40477d84c03be30691374d547a17e2313aa6764e Mon Sep 17 00:00:00 2001 From: Danielle Miu <29378233+DanielleMiu@users.noreply.github.com> Date: Fri, 10 Nov 2023 14:57:31 -0500 Subject: [PATCH] add objects to default loopback bucket --- internal/plugin/loopback/loopback.go | 42 +++++++++++++++++-- internal/plugin/loopback/storage.go | 2 +- internal/plugin/loopback/storage_test.go | 2 +- .../plugin/v1/storage_plugin_service.proto | 2 +- .../plugin/storage_plugin_service_grpc.pb.go | 4 +- 5 files changed, 44 insertions(+), 8 deletions(-) diff --git a/internal/plugin/loopback/loopback.go b/internal/plugin/loopback/loopback.go index a973215dc..7241d9dfd 100644 --- a/internal/plugin/loopback/loopback.go +++ b/internal/plugin/loopback/loopback.go @@ -4,6 +4,8 @@ package loopback import ( + "time" + plgpb "github.com/hashicorp/boundary/sdk/pbs/plugin" ) @@ -39,21 +41,55 @@ type LoopbackPlugin struct { // NewLoopbackPlugin returns a new loopback plugin. // For storage service testings NewLoopbackPlugin Supports WithMockErrors // and WithMockBuckets as options. If no mock buckets are provided, -// a bucket named `default` will be created. +// a bucket named `default` will be created with several zero-length files +// included. func NewLoopbackPlugin(opt ...TestOption) (*LoopbackPlugin, error) { opts, err := getTestOpts(opt...) if err != nil { return nil, err } + now := time.Now() + var zero int64 = 0 ret := &LoopbackPlugin{ TestPluginServer: new(TestPluginServer), LoopbackHost: &LoopbackHost{ hostMap: make(map[string][]*loopbackPluginHostInfo), }, LoopbackStorage: &LoopbackStorage{ - chunksSize: opts.withChunkSize, - buckets: map[BucketName]Bucket{"default": {}}, + chunksSize: opts.withChunkSize, + buckets: map[BucketName]Bucket{"default": { + ObjectName("test-file-1"): &storagePluginStorageInfo{ + lastModified: &now, + contentLength: &zero, + DataChunks: []Chunk{}, + }, + ObjectName("test-file-2"): &storagePluginStorageInfo{ + lastModified: &now, + contentLength: &zero, + DataChunks: []Chunk{}, + }, + ObjectName("test-file-3"): &storagePluginStorageInfo{ + lastModified: &now, + contentLength: &zero, + DataChunks: []Chunk{}, + }, + ObjectName("abc/file-1"): &storagePluginStorageInfo{ + lastModified: &now, + contentLength: &zero, + DataChunks: []Chunk{}, + }, + ObjectName("abc/file-2"): &storagePluginStorageInfo{ + lastModified: &now, + contentLength: &zero, + DataChunks: []Chunk{}, + }, + ObjectName("abc/file-3"): &storagePluginStorageInfo{ + lastModified: &now, + contentLength: &zero, + DataChunks: []Chunk{}, + }, + }}, errs: make([]PluginMockError, 0), putObjectResponse: make([]PluginMockPutObjectResponse, 0), }, diff --git a/internal/plugin/loopback/storage.go b/internal/plugin/loopback/storage.go index 497f4c1b5..5bfdfbbf7 100644 --- a/internal/plugin/loopback/storage.go +++ b/internal/plugin/loopback/storage.go @@ -453,8 +453,8 @@ func (l *LoopbackStorage) deleteObjects(ctx context.Context, req *plgpb.DeleteOb _, ok := bucket[prefix] if ok { delete(bucket, prefix) - deleted++ } + deleted++ // this is outside the if statement because aws always returns a success } return &plgpb.DeleteObjectsResponse{ ObjectsDeleted: deleted, diff --git a/internal/plugin/loopback/storage_test.go b/internal/plugin/loopback/storage_test.go index ae0303597..08815b2f4 100644 --- a/internal/plugin/loopback/storage_test.go +++ b/internal/plugin/loopback/storage_test.go @@ -1381,7 +1381,7 @@ func TestLoopbackDeleteObjects(t *testing.T) { Recursive: false, }, expected: &plgpb.DeleteObjectsResponse{ - ObjectsDeleted: 0, + ObjectsDeleted: 1, }, check: func() error { return nil diff --git a/internal/proto/plugin/v1/storage_plugin_service.proto b/internal/proto/plugin/v1/storage_plugin_service.proto index 51df8b023..29ba8b6a8 100644 --- a/internal/proto/plugin/v1/storage_plugin_service.proto +++ b/internal/proto/plugin/v1/storage_plugin_service.proto @@ -38,7 +38,7 @@ service StoragePluginService { // stores it to an external object store. rpc PutObject(PutObjectRequest) returns (PutObjectResponse); - // DeleteObjects is a hook that deletes one or many files in an external object store + // DeleteObjects deletes one or many files in an external object store // via a provided key prefix. rpc DeleteObjects(DeleteObjectsRequest) returns (DeleteObjectsResponse); } diff --git a/sdk/pbs/plugin/storage_plugin_service_grpc.pb.go b/sdk/pbs/plugin/storage_plugin_service_grpc.pb.go index 3135dd550..b38d1cf27 100644 --- a/sdk/pbs/plugin/storage_plugin_service_grpc.pb.go +++ b/sdk/pbs/plugin/storage_plugin_service_grpc.pb.go @@ -55,7 +55,7 @@ type StoragePluginServiceClient interface { // PutObject is a hook that reads a file stored on local disk and // stores it to an external object store. PutObject(ctx context.Context, in *PutObjectRequest, opts ...grpc.CallOption) (*PutObjectResponse, error) - // DeleteObjects is a hook that deletes one or many files in an external object store + // DeleteObjects deletes one or many files in an external object store // via a provided key prefix. DeleteObjects(ctx context.Context, in *DeleteObjectsRequest, opts ...grpc.CallOption) (*DeleteObjectsResponse, error) } @@ -186,7 +186,7 @@ type StoragePluginServiceServer interface { // PutObject is a hook that reads a file stored on local disk and // stores it to an external object store. PutObject(context.Context, *PutObjectRequest) (*PutObjectResponse, error) - // DeleteObjects is a hook that deletes one or many files in an external object store + // DeleteObjects deletes one or many files in an external object store // via a provided key prefix. DeleteObjects(context.Context, *DeleteObjectsRequest) (*DeleteObjectsResponse, error) mustEmbedUnimplementedStoragePluginServiceServer()