Skip to content

Commit

Permalink
Change testSuite fields to local constants
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Sim <ivan.sim@kasten.io>
  • Loading branch information
ihcsim committed Mar 22, 2022
1 parent 67f2411 commit 4ff88c0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 51 deletions.
41 changes: 18 additions & 23 deletions pkg/function/create_csi_snapshot_static_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,22 @@ import (
"github.com/kanisterio/kanister/pkg/kube/snapshot"
)

type CreateCSISnapshotStaticTestSuite struct {
snapshotName string
namespace string
deletionPolicy string
driver string
snapshotHandle string
snapshotClass string
}
type CreateCSISnapshotStaticTestSuite struct{}

var _ = Suite(&CreateCSISnapshotStaticTestSuite{})

func (testSuite *CreateCSISnapshotStaticTestSuite) SetUpSuite(c *C) {
testSuite.snapshotName = "test-snapshot"
testSuite.namespace = "test-namespace"
testSuite.deletionPolicy = "Retain"
testSuite.driver = "test-driver"
testSuite.snapshotClass = "test-snapshot-class"
testSuite.snapshotHandle = "test-snapshot-handle"
}
func (testSuite *CreateCSISnapshotStaticTestSuite) SetUpSuite(c *C) {}

func (testSuite *CreateCSISnapshotStaticTestSuite) TestCreateCSISnapshotStatic(c *C) {
const (
snapshotName = "test-snapshot"
namespace = "test-namespace"
deletionPolicy = "Retain"
driver = "test-driver"
snapshotClass = "test-snapshot-class"
snapshotHandle = "test-snapshot-handle"
)

for _, api := range []*metav1.APIResourceList{
{
TypeMeta: metav1.TypeMeta{
Expand Down Expand Up @@ -85,7 +80,7 @@ func (testSuite *CreateCSISnapshotStaticTestSuite) TestCreateCSISnapshotStatic(c

namespace := &v1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: testSuite.namespace,
Name: namespace,
},
}
_, err = fakeCli.CoreV1().Namespaces().Create(ctx, namespace, metav1.CreateOptions{})
Expand All @@ -100,20 +95,20 @@ func (testSuite *CreateCSISnapshotStaticTestSuite) TestCreateCSISnapshotStatic(c

snapshotClass := snapshot.UnstructuredVolumeSnapshotClass(
gvr,
testSuite.snapshotClass,
testSuite.driver,
testSuite.deletionPolicy,
snapshotClass,
driver,
deletionPolicy,
nil)
_, err = dynCli.Resource(gvr).Create(ctx, snapshotClass, metav1.CreateOptions{})
c.Assert(err, IsNil)

_, err = createCSISnapshotStatic(
ctx,
fakeSnapshotter,
testSuite.snapshotName,
snapshotName,
namespace.GetName(),
testSuite.driver,
testSuite.snapshotHandle,
driver,
snapshotHandle,
snapshotClass.GetName(), false)
c.Assert(err, IsNil)

Expand Down
49 changes: 21 additions & 28 deletions pkg/function/delete_csi_snapshot_content_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,22 @@ import (
"github.com/kanisterio/kanister/pkg/kube/snapshot"
)

type DeleteCSISnapshotContentTestSuite struct {
snapshotContentName string
snapshotName string
snapshotNamespace string
snapshotClassName string
deletionPolicy string
driver string
handle string
}
type DeleteCSISnapshotContentTestSuite struct{}

var _ = Suite(&DeleteCSISnapshotContentTestSuite{})

func (testSuite *DeleteCSISnapshotContentTestSuite) SetUpSuite(c *C) {
testSuite.snapshotContentName = "test-delete-snapshot-content"
testSuite.snapshotName = "test-delete-snapshot-name"
testSuite.snapshotNamespace = "test-delete-snapshot-namespace"
testSuite.snapshotClassName = "test-delete-snapshot-class"
testSuite.deletionPolicy = "Retain"
testSuite.driver = "test-delete-driver"
testSuite.handle = "test-delete-handle"
}
func (testSuite *DeleteCSISnapshotContentTestSuite) SetUpSuite(c *C) {}

func (testSuite *DeleteCSISnapshotContentTestSuite) TestDeleteCSISnapshotContent(c *C) {
const (
snapshotContentName = "test-delete-snapshot-content"
snapshotName = "test-delete-snapshot-name"
snapshotNamespace = "test-delete-snapshot-namespace"
snapshotClassName = "test-delete-snapshot-class"
deletionPolicy = "Retain"
driver = "test-delete-driver"
handle = "test-delete-handle"
)
for _, api := range []*metav1.APIResourceList{
{
TypeMeta: metav1.TypeMeta{
Expand Down Expand Up @@ -85,15 +78,15 @@ func (testSuite *DeleteCSISnapshotContentTestSuite) TestDeleteCSISnapshotContent
c.Assert(err, IsNil)

source := &snapshot.Source{
Handle: testSuite.snapshotNamespace,
Driver: testSuite.driver,
VolumeSnapshotClassName: testSuite.snapshotClassName,
Handle: snapshotNamespace,
Driver: driver,
VolumeSnapshotClassName: snapshotClassName,
}
err = fakeSnapshotter.CreateContentFromSource(ctx, source,
testSuite.snapshotContentName,
testSuite.snapshotName,
testSuite.snapshotNamespace,
testSuite.deletionPolicy)
snapshotContentName,
snapshotName,
snapshotNamespace,
deletionPolicy)
c.Assert(err, IsNil)

gv := strings.Split(api.GroupVersion, "/")
Expand All @@ -103,13 +96,13 @@ func (testSuite *DeleteCSISnapshotContentTestSuite) TestDeleteCSISnapshotContent
Resource: snapshot.VolumeSnapshotContentResourcePlural,
}

_, err = dynCli.Resource(gvr).Get(ctx, testSuite.snapshotContentName, metav1.GetOptions{})
_, err = dynCli.Resource(gvr).Get(ctx, snapshotContentName, metav1.GetOptions{})
c.Assert(err, IsNil)

err = deleteCSISnapshotContent(ctx, fakeSnapshotter, testSuite.snapshotContentName)
err = deleteCSISnapshotContent(ctx, fakeSnapshotter, snapshotContentName)
c.Assert(err, IsNil)

_, err = dynCli.Resource(gvr).Get(ctx, testSuite.snapshotContentName, metav1.GetOptions{})
_, err = dynCli.Resource(gvr).Get(ctx, snapshotContentName, metav1.GetOptions{})
c.Assert(err, NotNil)
}
}

0 comments on commit 4ff88c0

Please sign in to comment.