Skip to content

Commit

Permalink
test: add unit tests for pv/pvc metadata check
Browse files Browse the repository at this point in the history
  • Loading branch information
andyzhangx committed Jun 19, 2022
1 parent 45e7f52 commit 678a877
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
19 changes: 19 additions & 0 deletions pkg/smb/controllerserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,25 @@ func TestNewSMBVolume(t *testing.T) {
uuid: "pv-name",
},
},
{
desc: "subDir with pv/pvc metadata is specified",
name: "pv-name",
size: 100,
params: map[string]string{
"source": "//smb-server.default.svc.cluster.local/share",
"subDir": fmt.Sprintf("subdir-%s-%s-%s", pvcNameMetadata, pvcNamespaceMetadata, pvNameMetadata),
pvcNameKey: "pvcname",
pvcNamespaceKey: "pvcnamespace",
pvNameKey: "pvname",
},
expectVol: &smbVolume{
id: "smb-server.default.svc.cluster.local/share#subdir-pvcname-pvcnamespace-pvname#pv-name",
source: "//smb-server.default.svc.cluster.local/share",
subDir: "subdir-pvcname-pvcnamespace-pvname",
size: 100,
uuid: "pv-name",
},
},
{
desc: "subDir not specified",
name: "pv-name",
Expand Down
17 changes: 17 additions & 0 deletions pkg/smb/nodeserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ func TestNodeStageVolume(t *testing.T) {
volContext := map[string]string{
sourceField: "test_source",
}
volContextWithMetadata := map[string]string{
sourceField: "test_source",
pvcNameKey: "pvcname",
pvcNamespaceKey: "pvcnamespace",
pvNameKey: "pvname",
}
secrets := map[string]string{
usernameField: "test_username",
passwordField: "test_password",
Expand Down Expand Up @@ -167,6 +173,17 @@ func TestNodeStageVolume(t *testing.T) {
sourceTest),
expectedErr: testutil.TestError{},
},
{
desc: "[Success] Valid request with pv/pvc metdata",
req: csi.NodeStageVolumeRequest{VolumeId: "vol_1##", StagingTargetPath: sourceTest,
VolumeCapability: &stdVolCap,
VolumeContext: volContextWithMetadata,
Secrets: secrets},
flakyWindowsErrorMessage: fmt.Sprintf("volume(vol_1##) mount \"test_source\" on %#v failed with "+
"smb mapping failed with error: rpc error: code = Unknown desc = NewSmbGlobalMapping failed.",
sourceTest),
expectedErr: testutil.TestError{},
},
}

// Setup
Expand Down

0 comments on commit 678a877

Please sign in to comment.