make use of short declaration of variables and cleanup code
Signed-off-by: Humble Chirammal <hchiramm@redhat.com>
This commit is contained in:
@@ -27,7 +27,6 @@ import (
|
||||
)
|
||||
|
||||
func TestSyncContent(t *testing.T) {
|
||||
|
||||
tests := []controllerTest{
|
||||
{
|
||||
name: "1-1: Basic content update ready to use",
|
||||
|
@@ -57,7 +57,6 @@ func NewCSIHandler(
|
||||
}
|
||||
|
||||
func (handler *csiHandler) CreateSnapshot(content *crdv1.VolumeSnapshotContent, parameters map[string]string, snapshotterCredentials map[string]string) (string, string, time.Time, int64, bool, error) {
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), handler.timeout)
|
||||
defer cancel()
|
||||
|
||||
|
@@ -100,13 +100,17 @@ type controllerTest struct {
|
||||
|
||||
type testCall func(ctrl *csiSnapshotSideCarController, reactor *snapshotReactor, test controllerTest) error
|
||||
|
||||
const testNamespace = "default"
|
||||
const mockDriverName = "csi-mock-plugin"
|
||||
const (
|
||||
testNamespace = "default"
|
||||
mockDriverName = "csi-mock-plugin"
|
||||
)
|
||||
|
||||
var errVersionConflict = errors.New("VersionError")
|
||||
var nocontents []*crdv1.VolumeSnapshotContent
|
||||
var noevents = []string{}
|
||||
var noerrors = []reactorError{}
|
||||
var (
|
||||
errVersionConflict = errors.New("VersionError")
|
||||
nocontents []*crdv1.VolumeSnapshotContent
|
||||
noevents = []string{}
|
||||
noerrors = []reactorError{}
|
||||
)
|
||||
|
||||
// snapshotReactor is a core.Reactor that simulates etcd and API server. It
|
||||
// stores:
|
||||
@@ -681,6 +685,7 @@ func withContentAnnotations(content []*crdv1.VolumeSnapshotContent, annotations
|
||||
func testSyncContent(ctrl *csiSnapshotSideCarController, reactor *snapshotReactor, test controllerTest) error {
|
||||
return ctrl.syncContent(test.initialContents[0])
|
||||
}
|
||||
|
||||
func testSyncContentError(ctrl *csiSnapshotSideCarController, reactor *snapshotReactor, test controllerTest) error {
|
||||
err := ctrl.syncContent(test.initialContents[0])
|
||||
if err != nil {
|
||||
@@ -712,7 +717,6 @@ var (
|
||||
// controller waits for the operation lock. Controller is then resumed and we
|
||||
// check how it behaves.
|
||||
func wrapTestWithInjectedOperation(toWrap testCall, injectBeforeOperation func(ctrl *csiSnapshotSideCarController, reactor *snapshotReactor)) testCall {
|
||||
|
||||
return func(ctrl *csiSnapshotSideCarController, reactor *snapshotReactor, test controllerTest) error {
|
||||
// Inject a hook before async operation starts
|
||||
klog.V(4).Infof("reactor:injecting call")
|
||||
|
@@ -233,7 +233,7 @@ func (ctrl *csiSnapshotSideCarController) checkandUpdateContentStatusOperation(c
|
||||
var err error
|
||||
var creationTime time.Time
|
||||
var size int64
|
||||
var readyToUse = false
|
||||
readyToUse := false
|
||||
var driverName string
|
||||
var snapshotID string
|
||||
var snapshotterListCredentials map[string]string
|
||||
@@ -283,7 +283,6 @@ func (ctrl *csiSnapshotSideCarController) checkandUpdateContentStatusOperation(c
|
||||
return updatedContent, nil
|
||||
}
|
||||
return ctrl.createSnapshotWrapper(content)
|
||||
|
||||
}
|
||||
|
||||
// This is a wrapper function for the snapshot creation process.
|
||||
|
@@ -17,26 +17,27 @@ limitations under the License.
|
||||
package sidecar_controller
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"errors"
|
||||
|
||||
crdv1 "github.com/kubernetes-csi/external-snapshotter/client/v6/apis/volumesnapshot/v1"
|
||||
"github.com/kubernetes-csi/external-snapshotter/v6/pkg/utils"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
||||
var defaultSize int64 = 1000
|
||||
var emptySize int64
|
||||
var deletePolicy = crdv1.VolumeSnapshotContentDelete
|
||||
var retainPolicy = crdv1.VolumeSnapshotContentRetain
|
||||
var timeNow = time.Now()
|
||||
var timeNowMetav1 = metav1.Now()
|
||||
var False = false
|
||||
var True = true
|
||||
var (
|
||||
defaultSize int64 = 1000
|
||||
emptySize int64
|
||||
deletePolicy = crdv1.VolumeSnapshotContentDelete
|
||||
retainPolicy = crdv1.VolumeSnapshotContentRetain
|
||||
timeNow = time.Now()
|
||||
timeNowMetav1 = metav1.Now()
|
||||
False = false
|
||||
True = true
|
||||
)
|
||||
|
||||
var class1Parameters = map[string]string{
|
||||
"param1": "value1",
|
||||
@@ -149,7 +150,6 @@ var snapshotClasses = []*crdv1.VolumeSnapshotClass{
|
||||
// 2. Call the syncContent *once*.
|
||||
// 3. Compare resulting contents with expected contents.
|
||||
func TestDeleteSync(t *testing.T) {
|
||||
|
||||
tests := []controllerTest{
|
||||
{
|
||||
name: "1-1 - content non-nil DeletionTimestamp with delete policy will delete snapshot",
|
||||
|
Reference in New Issue
Block a user