Fixed spelling and capitalization

Signed-off-by: pa250194 <pa250194@ncr.com>
This commit is contained in:
pa250194 2021-10-12 11:46:48 -05:00
parent 911ecc64b8
commit 69fffa0d27
2 changed files with 19 additions and 21 deletions

View File

@ -24,15 +24,15 @@ import (
"os" "os"
"path/filepath" "path/filepath"
gcpStorage "cloud.google.com/go/storage" gcpstorage "cloud.google.com/go/storage"
interator "google.golang.org/api/iterator" "google.golang.org/api/iterator"
"google.golang.org/api/option" "google.golang.org/api/option"
) )
var ( var (
// IteratorDone is returned when the looping of objects/content // IteratorDone is returned when the looping of objects/content
// has reached the end of the iteration. // has reached the end of the iteration.
IteratorDone = interator.Done IteratorDone = iterator.Done
// ErrorDirectoryExists is an error returned when the filename provided // ErrorDirectoryExists is an error returned when the filename provided
// is a directory. // is a directory.
ErrorDirectoryExists = errors.New("filename is a directory") ErrorDirectoryExists = errors.New("filename is a directory")
@ -44,15 +44,13 @@ var (
type GCPClient struct { type GCPClient struct {
// client for interacting with the Google Cloud // client for interacting with the Google Cloud
// Storage APIs. // Storage APIs.
*gcpStorage.Client *gcpstorage.Client
} }
// NewClient creates a new GCP storage client // NewClient creates a new GCP storage client. The Client will automatically look for the Google Application
// The Google Storage Client will automatically // Credential environment variable or look for the Google Application Credential file.
// look for the Google Application Credential environment variable
// or look for the Google Application Credential file.
func NewClient(ctx context.Context, opts ...option.ClientOption) (*GCPClient, error) { func NewClient(ctx context.Context, opts ...option.ClientOption) (*GCPClient, error) {
client, err := gcpStorage.NewClient(ctx, opts...) client, err := gcpstorage.NewClient(ctx, opts...)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -73,7 +71,7 @@ func ValidateSecret(secret map[string][]byte, name string) error {
// BucketExists checks if the bucket with the provided name exists. // BucketExists checks if the bucket with the provided name exists.
func (c *GCPClient) BucketExists(ctx context.Context, bucketName string) (bool, error) { func (c *GCPClient) BucketExists(ctx context.Context, bucketName string) (bool, error) {
_, err := c.Client.Bucket(bucketName).Attrs(ctx) _, err := c.Client.Bucket(bucketName).Attrs(ctx)
if err == gcpStorage.ErrBucketNotExist { if err == gcpstorage.ErrBucketNotExist {
return false, err return false, err
} }
if err != nil { if err != nil {
@ -86,7 +84,7 @@ func (c *GCPClient) BucketExists(ctx context.Context, bucketName string) (bool,
func (c *GCPClient) ObjectExists(ctx context.Context, bucketName, objectName string) (bool, error) { func (c *GCPClient) ObjectExists(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 {
return false, err return false, err
} }
if err != nil { if err != nil {
@ -160,7 +158,7 @@ func (c *GCPClient) FGetObject(ctx context.Context, bucketName, objectName, loca
// ListObjects lists the objects/contents of the bucket whose bucket name is provided. // ListObjects lists the objects/contents of the bucket whose bucket name is provided.
// the objects are returned as an Objectiterator and .Next() has to be called on them // the objects are returned as an Objectiterator and .Next() has to be called on them
// to loop through the Objects. // to loop through the Objects.
func (c *GCPClient) ListObjects(ctx context.Context, bucketName string, query *gcpStorage.Query) *gcpStorage.ObjectIterator { func (c *GCPClient) ListObjects(ctx context.Context, bucketName string, query *gcpstorage.Query) *gcpstorage.ObjectIterator {
items := c.Client.Bucket(bucketName).Objects(ctx, query) items := c.Client.Bucket(bucketName).Objects(ctx, query)
return items return items
} }

View File

@ -32,7 +32,7 @@ import (
"testing" "testing"
"time" "time"
gcpStorage "cloud.google.com/go/storage" gcpstorage "cloud.google.com/go/storage"
"github.com/fluxcd/source-controller/pkg/gcp" "github.com/fluxcd/source-controller/pkg/gcp"
"google.golang.org/api/googleapi" "google.golang.org/api/googleapi"
raw "google.golang.org/api/storage/v1" raw "google.golang.org/api/storage/v1"
@ -48,7 +48,7 @@ const (
var ( var (
hc *http.Client hc *http.Client
client *gcpStorage.Client client *gcpstorage.Client
close func() close func()
err error err error
) )
@ -101,7 +101,7 @@ func TestMain(m *testing.M) {
} }
}) })
ctx := context.Background() ctx := context.Background()
client, err = gcpStorage.NewClient(ctx, option.WithHTTPClient(hc)) client, err = gcpstorage.NewClient(ctx, option.WithHTTPClient(hc))
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
@ -131,7 +131,7 @@ 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, gcpStorage.ErrBucketNotExist.Error()) assert.Error(t, err, gcpstorage.ErrBucketNotExist.Error())
assert.Assert(t, !exists) assert.Assert(t, !exists)
} }
@ -140,7 +140,7 @@ func TestObjectExists(t *testing.T) {
Client: client, Client: client,
} }
exists, err := gcpClient.ObjectExists(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)
} }
assert.NilError(t, err) assert.NilError(t, err)
@ -153,7 +153,7 @@ func TestObjectNotExists(t *testing.T) {
Client: client, Client: client,
} }
exists, err := gcpClient.ObjectExists(context.Background(), bucketName, object) exists, err := gcpClient.ObjectExists(context.Background(), bucketName, object)
assert.Error(t, err, gcpStorage.ErrObjectNotExist.Error()) assert.Error(t, err, gcpstorage.ErrObjectNotExist.Error())
assert.Assert(t, !exists) assert.Assert(t, !exists)
} }
@ -161,15 +161,15 @@ func TestListObjects(t *testing.T) {
gcpClient := &gcp.GCPClient{ gcpClient := &gcp.GCPClient{
Client: client, Client: client,
} }
objectInterator := gcpClient.ListObjects(context.Background(), bucketName, nil) objectIterator := gcpClient.ListObjects(context.Background(), bucketName, nil)
for { for {
_, err := objectInterator.Next() _, err := objectIterator.Next()
if err == gcp.IteratorDone { if err == gcp.IteratorDone {
break break
} }
assert.NilError(t, err) assert.NilError(t, err)
} }
assert.Assert(t, objectInterator != nil) assert.Assert(t, objectIterator != nil)
} }
func TestFGetObject(t *testing.T) { func TestFGetObject(t *testing.T) {