Skip to content

Commit

Permalink
Refactor comments and method names
Browse files Browse the repository at this point in the history
  • Loading branch information
pa250194 committed Sep 23, 2021
1 parent 38be5ed commit 052287f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
10 changes: 4 additions & 6 deletions pkg/gcp/gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down
16 changes: 13 additions & 3 deletions pkg/gcp/gcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,22 +131,32 @@ 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)
}
assert.NilError(t, err)
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,
Expand Down

0 comments on commit 052287f

Please sign in to comment.