Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions TestingHelperTest/public/New-ModuleV3-Add-ModuleV3.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,30 @@ function TestingHelperTest_NewModuleV3_AddModule_FailCall_NewModuleManifest {

}

function TestingHelperTest_NewModuleV3_AddModule_FolderExists {

$moduleName = "MyModule"

New-TestingFolder -Name $moduleName

$result = Add-TT_ModuleV3 -Name $moduleName

Assert-AddModuleV3 -Path $result
}


function TestingHelperTest_NewModuleV3_AddModule_ModuleExistInFolder {

$moduleName = "MyModule"

$result = Add-TT_ModuleV3 -Name $moduleName

$result = Add-TT_ModuleV3 -Name $moduleName @ErrorParameters

Assert-IsNull -Object $result
Assert-Contains -Expected "Module already exists." -Presented ($errorVar.Exception.Message)
}

function TestingHelperTest_NewModuleV3_AddModule_DefaultManifest {

$moduleName = "MyModule"
Expand Down
21 changes: 13 additions & 8 deletions private/New-ModuleV3.Helper.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function Get-TestModuleName {
return $name
}

function New-Folder{
function New-ModuleFolder{
[CmdletBinding(SupportsShouldProcess)]
param(
[Parameter(Mandatory,ValueFromPipeline)][string]$Path
Expand All @@ -71,23 +71,28 @@ function New-Folder{

try {
#test if path exists
if($Path | Test-Path){
Write-Error "Path already exists."
return $null
} else {
if(!($Path | Test-Path)){
if ($PSCmdlet.ShouldProcess($Path, "New-Item -ItemType Directory")) {
$null = New-Item -ItemType Directory -Path $Path
}

# Converting to Provider path
return $Path | Convert-Path
}
}

# Folder exists. Check if the psd1 file exists
$psd1Path = ($Path | Join-Path -ChildPath "$($Path | Split-Path -LeafBase).psd1")
if($psd1Path | Test-Path){
Write-Error -Message "Module already exists."
return $null
}

return $Path | Convert-Path

}
catch {
Write-Error -Message "Failed to add path."
return $null
}
}

}

2 changes: 1 addition & 1 deletion public/Add-ModuleV3.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function Add-ModuleV3 {

# Create the module folder. Fail if exists
# This will filter if Path already exist to avoid overwriting an existing module
$modulePath = $modulePathString | New-Folder
$modulePath = $modulePathString | New-ModuleFolder
if( !$modulePath ){ return $null }

$moduleName = Get-ModuleName -Path $modulePath
Expand Down