Refactor comments and method names
Signed-off-by: pa250194 <pa250194@ncr.com>
This commit is contained in:
parent
02102de2c7
commit
751243ce50
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue