Refactor CSI Translation Library into a struct that is injected into various components to simplify unit testing in future

This commit is contained in:
David Zhu
2019-09-12 17:59:06 -07:00
parent 67d928acdc
commit 92cb06a2e7
20 changed files with 168 additions and 94 deletions

View File

@@ -521,6 +521,12 @@ func wrapTestWithProvisionCalls(expectedProvisionCalls []provisionCall, toWrap t
return wrapTestWithPluginCalls(nil, nil, expectedProvisionCalls, toWrap)
}
type fakeCSINameTranslator struct{}
func (t fakeCSINameTranslator) GetCSINameFromInTreeName(pluginName string) (string, error) {
return "vendor.com/MockCSIPlugin", nil
}
// wrapTestWithCSIMigrationProvisionCalls returns a testCall that:
// - configures controller with a volume plugin that emulates CSI migration
// - calls given testCall
@@ -530,9 +536,7 @@ func wrapTestWithCSIMigrationProvisionCalls(toWrap testCall) testCall {
isMigratedToCSI: true,
}
ctrl.volumePluginMgr.InitPlugins([]vol.VolumePlugin{plugin}, nil /* prober */, ctrl)
ctrl.csiNameFromIntreeNameHook = func(string) (string, error) {
return "vendor.com/MockCSIPlugin", nil
}
ctrl.translator = fakeCSINameTranslator{}
return toWrap(ctrl, reactor, test)
}
}