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
2 changes: 1 addition & 1 deletion .github/workflows/deploy_module_on_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
$tag = $env:RELEASE_TAG
write-host -message "Release [$env:RELEASE_NAME] on tag [$tag]"
} else {
# Read Tag o Branch name
# Read Tag or Branch name
$tag = $env:EVENT_REF.Split('/')[2]
write-host "workflow_dispatch triggered on ref leaf [$tag]"
}
Expand Down
26 changes: 24 additions & 2 deletions TestingHelperTest/public/New-ModuleV3.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function TestingHelperTest_NewModuleV3_WithName_RemotePath {
Assert-AddModuleV3 -Path $expectedPath
}

function TestingHelperTest_NewModuleV3_WithOutName {
function TestingHelperTest_NewModuleV3_WithOutName_LocalPath {

# Error as the name is mandatory

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

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

function TestingHelperTest_NewModuleV3_WithOutName_withPath {

$folder = New-TestingFolder -Name "ModulefolderName" -PassThru
$finalFolder = $folder.FullName | Join-Path -ChildPath "ModulefolderName"

$result = New-TT_ModuleV3 -Path $folder @ErrorParameters

Assert-AreEqualPath -Expected $finalFolder -Presented $result
Assert-AddModuleV3 -Path $finalFolder
}

function TestingHelperTest_NewModuleV3_WithOutName_WithPath_AddAll {

$folder = New-TestingFolder -Name "ModulefolderName" -PassThru
$finalFolder = $folder.FullName | Join-Path -ChildPath "ModulefolderName"

$result = New-TT_ModuleV3 -Path $folder -AddAll @ErrorParameters

Assert-AreEqualPath -Expected $finalFolder -Presented $result
Assert-AddAll -Path $folder

}
function TestingHelperTest_NewModuleV3_AddTesting{

$moduleName = "MyModule"
Expand Down
3 changes: 3 additions & 0 deletions private/Add-ToModule.Helper.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ function ReturnValue($Path,$Force, $Passthru){
}

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

Expand Down
2 changes: 2 additions & 0 deletions private/Git.Dependency.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ $GITLASTERROR = $null
# Reset git configuration
function Reset-GitRepoConfiguration {
[CmdletBinding(SupportsShouldProcess)]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Scope='Function')]
param(
[Parameter(Position=0,ValueFromPipeline,ValueFromPipelineByPropertyName)]
[Alias("PSPath")][ValidateNotNullOrEmpty()]
Expand Down Expand Up @@ -58,6 +59,7 @@ function script:Invoke-GitRepositoryInit{
# check if git is installed
$gitPath = Get-Command -Name git -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Source
if(!$gitPath){
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUserDeclaredVarsMoreThanAssignments', '', Scope='Function')]
$GITLASTERROR = "Git is not installed"
return $null
}
Expand Down
4 changes: 2 additions & 2 deletions public/Add-ToModule.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ function Add-ToModuleSampleCode{
$modulePath = NormalizePath -Path:$Path ?? return $null

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

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

return ReturnValue -Path $Path -Force:$Force -Passthru:$Passthru
}
Expand Down
6 changes: 6 additions & 0 deletions public/Invoke-TestingHelper.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ function Invoke-TestingHelper {

process {

if([string]::IsNullOrWhiteSpace($Path)) {
$Path = '.'
}

"Inovking Testing Helper on path [$Path]" | Write-Verbose

$manifest = Get-ModuleManifest -Path ($Path | Convert-Path)
$testingmodulemanifest = Get-TestingModuleManifest -ModulePath $manifest.Path
$versionString = "{0} {1} {2}" -f $manifest.Name, $manifest.ModuleVersion, $manifest.PrivateData.PSData.Prerelease
Expand Down
9 changes: 7 additions & 2 deletions public/New-ModuleV3.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,15 @@ function New-ModuleV3 {
# Add deploy workflow
[Parameter()][switch]$AddDeployWorkflow
)
# check that Name and Path are not both empty
if(!$Name -and !$Path){
Write-Error "Name and Path cannot be both empty"
return $null
}

$retModulePath = $null

$modulePath = Get-ModulePath -RootPath $Path -Name $Name
$modulePath = Get-ModulePath -RootPath $Path -Name $Name
$moduleName = Get-ModuleName -Path $modulePath

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

# If asked for testing add sample code on both modules
$AddSampleCode = $AddSampleCode -or $AddTesting
$AddSampleCode = $AddSampleCode -or $AddTesting -or $AddAll

# Create the module
if ($moduleName) {
Expand Down
4 changes: 2 additions & 2 deletions test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Import-TestingHelper -AllowPrerelease
# Test-ModulelocalPSD1 -ShowTestErrors:$ShowTestErrors -TestName StagingModuleTest_*

if($TestName){
Test-ModulelocalPSD1 -ShowTestErrors:$ShowTestErrors -TestName $TestName
Invoke-TestingHelper -TestName $TestName
} else {
Test-ModulelocalPSD1 -ShowTestErrors:$ShowTestErrors
Invoke-TestingHelper

Check notice

Code scanning / PSScriptAnalyzer

Line has trailing whitespace

Line has trailing whitespace
}