Skip to content

Commit 751243c

Browse files
pa250194squaremo
authored andcommitted
Refactor comments and method names
Signed-off-by: pa250194 <[email protected]>
1 parent 02102de commit 751243c

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

pkg/gcp/gcp.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,8 @@ func (c *GCPClient) BucketExists(ctx context.Context, bucketName string) (bool,
8282
return true, nil
8383
}
8484

85-
// ObjectAttributes checks if the object with the provided name exists.
86-
// If it exists the Object attributes are returned.
87-
func (c *GCPClient) ObjectAttributes(ctx context.Context, bucketName, objectName string) (bool, error) {
85+
// ObjectExists checks if the object with the provided name exists.
86+
func (c *GCPClient) ObjectExists(ctx context.Context, bucketName, objectName string) (bool, error) {
8887
_, err := c.Client.Bucket(bucketName).Object(objectName).Attrs(ctx)
8988
// ErrObjectNotExist is returned if the object does not exist
9089
if err == gcpStorage.ErrObjectNotExist {
@@ -124,9 +123,8 @@ func (c *GCPClient) FGetObject(ctx context.Context, bucketName, objectName, loca
124123
}
125124

126125
// ObjectExists verifies if object exists and you have permission to access.
127-
// Check if the object exists and if you have permission to access it
128-
// The Object attributes are returned if the Object exists.
129-
exists, err := c.ObjectAttributes(ctx, bucketName, objectName)
126+
// Check if the object exists and if you have permission to access it.
127+
exists, err := c.ObjectExists(ctx, bucketName, objectName)
130128
if err != nil {
131129
return err
132130
}

pkg/gcp/gcp_test.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,22 +131,32 @@ func TestBucketNotExists(t *testing.T) {
131131
Client: client,
132132
}
133133
exists, err := gcpClient.BucketExists(context.Background(), bucket)
134-
assert.Error(t, err, "storage: bucket doesn't exist")
134+
assert.Error(t, err, gcpStorage.ErrBucketNotExist.Error())
135135
assert.Assert(t, !exists)
136136
}
137137

138-
func TestObjectAttributes(t *testing.T) {
138+
func TestObjectExists(t *testing.T) {
139139
gcpClient := &gcp.GCPClient{
140140
Client: client,
141141
}
142-
exists, err := gcpClient.ObjectAttributes(context.Background(), bucketName, objectName)
142+
exists, err := gcpClient.ObjectExists(context.Background(), bucketName, objectName)
143143
if err == gcpStorage.ErrObjectNotExist {
144144
assert.NilError(t, err)
145145
}
146146
assert.NilError(t, err)
147147
assert.Assert(t, exists)
148148
}
149149

150+
func TestObjectNotExists(t *testing.T) {
151+
object := "doesnotexists.yaml"
152+
gcpClient := &gcp.GCPClient{
153+
Client: client,
154+
}
155+
exists, err := gcpClient.ObjectExists(context.Background(), bucketName, object)
156+
assert.Error(t, err, gcpStorage.ErrObjectNotExist.Error())
157+
assert.Assert(t, !exists)
158+
}
159+
150160
func TestListObjects(t *testing.T) {
151161
gcpClient := &gcp.GCPClient{
152162
Client: client,

0 commit comments

Comments
 (0)