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 b192fcd commit 7c7657c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 34 deletions.
32 changes: 17 additions & 15 deletions pkg/function/create_csi_snapshot_static_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,18 @@ 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 +87,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 +102,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
39 changes: 20 additions & 19 deletions pkg/function/delete_csi_snapshot_content_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,18 @@ 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 +86,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 +104,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 7c7657c

Please sign in to comment.