Skip to content

Commit 6c9f80d

Browse files
authored
Merge pull request #103 from rulasg:96-small-bugs-and-improvements
TestingHelper - 96 small bugs and improvements
2 parents 786abbc + dba891a commit 6c9f80d

8 files changed

Lines changed: 47 additions & 9 deletions

File tree

.github/workflows/deploy_module_on_release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
$tag = $env:RELEASE_TAG
3535
write-host -message "Release [$env:RELEASE_NAME] on tag [$tag]"
3636
} else {
37-
# Read Tag o Branch name
37+
# Read Tag or Branch name
3838
$tag = $env:EVENT_REF.Split('/')[2]
3939
write-host "workflow_dispatch triggered on ref leaf [$tag]"
4040
}

TestingHelperTest/public/New-ModuleV3.Tests.ps1

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function TestingHelperTest_NewModuleV3_WithName_RemotePath {
3030
Assert-AddModuleV3 -Path $expectedPath
3131
}
3232

33-
function TestingHelperTest_NewModuleV3_WithOutName {
33+
function TestingHelperTest_NewModuleV3_WithOutName_LocalPath {
3434

3535
# Error as the name is mandatory
3636

@@ -40,9 +40,31 @@ function TestingHelperTest_NewModuleV3_WithOutName {
4040
$result = New-TT_ModuleV3 @ErrorParameters
4141

4242
Assert-IsNull -Object $result
43-
Assert-Contains -Expected "Path and Name cannot be null or empty at the same time." -Presented $errorVar.Exception.Message
43+
Assert-Contains -Expected "Name and Path cannot be both empty" -Presented $errorVar.Exception.Message
4444
}
4545

46+
function TestingHelperTest_NewModuleV3_WithOutName_withPath {
47+
48+
$folder = New-TestingFolder -Name "ModulefolderName" -PassThru
49+
$finalFolder = $folder.FullName | Join-Path -ChildPath "ModulefolderName"
50+
51+
$result = New-TT_ModuleV3 -Path $folder @ErrorParameters
52+
53+
Assert-AreEqualPath -Expected $finalFolder -Presented $result
54+
Assert-AddModuleV3 -Path $finalFolder
55+
}
56+
57+
function TestingHelperTest_NewModuleV3_WithOutName_WithPath_AddAll {
58+
59+
$folder = New-TestingFolder -Name "ModulefolderName" -PassThru
60+
$finalFolder = $folder.FullName | Join-Path -ChildPath "ModulefolderName"
61+
62+
$result = New-TT_ModuleV3 -Path $folder -AddAll @ErrorParameters
63+
64+
Assert-AreEqualPath -Expected $finalFolder -Presented $result
65+
Assert-AddAll -Path $folder
66+
67+
}
4668
function TestingHelperTest_NewModuleV3_AddTesting{
4769

4870
$moduleName = "MyModule"

private/Add-ToModule.Helper.ps1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ function ReturnValue($Path,$Force, $Passthru){
1313
}
1414

1515
# Normalize $Path and returns $null if not valid
16+
# If $Path is a file, returns the parent folder
17+
# If $Path is $null or empty, returns the current folder
18+
# Path needs to be a valid path
1619
function NormalizePath($Path){
1720
# Path returned should be the folder where the module is located.
1821

private/Git.Dependency.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ $GITLASTERROR = $null
77
# Reset git configuration
88
function Reset-GitRepoConfiguration {
99
[CmdletBinding(SupportsShouldProcess)]
10+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Scope='Function')]
1011
param(
1112
[Parameter(Position=0,ValueFromPipeline,ValueFromPipelineByPropertyName)]
1213
[Alias("PSPath")][ValidateNotNullOrEmpty()]
@@ -58,6 +59,7 @@ function script:Invoke-GitRepositoryInit{
5859
# check if git is installed
5960
$gitPath = Get-Command -Name git -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Source
6061
if(!$gitPath){
62+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUserDeclaredVarsMoreThanAssignments', '', Scope='Function')]
6163
$GITLASTERROR = "Git is not installed"
6264
return $null
6365
}

public/Add-ToModule.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ function Add-ToModuleSampleCode{
2323
$modulePath = NormalizePath -Path:$Path ?? return $null
2424

2525
$destination = $modulePath | Join-Path -ChildPath "public"
26-
Import-Template -Path $destination -File "samplePublicFunction.ps1" -Template "template.module.functions.public.ps1"
26+
$null = Import-Template -Path $destination -File "samplePublicFunction.ps1" -Template "template.module.functions.public.ps1"
2727

2828
$destination = $modulePath | Join-Path -ChildPath "private"
29-
Import-Template -Path $destination -File "samplePrivateFunction.ps1" -Template "template.module.functions.private.ps1"
29+
$null = Import-Template -Path $destination -File "samplePrivateFunction.ps1" -Template "template.module.functions.private.ps1"
3030

3131
return ReturnValue -Path $Path -Force:$Force -Passthru:$Passthru
3232
}

public/Invoke-TestingHelper.ps1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ function Invoke-TestingHelper {
8181

8282
process {
8383

84+
if([string]::IsNullOrWhiteSpace($Path)) {
85+
$Path = '.'
86+
}
87+
88+
"Inovking Testing Helper on path [$Path]" | Write-Verbose
89+
8490
$manifest = Get-ModuleManifest -Path ($Path | Convert-Path)
8591
$testingmodulemanifest = Get-TestingModuleManifest -ModulePath $manifest.Path
8692
$versionString = "{0} {1} {2}" -f $manifest.Name, $manifest.ModuleVersion, $manifest.PrivateData.PSData.Prerelease

public/New-ModuleV3.ps1

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,15 @@ function New-ModuleV3 {
6464
# Add deploy workflow
6565
[Parameter()][switch]$AddDeployWorkflow
6666
)
67+
# check that Name and Path are not both empty
68+
if(!$Name -and !$Path){
69+
Write-Error "Name and Path cannot be both empty"
70+
return $null
71+
}
6772

6873
$retModulePath = $null
6974

70-
$modulePath = Get-ModulePath -RootPath $Path -Name $Name
75+
$modulePath = Get-ModulePath -RootPath $Path -Name $Name
7176
$moduleName = Get-ModuleName -Path $modulePath
7277

7378
# check $modulePath and return if null
@@ -76,7 +81,7 @@ function New-ModuleV3 {
7681
}
7782

7883
# If asked for testing add sample code on both modules
79-
$AddSampleCode = $AddSampleCode -or $AddTesting
84+
$AddSampleCode = $AddSampleCode -or $AddTesting -or $AddAll
8085

8186
# Create the module
8287
if ($moduleName) {

test.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ Import-TestingHelper -AllowPrerelease
7171
# Test-ModulelocalPSD1 -ShowTestErrors:$ShowTestErrors -TestName StagingModuleTest_*
7272

7373
if($TestName){
74-
Test-ModulelocalPSD1 -ShowTestErrors:$ShowTestErrors -TestName $TestName
74+
Invoke-TestingHelper -TestName $TestName
7575
} else {
76-
Test-ModulelocalPSD1 -ShowTestErrors:$ShowTestErrors
76+
Invoke-TestingHelper
7777
}

0 commit comments

Comments
 (0)