From 2cc48fefb17cc27c6b81a10a86a667ffe72c8020 Mon Sep 17 00:00:00 2001 From: pa250194 Date: Thu, 2 Sep 2021 08:51:02 -0500 Subject: [PATCH] Added initial testing for new GCP provider Signed-off-by: pa250194 --- pkg/gcp/gcp_test.go | 79 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/pkg/gcp/gcp_test.go b/pkg/gcp/gcp_test.go index 30412f49..459e691a 100644 --- a/pkg/gcp/gcp_test.go +++ b/pkg/gcp/gcp_test.go @@ -18,12 +18,24 @@ package gcp import ( "context" + "os" + "path/filepath" "testing" "gotest.tools/assert" ) +func TestNewClient(t *testing.T) { + // TODO: Setup GCP mock here + t.Skip() + client, err := NewClient(context.Background()) + assert.NilError(t, err) + assert.Assert(t, client.Client != nil) +} + func TestSetRange(t *testing.T) { + // TODO: Setup GCP mock here + t.Skip() client, err := NewClient(context.Background()) assert.NilError(t, err) testCases := []struct { @@ -60,3 +72,70 @@ func TestSetRange(t *testing.T) { }) } } + +func TestBucketExists(t *testing.T) { + // TODO: Setup GCP mock here + t.Skip() + ctx := context.Background() + bucketName := "" + client, err := NewClient(ctx) + assert.NilError(t, err) + exists, err := client.BucketExists(ctx, bucketName) + assert.NilError(t, err) + assert.Assert(t, exists) +} + +func TestObjectExists(t *testing.T) { + // TODO: Setup GCP mock here + t.Skip() + ctx := context.Background() + // bucketName is the name of the bucket which contains the object + bucketName := "" + // objectName is the path to the object within the bucket + objectName := "" + client, err := NewClient(ctx) + assert.NilError(t, err) + exists, attrs, err := client.ObjectExists(ctx, bucketName, objectName) + assert.NilError(t, err) + assert.Assert(t, exists) + assert.Assert(t, attrs != nil) +} + +func TestListObjects(t *testing.T) { + // TODO: Setup GCP mock here + t.Skip() + ctx := context.Background() + // bucketName is the name of the bucket which contains the object + bucketName := "" + client, err := NewClient(ctx) + assert.NilError(t, err) + objects := client.ListObjects(ctx, bucketName, nil) + assert.NilError(t, err) + assert.Assert(t, objects != nil) + for { + object, err := objects.Next() + if err == IteratorDone { + break + } + assert.Assert(t, object != nil) + } +} + +func TestFGetObject(t *testing.T) { + // TODO: Setup GCP mock here + t.Skip() + ctx := context.Background() + // bucketName is the name of the bucket which contains the object + bucketName := "" + // objectName is the path to the object within the bucket + objectName := "" + tempDir, err := os.MkdirTemp("", bucketName) + if err != nil { + assert.NilError(t, err) + } + localPath := filepath.Join(tempDir, objectName) + client, err := NewClient(ctx) + assert.NilError(t, err) + objErr := client.FGetObject(ctx, bucketName, objectName, localPath) + assert.NilError(t, objErr) +}