From 751243ce50a85911b631fce712640a80541dbcaa Mon Sep 17 00:00:00 2001 From: pa250194 Date: Thu, 23 Sep 2021 13:42:21 -0500 Subject: [PATCH] Refactor comments and method names Signed-off-by: pa250194 --- pkg/gcp/gcp.go | 10 ++++------ pkg/gcp/gcp_test.go | 16 +++++++++++++--- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/pkg/gcp/gcp.go b/pkg/gcp/gcp.go index c869419b..470fe227 100644 --- a/pkg/gcp/gcp.go +++ b/pkg/gcp/gcp.go @@ -82,9 +82,8 @@ func (c *GCPClient) BucketExists(ctx context.Context, bucketName string) (bool, return true, nil } -// ObjectAttributes checks if the object with the provided name exists. -// If it exists the Object attributes are returned. -func (c *GCPClient) ObjectAttributes(ctx context.Context, bucketName, objectName string) (bool, error) { +// ObjectExists checks if the object with the provided name exists. +func (c *GCPClient) ObjectExists(ctx context.Context, bucketName, objectName string) (bool, error) { _, err := c.Client.Bucket(bucketName).Object(objectName).Attrs(ctx) // ErrObjectNotExist is returned if the object does not exist if err == gcpStorage.ErrObjectNotExist { @@ -124,9 +123,8 @@ func (c *GCPClient) FGetObject(ctx context.Context, bucketName, objectName, loca } // ObjectExists verifies if object exists and you have permission to access. - // Check if the object exists and if you have permission to access it - // The Object attributes are returned if the Object exists. - exists, err := c.ObjectAttributes(ctx, bucketName, objectName) + // Check if the object exists and if you have permission to access it. + exists, err := c.ObjectExists(ctx, bucketName, objectName) if err != nil { return err } diff --git a/pkg/gcp/gcp_test.go b/pkg/gcp/gcp_test.go index 76c455e5..8faa5e2c 100644 --- a/pkg/gcp/gcp_test.go +++ b/pkg/gcp/gcp_test.go @@ -131,15 +131,15 @@ func TestBucketNotExists(t *testing.T) { Client: client, } exists, err := gcpClient.BucketExists(context.Background(), bucket) - assert.Error(t, err, "storage: bucket doesn't exist") + assert.Error(t, err, gcpStorage.ErrBucketNotExist.Error()) assert.Assert(t, !exists) } -func TestObjectAttributes(t *testing.T) { +func TestObjectExists(t *testing.T) { gcpClient := &gcp.GCPClient{ Client: client, } - exists, err := gcpClient.ObjectAttributes(context.Background(), bucketName, objectName) + exists, err := gcpClient.ObjectExists(context.Background(), bucketName, objectName) if err == gcpStorage.ErrObjectNotExist { assert.NilError(t, err) } @@ -147,6 +147,16 @@ func TestObjectAttributes(t *testing.T) { assert.Assert(t, exists) } +func TestObjectNotExists(t *testing.T) { + object := "doesnotexists.yaml" + gcpClient := &gcp.GCPClient{ + Client: client, + } + exists, err := gcpClient.ObjectExists(context.Background(), bucketName, object) + assert.Error(t, err, gcpStorage.ErrObjectNotExist.Error()) + assert.Assert(t, !exists) +} + func TestListObjects(t *testing.T) { gcpClient := &gcp.GCPClient{ Client: client,