zowe-cli icon indicating copy to clipboard operation
zowe-cli copied to clipboard

[v2] Command handler unit tests require a lot of mocks

Open t1m0thyj opened this issue 3 years ago • 1 comments

In a unit test that calls ICommandHandler.process and mocks an ImperativeConfig.instance.config object with the exists: true property defined, several mocks are required which may be an inconvenience for plug-in developers.

For an example, see this sample plug-in unit test: https://github.com/zowe/zowe-cli-sample-plugin/commit/a6b6d22ea06dcdc313e3ca5a341d0769e7e5301b#diff-c5dfd517fddad71ab1fe78c762be9a365f981aa118a4b3a72427717d679d634c

The following functions require mocks to be defined on the ImperativeConfig instance:

  • LoggerUtils.censorRawData - envVariablePrefix, config.api.layers.get, config.api.secure.secureFields
  • ConfigAutoStore.findActiveProfile - loadedConfig.profiles

t1m0thyj avatar Jan 18 '22 15:01 t1m0thyj

After a short discussion, we wanted to reduce code duplication. This might be a good enhancement for the cli-test-utils package. We could add a few clever ways to mock these methods 😋 (not a good first issue 😅 )

zFernand0 avatar Nov 17 '23 18:11 zFernand0