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
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ObjectAttributes checks if the object with the provided name exists.
|
// ObjectExists checks if the object with the provided name exists.
|
||||||
// If it exists the Object attributes are returned.
|
func (c *GCPClient) ObjectExists(ctx context.Context, bucketName, objectName string) (bool, error) {
|
||||||
func (c *GCPClient) ObjectAttributes(ctx context.Context, bucketName, objectName string) (bool, error) {
|
|
||||||
_, err := c.Client.Bucket(bucketName).Object(objectName).Attrs(ctx)
|
_, err := c.Client.Bucket(bucketName).Object(objectName).Attrs(ctx)
|
||||||
// ErrObjectNotExist is returned if the object does not exist
|
// ErrObjectNotExist is returned if the object does not exist
|
||||||
if err == gcpStorage.ErrObjectNotExist {
|
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.
|
// ObjectExists verifies if object exists and you have permission to access.
|
||||||
// Check if the object exists and if you have permission to access it
|
// 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.ObjectExists(ctx, bucketName, objectName)
|
||||||
exists, err := c.ObjectAttributes(ctx, bucketName, objectName)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -131,15 +131,15 @@ func TestBucketNotExists(t *testing.T) {
|
||||||
Client: client,
|
Client: client,
|
||||||
}
|
}
|
||||||
exists, err := gcpClient.BucketExists(context.Background(), bucket)
|
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)
|
assert.Assert(t, !exists)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestObjectAttributes(t *testing.T) {
|
func TestObjectExists(t *testing.T) {
|
||||||
gcpClient := &gcp.GCPClient{
|
gcpClient := &gcp.GCPClient{
|
||||||
Client: client,
|
Client: client,
|
||||||
}
|
}
|
||||||
exists, err := gcpClient.ObjectAttributes(context.Background(), bucketName, objectName)
|
exists, err := gcpClient.ObjectExists(context.Background(), bucketName, objectName)
|
||||||
if err == gcpStorage.ErrObjectNotExist {
|
if err == gcpStorage.ErrObjectNotExist {
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
}
|
}
|
||||||
|
@ -147,6 +147,16 @@ func TestObjectAttributes(t *testing.T) {
|
||||||
assert.Assert(t, exists)
|
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) {
|
func TestListObjects(t *testing.T) {
|
||||||
gcpClient := &gcp.GCPClient{
|
gcpClient := &gcp.GCPClient{
|
||||||
Client: client,
|
Client: client,
|
||||||
|
|
Loading…
Reference in New Issue