Skip to content

Commit

Permalink
Merge pull request #76 from webmd-health-services/hotfix/remove-carbo…
Browse files Browse the repository at this point in the history
…n-force

2.9.1
  • Loading branch information
splatteredbits authored Nov 1, 2019
2 parents b5dc5c5 + 8040468 commit 7d8695a
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 31 deletions.
14 changes: 2 additions & 12 deletions Carbon/Carbon.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
RootModule = 'Carbon.psm1'

# Version number of this module.
ModuleVersion = '2.9.0'
ModuleVersion = '2.9.1'

# ID used to uniquely identify this module
GUID = '075d9444-c01b-48c3-889a-0b3490716fa2'
Expand Down Expand Up @@ -349,17 +349,7 @@ All functions are idempotent: when run multiple times with the same arguments, y

# ReleaseNotes of this module
ReleaseNotes = @'
* Carbon should now import in less than a second.
* Fixed: `Grant-CHttpUrlPermission` documentation uses command named `Grant-CHttpUrlAclPermission`. (Fixes [issue 66](https://github.com/webmd-health-services/Carbon/issues/66).)
* Fixed: `Enable-CNtfsCompression` always enables compression even if compression is already enabled.
* Fixed: `Disable-CNtfsCompression` always disables compression even if compression is already disabled.
* Fixed: `Uninstall-CService` can write an error when a service's process exits at unexpected times.
* Fixed: `Get-CUser` can sometimes take 60 to 90 seconds to lookup a specific user.
* Fixed: `Get-CGroup` can sometimes take 60 to 90 seconds to lookup a specific group.
* Improved `Set-CEnvironmentVariable` and `Remove-CEnvironmentVariable` functions' reliability when setting and removing variables for a specific user (they now use `Start-Job` instead of Carbon's `Invoke-CPowerShell`).
* Fixed: Carbon was hiding the ServerManager module's `Get-WindowsFeature`, `Install-WindowsFeature`, and `Uninstall-WindowsFeature` cmdlets (fixes issue #55).
* Fixed: `Set-CHostsEntry` can sometimes clear the hosts file (fixes issue #39).
* Fixed: `Get-CServiceConfiguration` fails with a terminating exception if a service doesn't exist.
* Fixed: `Import-Carbon.ps1` fails if Carbon is already imported from a different location than the location from which it will import Carbon.
'@
} # End of PSData hashtable

Expand Down
9 changes: 7 additions & 2 deletions Carbon/Import-Carbon.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,14 @@ $carbonPsd1Path = Join-Path -Path $PSScriptRoot -ChildPath 'Carbon.psd1' -Resolv

try
{
if( $Force -and (Get-Module -Name 'Carbon') )
$module = Get-Module -Name 'Carbon'
if( $module )
{
Remove-Module -Name 'Carbon' -Force
$expectedPath = Join-Path -Path $PSScriptRoot -ChildPath 'Carbon.psm1'
if( $Force -or $module.Path -ne $expectedPath )
{
Remove-Module -Name 'Carbon' -Force
}
}

$optionalParams = @{ }
Expand Down
71 changes: 54 additions & 17 deletions Test/Import-Carbon.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,37 @@

$importCarbonPath = Join-Path -Path $PSScriptRoot -ChildPath '..\Carbon\Import-Carbon.ps1' -Resolve

Describe 'Import-Carbon' {

BeforeEach {
$Global:Error.Clear()
if( (Get-Module 'Carbon') )
{
Remove-Module 'Carbon' -Force
}
function Init
{
$Global:Error.Clear()
if( (Get-Module 'Carbon') )
{
Remove-Module 'Carbon' -Force
}

AfterEach {
if( (Get-Module 'Carbon') )
{
Remove-Module 'Carbon' -Force
}
}

function Reset
{
if( (Get-Module 'Carbon') )
{
Remove-Module 'Carbon' -Force
}
}

Describe 'Import-Carbon' {

BeforeEach { Init }
AfterEach { Reset }

It 'should import' {
& $importCarbonPath
(Get-Command -Module 'Carbon') | Should Not BeNullOrEmpty
(Get-Command -Module 'Carbon') | Should -Not -BeNullOrEmpty
}

It 'should import with prefix' {
& $importCarbonPath -Prefix 'C'
$carbonCmds = Get-Command -Module 'Carbon'
$carbonCmds | Should Not BeNullOrEmpty
$carbonCmds | Should -Not -BeNullOrEmpty
foreach( $cmd in $carbonCmds )
{
$cmd.Name | Should -Match '^.+-C.+$'
Expand All @@ -62,7 +67,7 @@ Describe 'Import-Carbon' {
try
{
& $importCarbonPath
$Global:Error.Count | Should Be 0
$Global:Error.Count | Should -Be 0
}
finally
{
Expand Down Expand Up @@ -107,3 +112,35 @@ Describe 'Import-Carbon' {
Should -BeLessOrEqual $maxAvgDuration
}
}

Describe 'Import-CarbonPs1.when importing multiple times from different locations' {
AfterEach { Reset }
It 'should import without errors' {
Init
$Global:Error.Clear()
$otherCarbonModulesRoot = Join-Path -Path $TestDrive.FullName -ChildPath ([IO.Path]::GetRandomFileName())
New-Item -Path $otherCarbonModulesRoot -ItemType 'Directory'
Copy-Item -Path ($importCarbonPath | Split-Path -Parent) -Destination $otherCarbonModulesRoot -Recurse

$otherCarbonRoot = Join-Path -Path $otherCarbonModulesRoot -ChildPath 'Carbon'
$otherCarbonRoot | Should -Exist
Import-Module -Name $otherCarbonRoot
& $importCarbonPath
(Get-Command -Module 'Carbon') | Should -Not -BeNullOrEmpty
$Global:Error | Should -BeNullOrEmpty
}
}

Describe 'Import-CarbonPs1.when importing multiple times from same location' {
AfterEach { Reset }
It 'should not remove or import' {
Init
$Global:Error.Clear()
& $importCarbonPath
Mock -CommandName 'Import-Module'
Mock -CommandName 'Remove-Module'
& $importCarbonPath
Assert-MockCalled -CommandName 'Remove-Module' -Times 0
Assert-MockCalled -CommandName 'Import-Module' -Times 1
}
}

0 comments on commit 7d8695a

Please sign in to comment.