DscResource.Tests
DscResource.Tests copied to clipboard
Modules not able to run when there are multiple modules on the machine
When the same module is on the machine in multiple places some of the integration tests fail due to how we are currently setting up the test environment. This is fixed by ensuring only one copy of a module is on the machine, but we should have a better way of handling this scenario.
see: https://github.com/PowerShell/DscResource.Tests/blob/master/TestHelper.psm1#L280
Yes, I've run into the problem many times before.
One solution might be to ensure the Module version number of the Module being tested was issued to the Import-Module cmdlet. For the integration tests you'd need the Import-DSCResource to also do this:
$ManifestPath = ...whereever the manifest is...
$ManifestContent = Get-Content -Path $ManifestPath -Raw
$Regex = '(?<=ModuleVersion\s+=\s+'')(?<ModuleVersion>.*)(?='')'
$Matches = @([regex]::matches($ManifestContent, $Regex, 'IgnoreCase'))
$version = $null
if (-not $Matches)
{
Throw "ModuleVersion could not be found in Module Manifest '$ManifestPath'"
}
$version = $Matches[0].Value
$Module = @{
ModuleName="xActiveDirectory"
ModuleVersion=$version
}
Import-DSCResource -Module $Module
We could have same version of the same module deployed in multiple places though, so that wouldn't work in that case. We can specify the full path to the module when importing it.
@KarolKaczmarek - now that would be an even better idea! :smile: