Skip to content

Commit

Permalink
Update unit test to test with GCP profile (#5900)
Browse files Browse the repository at this point in the history
  • Loading branch information
SupriyaKasten authored and Ilya Kislenko committed Jun 25, 2019
1 parent 2c72e6d commit 272ef43
Showing 1 changed file with 35 additions and 23 deletions.
58 changes: 35 additions & 23 deletions pkg/function/data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,27 @@ import (
crv1alpha1 "github.com/kanisterio/kanister/pkg/apis/cr/v1alpha1"
"github.com/kanisterio/kanister/pkg/client/clientset/versioned"
"github.com/kanisterio/kanister/pkg/kube"
"github.com/kanisterio/kanister/pkg/location"
"github.com/kanisterio/kanister/pkg/objectstore"
"github.com/kanisterio/kanister/pkg/param"
"github.com/kanisterio/kanister/pkg/resource"
"github.com/kanisterio/kanister/pkg/testutil"
)

type DataSuite struct {
cli kubernetes.Interface
crCli versioned.Interface
namespace string
cli kubernetes.Interface
crCli versioned.Interface
namespace string
profile *param.Profile
providerType objectstore.ProviderType
}

var _ = Suite(&DataSuite{})
const (
testBucketName = "kio-store-tests"
)

var _ = Suite(&DataSuite{providerType: objectstore.ProviderTypeS3})
var _ = Suite(&DataSuite{providerType: objectstore.ProviderTypeGCS})

func (s *DataSuite) SetUpSuite(c *C) {
config, err := kube.LoadConfig()
Expand Down Expand Up @@ -56,9 +64,29 @@ func (s *DataSuite) SetUpSuite(c *C) {
p := testutil.NewTestProfile(s.namespace, sec.GetName())
_, err = s.crCli.CrV1alpha1().Profiles(s.namespace).Create(p)
c.Assert(err, IsNil)

var location crv1alpha1.Location
switch s.providerType {
case objectstore.ProviderTypeS3:
location = crv1alpha1.Location{
Type: crv1alpha1.LocationTypeS3Compliant,
}
case objectstore.ProviderTypeGCS:
location = crv1alpha1.Location{
Type: crv1alpha1.LocationTypeGCS,
}
default:
c.Fatalf("Unrecognized objectstore '%s'", s.providerType)
}
location.Prefix = "testBackupRestoreLocDelete"
location.Bucket = testBucketName
s.profile = testutil.ObjectStoreProfileOrSkip(c, s.providerType, location)
}

func (s *DataSuite) TearDownSuite(c *C) {
ctx := context.Background()
err := location.Delete(ctx, *s.profile, "")
c.Assert(err, IsNil)
if s.namespace != "" {
s.cli.Core().Namespaces().Delete(s.namespace, nil)
}
Expand Down Expand Up @@ -182,13 +210,7 @@ func (s *DataSuite) TestBackupRestoreDeleteData(c *C) {

tp, err := param.New(ctx, s.cli, s.crCli, as)
c.Assert(err, IsNil)

location := crv1alpha1.Location{
Type: crv1alpha1.LocationTypeS3Compliant,
Prefix: "testBackupRestoreLocDelete",
Bucket: testutil.GetEnvOrSkip(c, testutil.TestS3BucketName),
}
tp.Profile = testutil.ObjectStoreProfileOrSkip(c, objectstore.ProviderTypeS3, location)
tp.Profile = s.profile

// Test backup
bp := *newBackupDataBlueprint()
Expand Down Expand Up @@ -254,12 +276,7 @@ func (s *DataSuite) TestBackupRestoreDataWithSnapshotID(c *C) {

tp, err := param.New(ctx, s.cli, s.crCli, as)
c.Assert(err, IsNil)

location := crv1alpha1.Location{
Type: crv1alpha1.LocationTypeS3Compliant,
Bucket: testutil.GetEnvOrSkip(c, testutil.TestS3BucketName),
}
tp.Profile = testutil.ObjectStoreProfileOrSkip(c, objectstore.ProviderTypeS3, location)
tp.Profile = s.profile

// Test backup
bp := *newBackupDataBlueprint()
Expand Down Expand Up @@ -426,11 +443,6 @@ func (s *DataSuite) initPVCTemplateParams(c *C, pvc *v1.PersistentVolumeClaim, o
}
tp, err := param.New(context.Background(), s.cli, s.crCli, as)
c.Assert(err, IsNil)

location := crv1alpha1.Location{
Type: crv1alpha1.LocationTypeS3Compliant,
Bucket: testutil.GetEnvOrSkip(c, testutil.TestS3BucketName),
}
tp.Profile = testutil.ObjectStoreProfileOrSkip(c, objectstore.ProviderTypeS3, location)
tp.Profile = s.profile
return tp
}

0 comments on commit 272ef43

Please sign in to comment.