Skip to content

Commit b481a50

Browse files
committed
test: add unit tests for pv/pvc metadata check
fix
1 parent 45e7f52 commit b481a50

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

pkg/smb/controllerserver_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,25 @@ func TestNewSMBVolume(t *testing.T) {
612612
uuid: "pv-name",
613613
},
614614
},
615+
{
616+
desc: "subDir with pv/pvc metadata is specified",
617+
name: "pv-name",
618+
size: 100,
619+
params: map[string]string{
620+
"source": "//smb-server.default.svc.cluster.local/share",
621+
"subDir": fmt.Sprintf("subdir-%s-%s-%s", pvcNameMetadata, pvcNamespaceMetadata, pvNameMetadata),
622+
pvcNameKey: "pvcname",
623+
pvcNamespaceKey: "pvcnamespace",
624+
pvNameKey: "pvname",
625+
},
626+
expectVol: &smbVolume{
627+
id: "smb-server.default.svc.cluster.local/share#subdir-pvcname-pvcnamespace-pvname#pv-name",
628+
source: "//smb-server.default.svc.cluster.local/share",
629+
subDir: "subdir-pvcname-pvcnamespace-pvname",
630+
size: 100,
631+
uuid: "pv-name",
632+
},
633+
},
615634
{
616635
desc: "subDir not specified",
617636
name: "pv-name",

pkg/smb/nodeserver_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ func TestNodeStageVolume(t *testing.T) {
6363
volContext := map[string]string{
6464
sourceField: "test_source",
6565
}
66+
volContextWithMetadata := map[string]string{
67+
sourceField: "test_source",
68+
pvcNameKey: "pvcname",
69+
pvcNamespaceKey: "pvcnamespace",
70+
pvNameKey: "pvname",
71+
}
6672
secrets := map[string]string{
6773
usernameField: "test_username",
6874
passwordField: "test_password",
@@ -167,6 +173,17 @@ func TestNodeStageVolume(t *testing.T) {
167173
sourceTest),
168174
expectedErr: testutil.TestError{},
169175
},
176+
{
177+
desc: "[Success] Valid request with pv/pvc metadata",
178+
req: csi.NodeStageVolumeRequest{VolumeId: "vol_1##", StagingTargetPath: sourceTest,
179+
VolumeCapability: &stdVolCap,
180+
VolumeContext: volContextWithMetadata,
181+
Secrets: secrets},
182+
flakyWindowsErrorMessage: fmt.Sprintf("volume(vol_1##) mount \"test_source\" on %#v failed with "+
183+
"smb mapping failed with error: rpc error: code = Unknown desc = NewSmbGlobalMapping failed.",
184+
sourceTest),
185+
expectedErr: testutil.TestError{},
186+
},
170187
}
171188

172189
// Setup

0 commit comments

Comments
 (0)