DscResource.Tests icon indicating copy to clipboard operation
DscResource.Tests copied to clipboard

Modules not able to run when there are multiple modules on the machine

Open mbreakey3 opened this issue 9 years ago • 3 comments

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

mbreakey3 avatar May 03 '16 23:05 mbreakey3

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

PlagueHO avatar May 04 '16 00:05 PlagueHO

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 avatar May 04 '16 18:05 KarolKaczmarek

@KarolKaczmarek - now that would be an even better idea! :smile:

PlagueHO avatar May 04 '16 21:05 PlagueHO