Adds method CanAttach() to check plugin attachability

This commit is contained in:
Vladimir Vivien
2018-10-19 15:07:33 -04:00
parent 5b6a23f3af
commit 0a653b3b80
17 changed files with 128 additions and 21 deletions

View File

@@ -375,6 +375,36 @@ func TestPluginNewDetacher(t *testing.T) {
}
}
func TestPluginCanAttach(t *testing.T) {
tests := []struct {
name string
driverName string
canAttach bool
}{
{
name: "attachable",
driverName: "attachble-driver",
canAttach: true,
},
}
for _, test := range tests {
csiDriver := getCSIDriver(test.driverName, nil, &test.canAttach)
t.Run(test.name, func(t *testing.T) {
fakeCSIClient := fakecsi.NewSimpleClientset(csiDriver)
plug, tmpDir := newTestPlugin(t, nil, fakeCSIClient)
defer os.RemoveAll(tmpDir)
spec := volume.NewSpecFromPersistentVolume(makeTestPV("test-pv", 10, test.driverName, "test-vol"), false)
pluginCanAttach := plug.CanAttach(spec)
if pluginCanAttach != test.canAttach {
t.Fatalf("expecting plugin.CanAttach %t got %t", test.canAttach, pluginCanAttach)
return
}
})
}
}
func TestPluginNewBlockMapper(t *testing.T) {
defer utilfeaturetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.CSIBlockVolume, true)()