PowerShell / DscResource.Tests

Common meta tests for PowerShell DSC resources repositories.
MIT License
51 stars 49 forks source link

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

Open mbreakey3 opened 8 years ago

mbreakey3 commented 8 years ago

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

PlagueHO commented 8 years ago

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
KarolKaczmarek commented 8 years ago

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.

PlagueHO commented 8 years ago

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