Fixed spelling and capitalization
Signed-off-by: pa250194 <pa250194@ncr.com>
This commit is contained in:
parent
911ecc64b8
commit
69fffa0d27
|
@ -24,15 +24,15 @@ import (
|
|||
"os"
|
||||
"path/filepath"
|
||||
|
||||
gcpStorage "cloud.google.com/go/storage"
|
||||
interator "google.golang.org/api/iterator"
|
||||
gcpstorage "cloud.google.com/go/storage"
|
||||
"google.golang.org/api/iterator"
|
||||
"google.golang.org/api/option"
|
||||
)
|
||||
|
||||
var (
|
||||
// IteratorDone is returned when the looping of objects/content
|
||||
// has reached the end of the iteration.
|
||||
IteratorDone = interator.Done
|
||||
IteratorDone = iterator.Done
|
||||
// ErrorDirectoryExists is an error returned when the filename provided
|
||||
// is a directory.
|
||||
ErrorDirectoryExists = errors.New("filename is a directory")
|
||||
|
@ -44,15 +44,13 @@ var (
|
|||
type GCPClient struct {
|
||||
// client for interacting with the Google Cloud
|
||||
// Storage APIs.
|
||||
*gcpStorage.Client
|
||||
*gcpstorage.Client
|
||||
}
|
||||
|
||||
// NewClient creates a new GCP storage client
|
||||
// The Google Storage Client will automatically
|
||||
// look for the Google Application Credential environment variable
|
||||
// or look for the Google Application Credential file.
|
||||
// NewClient creates a new GCP storage client. The Client will automatically 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) {
|
||||
client, err := gcpStorage.NewClient(ctx, opts...)
|
||||
client, err := gcpstorage.NewClient(ctx, opts...)
|
||||
if err != nil {
|
||||
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.
|
||||
func (c *GCPClient) BucketExists(ctx context.Context, bucketName string) (bool, error) {
|
||||
_, err := c.Client.Bucket(bucketName).Attrs(ctx)
|
||||
if err == gcpStorage.ErrBucketNotExist {
|
||||
if err == gcpstorage.ErrBucketNotExist {
|
||||
return false, err
|
||||
}
|
||||
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) {
|
||||
_, err := c.Client.Bucket(bucketName).Object(objectName).Attrs(ctx)
|
||||
// ErrObjectNotExist is returned if the object does not exist
|
||||
if err == gcpStorage.ErrObjectNotExist {
|
||||
if err == gcpstorage.ErrObjectNotExist {
|
||||
return false, err
|
||||
}
|
||||
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.
|
||||
// the objects are returned as an Objectiterator and .Next() has to be called on them
|
||||
// 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)
|
||||
return items
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
gcpStorage "cloud.google.com/go/storage"
|
||||
gcpstorage "cloud.google.com/go/storage"
|
||||
"github.com/fluxcd/source-controller/pkg/gcp"
|
||||
"google.golang.org/api/googleapi"
|
||||
raw "google.golang.org/api/storage/v1"
|
||||
|
@ -48,7 +48,7 @@ const (
|
|||
|
||||
var (
|
||||
hc *http.Client
|
||||
client *gcpStorage.Client
|
||||
client *gcpstorage.Client
|
||||
close func()
|
||||
err error
|
||||
)
|
||||
|
@ -101,7 +101,7 @@ func TestMain(m *testing.M) {
|
|||
}
|
||||
})
|
||||
ctx := context.Background()
|
||||
client, err = gcpStorage.NewClient(ctx, option.WithHTTPClient(hc))
|
||||
client, err = gcpstorage.NewClient(ctx, option.WithHTTPClient(hc))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
@ -131,7 +131,7 @@ func TestBucketNotExists(t *testing.T) {
|
|||
Client: client,
|
||||
}
|
||||
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)
|
||||
}
|
||||
|
||||
|
@ -140,7 +140,7 @@ func TestObjectExists(t *testing.T) {
|
|||
Client: client,
|
||||
}
|
||||
exists, err := gcpClient.ObjectExists(context.Background(), bucketName, objectName)
|
||||
if err == gcpStorage.ErrObjectNotExist {
|
||||
if err == gcpstorage.ErrObjectNotExist {
|
||||
assert.NilError(t, err)
|
||||
}
|
||||
assert.NilError(t, err)
|
||||
|
@ -153,7 +153,7 @@ func TestObjectNotExists(t *testing.T) {
|
|||
Client: client,
|
||||
}
|
||||
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)
|
||||
}
|
||||
|
||||
|
@ -161,15 +161,15 @@ func TestListObjects(t *testing.T) {
|
|||
gcpClient := &gcp.GCPClient{
|
||||
Client: client,
|
||||
}
|
||||
objectInterator := gcpClient.ListObjects(context.Background(), bucketName, nil)
|
||||
objectIterator := gcpClient.ListObjects(context.Background(), bucketName, nil)
|
||||
for {
|
||||
_, err := objectInterator.Next()
|
||||
_, err := objectIterator.Next()
|
||||
if err == gcp.IteratorDone {
|
||||
break
|
||||
}
|
||||
assert.NilError(t, err)
|
||||
}
|
||||
assert.Assert(t, objectInterator != nil)
|
||||
assert.Assert(t, objectIterator != nil)
|
||||
}
|
||||
|
||||
func TestFGetObject(t *testing.T) {
|
||||
|
|
Loading…
Reference in New Issue