Skip to content

Commit 63a927b

Browse files
committed
add e2e test case for labels
1 parent 957e733 commit 63a927b

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

pkg/common/utils.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -161,15 +161,15 @@ func ConvertLabelsStringToMap(labels string) (map[string]string, error) {
161161
return labelsMap, nil
162162
}
163163

164-
regexKey, _ := regexp.Compile("^[a-z][-_a-z0-9]{0,62}$")
164+
regexKey, _ := regexp.Compile("^\\p{Ll}[\\p{Ll}0-9_-]{0,62}$")
165165
checkLabelKeyFn := func(key string) error {
166166
if !regexKey.MatchString(key) {
167167
return fmt.Errorf("label key %q is invalid (lowercase, digit, _ and - chars are allowed / 1-63 characters", key)
168168
}
169169
return nil
170170
}
171171

172-
regexValue, _ := regexp.Compile("^[-_a-z0-9]{0,63}$")
172+
regexValue, _ := regexp.Compile("^[\\p{Ll}0-9_-]{0,63}$")
173173
checkLabelValueFn := func(value string) error {
174174
if !regexValue.MatchString(value) {
175175
return fmt.Errorf("label value %q is invalid (should start with lowercase char / lowercase, digit, _ and - chars are allowed / 0-63 characters", value)

test/e2e/tests/single_zone_e2e_test.go

+35
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,41 @@ var _ = Describe("GCE PD CSI Driver", func() {
292292
}()
293293
})
294294

295+
It("Should create and delete disk with labels", func() {
296+
Expect(testContexts).ToNot(BeEmpty())
297+
testContext := getRandomTestContext()
298+
299+
p, z, _ := testContext.Instance.GetIdentity()
300+
client := testContext.Client
301+
302+
// Create Disk
303+
volName := testNamePrefix + string(uuid.NewUUID())
304+
params := map[string]string{
305+
common.ParameterKeyLabels: "key1=value1,key2=value2",
306+
}
307+
volID, err := client.CreateVolume(volName, params, defaultSizeGb, nil)
308+
Expect(err).To(BeNil(), "CreateVolume failed with error: %v", err)
309+
310+
// Validate Disk Created
311+
cloudDisk, err := computeService.Disks.Get(p, z, volName).Do()
312+
Expect(err).To(BeNil(), "Could not get disk from cloud directly")
313+
Expect(cloudDisk.Type).To(ContainSubstring(standardDiskType))
314+
Expect(cloudDisk.Status).To(Equal(readyState))
315+
Expect(cloudDisk.SizeGb).To(Equal(defaultSizeGb))
316+
Expect(cloudDisk.Labels).To(Equal(map[string]string{"key1": "value1", "key2": "value2"}))
317+
Expect(cloudDisk.Name).To(Equal(volName))
318+
319+
defer func() {
320+
// Delete Disk
321+
client.DeleteVolume(volID)
322+
Expect(err).To(BeNil(), "DeleteVolume failed")
323+
324+
// Validate Disk Deleted
325+
_, err = computeService.Disks.Get(p, z, volName).Do()
326+
Expect(gce.IsGCEError(err, "notFound")).To(BeTrue(), "Expected disk to not be found")
327+
}()
328+
})
329+
295330
// Test volume already exists idempotency
296331

297332
// Test volume with op pending

test/k8s-integration/config/sc-standard.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ metadata:
55
provisioner: pd.csi.storage.gke.io
66
parameters:
77
type: pd-standard
8+
labels: key1=value1,key2=value2
89
volumeBindingMode: WaitForFirstConsumer

0 commit comments

Comments
 (0)