Skip to content

Commit 7bde031

Browse files
julianKatzhajiler
authored andcommitted
Put some string variables into consts for re-use
1 parent 017867f commit 7bde031

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

pkg/parameters/parameters_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"testing"
2222

2323
"github.com/google/go-cmp/cmp"
24+
"github.com/google/go-cmp/cmp/cmpopts"
2425
"sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/constants"
2526
)
2627

@@ -283,11 +284,11 @@ func TestExtractAndDefaultParameters(t *testing.T) {
283284
},
284285
{
285286
name: "confidential compute enabled with valid KMS key",
286-
parameters: map[string]string{ParameterKeyEnableConfidentialCompute: "true", ParameterKeyDiskEncryptionKmsKey: validRegionalKmsKey},
287+
parameters: map[string]string{ParameterKeyEnableConfidentialCompute: "true", ParameterKeyDiskEncryptionKmsKey: validKmsKeyRegional},
287288
expectParams: DiskParameters{
288289
DiskType: "pd-standard",
289290
ReplicationType: "none",
290-
DiskEncryptionKMSKey: validRegionalKmsKey,
291+
DiskEncryptionKMSKey: validKmsKeyRegional,
291292
EnableConfidentialCompute: true,
292293
Tags: map[string]string{},
293294
Labels: map[string]string{},
@@ -551,7 +552,7 @@ func TestExtractAndDefaultParameters(t *testing.T) {
551552
return
552553
}
553554

554-
if diff := cmp.Diff(tc.expectParams, p); diff != "" {
555+
if diff := cmp.Diff(tc.expectParams, p, cmpopts.IgnoreUnexported(DiskParameters{})); diff != "" {
555556
t.Errorf("ExtractAndDefaultParameters(%+v): -want, +got \n%s", tc.parameters, diff)
556557
}
557558

pkg/parameters/utils_test.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ import (
66
"testing"
77
)
88

9+
const (
10+
validKmsKeyRegional = "projects/my-project/locations/us-central1/keyRings/TestKeyRing/cryptoKeys/test-key"
11+
validKmsKeyGlobal = "projects/my-project/locations/global/keyRings/TestKeyRing/cryptoKeys/test-key"
12+
invalidKmsKey = "projects/my-project/locations/keyRings/TestKeyRing/cryptoKeys/test-key"
13+
)
14+
915
func TestSnapshotStorageLocations(t *testing.T) {
1016
tests := []struct {
1117
desc string
@@ -161,15 +167,15 @@ func TestIsValidDiskEncryptionKmsKey(t *testing.T) {
161167
expectedIsValid bool
162168
}{
163169
{
164-
diskEncryptionKmsKey: "projects/my-project/locations/us-central1/keyRings/TestKeyRing/cryptoKeys/test-key",
170+
diskEncryptionKmsKey: validKmsKeyRegional,
165171
expectedIsValid: true,
166172
},
167173
{
168-
diskEncryptionKmsKey: "projects/my-project/locations/global/keyRings/TestKeyRing/cryptoKeys/test-key",
174+
diskEncryptionKmsKey: validKmsKeyGlobal,
169175
expectedIsValid: true,
170176
},
171177
{
172-
diskEncryptionKmsKey: "projects/my-project/locations/keyRings/TestKeyRing/cryptoKeys/test-key",
178+
diskEncryptionKmsKey: invalidKmsKey,
173179
expectedIsValid: false,
174180
},
175181
}

0 commit comments

Comments
 (0)