From 0e4d11b0fb49fdb2ed303cbad74a5c4bcfe3d76c Mon Sep 17 00:00:00 2001 From: Humble Chirammal Date: Sun, 6 Jan 2019 14:31:02 +0530 Subject: [PATCH] Correct error variables and fix other golint errors. Signed-off-by: Humble Chirammal --- pkg/connection/connection_test.go | 12 ++++++------ pkg/controller/framework_test.go | 26 +++++++++++++------------- pkg/controller/snapshot_controller.go | 6 +++--- pkg/controller/util.go | 10 +++++----- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/pkg/connection/connection_test.go b/pkg/connection/connection_test.go index 13362e5c..85b54e3e 100644 --- a/pkg/connection/connection_test.go +++ b/pkg/connection/connection_test.go @@ -104,7 +104,7 @@ func TestGetPluginInfo(t *testing.T) { in := &csi.GetPluginInfoRequest{} out := test.output - var injectedErr error = nil + var injectedErr error if test.injectError { injectedErr = fmt.Errorf("mock error") } @@ -214,7 +214,7 @@ func TestSupportsControllerCreateSnapshot(t *testing.T) { in := &csi.ControllerGetCapabilitiesRequest{} out := test.output - var injectedErr error = nil + var injectedErr error if test.injectError { injectedErr = fmt.Errorf("mock error") } @@ -354,7 +354,7 @@ func TestSupportsControllerListSnapshots(t *testing.T) { in := &csi.ControllerGetCapabilitiesRequest{} out := test.output - var injectedErr error = nil + var injectedErr error if test.injectError { injectedErr = fmt.Errorf("mock error") } @@ -524,7 +524,7 @@ func TestCreateSnapshot(t *testing.T) { for _, test := range tests { in := test.input out := test.output - var injectedErr error = nil + var injectedErr error if test.injectError != codes.OK { injectedErr = status.Error(test.injectError, fmt.Sprintf("Injecting error %d", test.injectError)) } @@ -632,7 +632,7 @@ func TestDeleteSnapshot(t *testing.T) { for _, test := range tests { in := test.input out := test.output - var injectedErr error = nil + var injectedErr error if test.injectError != codes.OK { injectedErr = status.Error(test.injectError, fmt.Sprintf("Injecting error %d", test.injectError)) } @@ -730,7 +730,7 @@ func TestGetSnapshotStatus(t *testing.T) { for _, test := range tests { in := test.input out := test.output - var injectedErr error = nil + var injectedErr error if test.injectError != codes.OK { injectedErr = status.Error(test.injectError, fmt.Sprintf("Injecting error %d", test.injectError)) } diff --git a/pkg/controller/framework_test.go b/pkg/controller/framework_test.go index 5e5959df..d3c6680e 100644 --- a/pkg/controller/framework_test.go +++ b/pkg/controller/framework_test.go @@ -119,7 +119,7 @@ type testCall func(ctrl *csiSnapshotController, reactor *snapshotReactor, test c const testNamespace = "default" const mockDriverName = "csi-mock-plugin" -var versionConflictError = errors.New("VersionError") +var errVersionConflict = errors.New("VersionError") var nocontents []*crdv1.VolumeSnapshotContent var nosnapshots []*crdv1.VolumeSnapshot var noevents = []string{} @@ -228,7 +228,7 @@ func (r *snapshotReactor) React(action core.Action) (handled bool, ret runtime.O storedVer, _ := strconv.Atoi(storedVolume.ResourceVersion) requestedVer, _ := strconv.Atoi(content.ResourceVersion) if storedVer != requestedVer { - return true, obj, versionConflictError + return true, obj, errVersionConflict } // Don't modify the existing object content = content.DeepCopy() @@ -254,7 +254,7 @@ func (r *snapshotReactor) React(action core.Action) (handled bool, ret runtime.O storedVer, _ := strconv.Atoi(storedSnapshot.ResourceVersion) requestedVer, _ := strconv.Atoi(snapshot.ResourceVersion) if storedVer != requestedVer { - return true, obj, versionConflictError + return true, obj, errVersionConflict } // Don't modify the existing object snapshot = snapshot.DeepCopy() @@ -966,16 +966,16 @@ func testSyncContent(ctrl *csiSnapshotController, reactor *snapshotReactor, test } var ( - classEmpty string = "" - classGold string = "gold" - classSilver string = "silver" - classNonExisting string = "non-existing" - defaultClass string = "default-class" - emptySecretClass string = "empty-secret-class" - invalidSecretClass string = "invalid-secret-class" - validSecretClass string = "valid-secret-class" - sameDriver string = "sameDriver" - diffDriver string = "diffDriver" + classEmpty string + classGold = "gold" + classSilver = "silver" + classNonExisting = "non-existing" + defaultClass = "default-class" + emptySecretClass = "empty-secret-class" + invalidSecretClass = "invalid-secret-class" + validSecretClass = "valid-secret-class" + sameDriver = "sameDriver" + diffDriver = "diffDriver" ) // wrapTestWithInjectedOperation returns a testCall that: diff --git a/pkg/controller/snapshot_controller.go b/pkg/controller/snapshot_controller.go index d462a555..93975e93 100644 --- a/pkg/controller/snapshot_controller.go +++ b/pkg/controller/snapshot_controller.go @@ -556,9 +556,9 @@ func (ctrl *csiSnapshotController) getCreateSnapshotInput(snapshot *crdv1.Volume func (ctrl *csiSnapshotController) checkandUpdateBoundSnapshotStatusOperation(snapshot *crdv1.VolumeSnapshot, content *crdv1.VolumeSnapshotContent) (*crdv1.VolumeSnapshot, error) { var err error - var timestamp int64 = 0 - var size int64 = 0 - var readyToUse bool = false + var timestamp int64 + var size int64 + var readyToUse = false class, volume, _, snapshotterCredentials, err := ctrl.getCreateSnapshotInput(snapshot) if err != nil { return nil, fmt.Errorf("failed to get input parameters to create snapshot %s: %q", snapshot.Name, err) diff --git a/pkg/controller/util.go b/pkg/controller/util.go index 570099c4..792d22ec 100644 --- a/pkg/controller/util.go +++ b/pkg/controller/util.go @@ -68,7 +68,7 @@ const ( ) var snapshotterSecretParams = deprecatedSecretParamsMap{ - name: "Snapshotter", + name: "Snapshotter", deprecatedSecretNameKey: snapshotterSecretNameKey, deprecatedSecretNamespaceKey: snapshotterSecretNamespaceKey, secretNameKey: prefixedSnapshotterSecretNameKey, @@ -168,21 +168,21 @@ func verifyAndGetSecretNameAndNamespaceTemplate(secret deprecatedSecretParamsMap numNamespace := 0 if t, ok := snapshotClassParams[secret.deprecatedSecretNameKey]; ok { nameTemplate = t - numName += 1 + numName++ glog.Warning(deprecationWarning(secret.deprecatedSecretNameKey, secret.secretNameKey, "")) } if t, ok := snapshotClassParams[secret.deprecatedSecretNamespaceKey]; ok { namespaceTemplate = t - numNamespace += 1 + numNamespace++ glog.Warning(deprecationWarning(secret.deprecatedSecretNamespaceKey, secret.secretNamespaceKey, "")) } if t, ok := snapshotClassParams[secret.secretNameKey]; ok { nameTemplate = t - numName += 1 + numName++ } if t, ok := snapshotClassParams[secret.secretNamespaceKey]; ok { namespaceTemplate = t - numNamespace += 1 + numNamespace++ } if numName > 1 || numNamespace > 1 {