From 8e9680affd6ae254f7a74c58649ba642c63427f4 Mon Sep 17 00:00:00 2001 From: bells17 Date: Thu, 20 Feb 2020 23:13:12 +0900 Subject: [PATCH] Modify to upper case variable name from lower case for unit tests --- .../snapshot_delete_test.go | 8 +++---- pkg/utils/util.go | 24 +++++++++---------- pkg/utils/util_test.go | 16 ++++++------- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/pkg/sidecar-controller/snapshot_delete_test.go b/pkg/sidecar-controller/snapshot_delete_test.go index 01240892..5c431037 100644 --- a/pkg/sidecar-controller/snapshot_delete_test.go +++ b/pkg/sidecar-controller/snapshot_delete_test.go @@ -62,10 +62,10 @@ var class5Parameters = map[string]string{ } var class6Parameters = map[string]string{ - "csi.storage.k8s.io/snapshotter-secret-name": "secret", - "csi.storage.k8s.io/snapshotter-secret-namespace": "default", - "csi.storage.k8s.io/snapshotter-list-secret-name": "secret", - "csi.storage.k8s.io/snapshotter-list-secret-namespace": "default", + utils.PrefixedSnapshotterSecretNameKey: "secret", + utils.PrefixedSnapshotterSecretNamespaceKey: "default", + utils.PrefixedSnapshotterListSecretNameKey: "secret", + utils.PrefixedSnapshotterListSecretNamespaceKey: "default", } var snapshotClasses = []*crdv1.VolumeSnapshotClass{ diff --git a/pkg/utils/util.go b/pkg/utils/util.go index b97a7383..4c135662 100644 --- a/pkg/utils/util.go +++ b/pkg/utils/util.go @@ -53,11 +53,11 @@ const ( // fields in subsequent CSI calls or Kubernetes API objects. csiParameterPrefix = "csi.storage.k8s.io/" - prefixedSnapshotterSecretNameKey = csiParameterPrefix + "snapshotter-secret-name" - prefixedSnapshotterSecretNamespaceKey = csiParameterPrefix + "snapshotter-secret-namespace" + PrefixedSnapshotterSecretNameKey = csiParameterPrefix + "snapshotter-secret-name" + PrefixedSnapshotterSecretNamespaceKey = csiParameterPrefix + "snapshotter-secret-namespace" - prefixedSnapshotterListSecretNameKey = csiParameterPrefix + "snapshotter-list-secret-name" - prefixedSnapshotterListSecretNamespaceKey = csiParameterPrefix + "snapshotter-list-secret-namespace" + PrefixedSnapshotterListSecretNameKey = csiParameterPrefix + "snapshotter-list-secret-name" + PrefixedSnapshotterListSecretNamespaceKey = csiParameterPrefix + "snapshotter-list-secret-namespace" // Name of finalizer on VolumeSnapshotContents that are bound by VolumeSnapshots VolumeSnapshotContentFinalizer = "snapshot.storage.kubernetes.io/volumesnapshotcontent-bound-protection" @@ -86,14 +86,14 @@ const ( var SnapshotterSecretParams = secretParamsMap{ name: "Snapshotter", - secretNameKey: prefixedSnapshotterSecretNameKey, - secretNamespaceKey: prefixedSnapshotterSecretNamespaceKey, + secretNameKey: PrefixedSnapshotterSecretNameKey, + secretNamespaceKey: PrefixedSnapshotterSecretNamespaceKey, } var SnapshotterListSecretParams = secretParamsMap{ name: "SnapshotterList", - secretNameKey: prefixedSnapshotterListSecretNameKey, - secretNamespaceKey: prefixedSnapshotterListSecretNamespaceKey, + secretNameKey: PrefixedSnapshotterListSecretNameKey, + secretNamespaceKey: PrefixedSnapshotterListSecretNamespaceKey, } func SnapshotKey(vs *crdv1.VolumeSnapshot) string { @@ -366,10 +366,10 @@ func RemovePrefixedParameters(param map[string]string) (map[string]string, error if strings.HasPrefix(k, csiParameterPrefix) { // Check if its well known switch k { - case prefixedSnapshotterSecretNameKey: - case prefixedSnapshotterSecretNamespaceKey: - case prefixedSnapshotterListSecretNameKey: - case prefixedSnapshotterListSecretNamespaceKey: + case PrefixedSnapshotterSecretNameKey: + case PrefixedSnapshotterSecretNamespaceKey: + case PrefixedSnapshotterListSecretNameKey: + case PrefixedSnapshotterListSecretNamespaceKey: default: return map[string]string{}, fmt.Errorf("found unknown parameter key \"%s\" with reserved namespace %s", k, csiParameterPrefix) } diff --git a/pkg/utils/util_test.go b/pkg/utils/util_test.go index d8e853b5..d3a37191 100644 --- a/pkg/utils/util_test.go +++ b/pkg/utils/util_test.go @@ -41,18 +41,18 @@ func TestGetSecretReference(t *testing.T) { }, "namespace, no name": { secretParams: SnapshotterSecretParams, - params: map[string]string{prefixedSnapshotterSecretNamespaceKey: "foo"}, + params: map[string]string{PrefixedSnapshotterSecretNamespaceKey: "foo"}, expectErr: true, }, "simple - valid": { secretParams: SnapshotterSecretParams, - params: map[string]string{prefixedSnapshotterSecretNameKey: "name", prefixedSnapshotterSecretNamespaceKey: "ns"}, + params: map[string]string{PrefixedSnapshotterSecretNameKey: "name", PrefixedSnapshotterSecretNamespaceKey: "ns"}, snapshot: &crdv1.VolumeSnapshot{}, expectRef: &v1.SecretReference{Name: "name", Namespace: "ns"}, }, "simple - invalid name": { secretParams: SnapshotterSecretParams, - params: map[string]string{prefixedSnapshotterSecretNameKey: "bad name", prefixedSnapshotterSecretNamespaceKey: "ns"}, + params: map[string]string{PrefixedSnapshotterSecretNameKey: "bad name", PrefixedSnapshotterSecretNamespaceKey: "ns"}, snapshot: &crdv1.VolumeSnapshot{}, expectRef: nil, expectErr: true, @@ -60,8 +60,8 @@ func TestGetSecretReference(t *testing.T) { "template - invalid": { secretParams: SnapshotterSecretParams, params: map[string]string{ - prefixedSnapshotterSecretNameKey: "static-${volumesnapshotcontent.name}-${volumesnapshot.namespace}-${volumesnapshot.name}-${volumesnapshot.annotations['akey']}", - prefixedSnapshotterSecretNamespaceKey: "static-${volumesnapshotcontent.name}-${volumesnapshot.namespace}", + PrefixedSnapshotterSecretNameKey: "static-${volumesnapshotcontent.name}-${volumesnapshot.namespace}-${volumesnapshot.name}-${volumesnapshot.annotations['akey']}", + PrefixedSnapshotterSecretNamespaceKey: "static-${volumesnapshotcontent.name}-${volumesnapshot.namespace}", }, snapContentName: "snapcontentname", snapshot: &crdv1.VolumeSnapshot{ @@ -111,14 +111,14 @@ func TestRemovePrefixedCSIParams(t *testing.T) { }, { name: "one prefixed", - params: map[string]string{prefixedSnapshotterSecretNameKey: "bar", "bim": "baz"}, + params: map[string]string{PrefixedSnapshotterSecretNameKey: "bar", "bim": "baz"}, expectedParams: map[string]string{"bim": "baz"}, }, { name: "all known prefixed", params: map[string]string{ - prefixedSnapshotterSecretNameKey: "csiBar", - prefixedSnapshotterSecretNamespaceKey: "csiBar", + PrefixedSnapshotterSecretNameKey: "csiBar", + PrefixedSnapshotterSecretNamespaceKey: "csiBar", }, expectedParams: map[string]string{}, },