diff --git a/.vscode/tasks.json b/.vscode/tasks.json index f6898a9..c4d0e9e 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -158,7 +158,10 @@ "echo": false, "showReuseMessage": false }, - "group": "test" + "group": { + "kind": "test", + "isDefault": true + } }, { "label": "DevCC", diff --git a/actions_bootstrap.ps1 b/actions_bootstrap.ps1 index c21013c..ab0f6e0 100644 --- a/actions_bootstrap.ps1 +++ b/actions_bootstrap.ps1 @@ -16,12 +16,12 @@ $modulesToInstall = New-Object System.Collections.Generic.List[object] # https://github.com/pester/Pester [void]$modulesToInstall.Add(([PSCustomObject]@{ ModuleName = 'Pester' - ModuleVersion = '5.5.0' + ModuleVersion = '5.6.1' })) # https://github.com/nightroman/Invoke-Build [void]$modulesToInstall.Add(([PSCustomObject]@{ ModuleName = 'InvokeBuild' - ModuleVersion = '5.11.1' + ModuleVersion = '5.11.3' })) # https://github.com/PowerShell/PSScriptAnalyzer [void]$modulesToInstall.Add(([PSCustomObject]@{ @@ -46,7 +46,14 @@ foreach ($module in $modulesToInstall) { ErrorAction = 'Stop' } try { - Install-Module @installSplat + if ($module.ModuleName -eq 'Pester' -and $IsWindows) { + # special case for Pester certificate mismatch with older Pester versions - https://github.com/pester/Pester/issues/2389 + # this only affects windows builds + Install-Module @installSplat -SkipPublisherCheck + } + else { + Install-Module @installSplat + } Import-Module -Name $module.ModuleName -ErrorAction Stop ' - Successfully installed {0}' -f $module.ModuleName } diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 34af53b..3ae30e2 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -5,6 +5,28 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [2.20.0] + +- Catesta template module changes + - CI/CD Changes: + - Adjusted all action bootstrap for module installs to include a `SkipPublisherCheck` when installing Pester module on Windows builds. (https://github.com/pester/Pester/issues/2389) + - Pester bumped from `5.5.0` to `5.6.1` + - InvokeBuild bumped from `5.11.1` to `5.11.3` + - **New template question**: Catesta now asks if PowerShell Classes will be used in the module project. If `Yes` is specified a Classes structure will be scaffold. + - Sample pester tests for Pester v5 refactored to follow Pester 5 rules + - Refactored `ExportedFunctions.Tests.ps1` for better efficiency in loops + - Minor spelling correction in sample Pester tests + - `tasks.json` + - `Test` task is now explicitly set as default test task +- Catesta primary module changes + - `tasks.json` + - `Test` task is now explicitly set as default test task + - Pester bumped from `5.5.0` to `5.6.1` + - InvokeBuild bumped from `5.11.1` to `5.11.3` + - Adjusted action bootstrap for module installs to include a `SkipPublisherCheck` when installing Pester module on Windows builds. (https://github.com/pester/Pester/issues/2389) + - Refactored all unit and infra tests to adhere to Pester 5 rules + - Refactored `ExportedFunctions.Tests.ps1` for better efficiency in loops + ## [2.12.0] - Catesta template module changes diff --git a/docs/Catesta-Basics.md b/docs/Catesta-Basics.md index c7efb84..4346cb6 100644 --- a/docs/Catesta-Basics.md +++ b/docs/Catesta-Basics.md @@ -33,6 +33,9 @@ New-VaultProject -DestinationPath $outPutPath * **Enter a description for the module:** *Description of what your module does* * **Enter the version number of the module (0.0.1)**: *Starting version #* * **Enter your full name**: *Module author name* +* **Will you use classes in your module?** + * [N] No + * [Y] Yes * **Which CICD tool will you use to build and deploy your project?**: *Choose CI/CD tool for automated project build and deployment.* * [M] Module Only * [G] GitHub Actions diff --git a/docs/Catesta-ModuleSchema.md b/docs/Catesta-ModuleSchema.md index ec011c2..84432a0 100644 --- a/docs/Catesta-ModuleSchema.md +++ b/docs/Catesta-ModuleSchema.md @@ -31,6 +31,14 @@ name : FN type : user-fullname default : +name : psClasses +type : choice +choices: + value : No + help : Classes will not be used in this PowerShell module. + value : Yes + help : Classes will be used in this PowerShell module. + name : CICD type : choice choices: @@ -254,6 +262,7 @@ ModuleName = 'text' Description = 'text' Version = '0.0.1' FN = 'user full name' +psClasses = 'No' CICD = 'GITHUB' GitHubAOptions = 'windows','pwshcore','linux','macos' AWSOptions = 'ps','pwshcore','pwsh' diff --git a/docs/Catesta.md b/docs/Catesta.md index 79518f9..fa08c6f 100644 --- a/docs/Catesta.md +++ b/docs/Catesta.md @@ -2,7 +2,7 @@ Module Name: Catesta Module Guid: 6796b193-9013-468a-b022-837749af2d06 Download Help Link: NA -Help Version: 2.12.0 +Help Version: 2.20.0 Locale: en-US --- diff --git a/src/Catesta.build.ps1 b/src/Catesta.build.ps1 index dd6b1e0..4fe2670 100644 --- a/src/Catesta.build.ps1 +++ b/src/Catesta.build.ps1 @@ -268,10 +268,10 @@ Add-BuildTask Test { if ($env:CI -and $IsMacOS) { # the MacOS github action does not properly detect the relative path. Write-Build White " CI: $env:CI and MacOS action detected. Hard coding path." - $pesterConfiguration.CodeCoverage.Path = "/Users/runner/work/Catesta/Catesta/src/Catesta/*/*.ps1" + $pesterConfiguration.CodeCoverage.Path = "/Users/runner/work/$ModuleName/$ModuleName/src/$ModuleName/*/*.ps1" } else { - $pesterConfiguration.CodeCoverage.Path = "..\..\..\$ModuleName\*\*.ps1" + $pesterConfiguration.CodeCoverage.Path = "..\..\..\src\$ModuleName\*\*.ps1" } $pesterConfiguration.TestResult.Enabled = $true $pesterConfiguration.TestResult.OutputPath = "$testOutPutPath\PesterTests.xml" @@ -472,6 +472,7 @@ Add-BuildTask AssetCopy -Before Build { Copy-Item -Path "$script:ModuleSourcePath\*" -Destination $script:ArtifactsPath -Exclude *.psd1, *.psm1 -Recurse -ErrorAction Stop Copy-Item -Path "$script:ModuleSourcePath\Resources\Module\src\PSScriptAnalyzerSettings.psd1" -Destination "$script:ArtifactsPath\Resources\Module\src\PSScriptAnalyzerSettings.psd1" -ErrorAction Stop Copy-Item -Path "$script:ModuleSourcePath\Resources\Module\src\Module\Module.psm1" -Destination "$script:ArtifactsPath\Resources\Module\src\Module\Module.psm1" -ErrorAction Stop + Copy-Item -Path "$script:ModuleSourcePath\Resources\Module\src\Module\Module_Classes.psm1" -Destination "$script:ArtifactsPath\Resources\Module\src\Module\Module_Classes.psm1" -ErrorAction Stop # Copy-Item -Path "$script:ModuleSourcePath\Resources\Vault\src\PSVault\PSVault.psd1" -Destination "$script:ArtifactsPath\Resources\Vault\src\PSVault\PSVault.psd1" -ErrorAction Stop Copy-Item -Path "$script:ModuleSourcePath\Resources\Vault\src\PSVault\PSVault.psm1" -Destination "$script:ArtifactsPath\Resources\Vault\src\PSVault\PSVault.psm1" -ErrorAction Stop Copy-Item -Path "$script:ModuleSourcePath\Resources\Vault\src\PSVault\PSVault.Extension\PSVault.Extension.psd1" -Destination "$script:ArtifactsPath\Resources\Vault\src\PSVault\PSVault.Extension\PSVault.Extension.psd1" -ErrorAction Stop @@ -526,8 +527,6 @@ Add-BuildTask Build { Write-Build Green ' ...Build Complete!' } #Build -# TODO: schema generator step - #Synopsis: Invokes all Pester Integration Tests in the Tests\Integration folder (if it exists) Add-BuildTask IntegrationTest { if (Test-Path -Path $script:IntegrationTestsPath) { diff --git a/src/Catesta/Catesta.psd1 b/src/Catesta/Catesta.psd1 index cb9a684..e613add 100644 --- a/src/Catesta/Catesta.psd1 +++ b/src/Catesta/Catesta.psd1 @@ -12,7 +12,7 @@ RootModule = 'Catesta.psm1' # Version number of this module. - ModuleVersion = '2.12.0' + ModuleVersion = '2.20.0' # Supported PSEditions # CompatiblePSEditions = @() diff --git a/src/Catesta/Resources/AWS/install_modules.ps1 b/src/Catesta/Resources/AWS/install_modules.ps1 index a09d97b..b49fddb 100644 --- a/src/Catesta/Resources/AWS/install_modules.ps1 +++ b/src/Catesta/Resources/AWS/install_modules.ps1 @@ -59,7 +59,7 @@ elseif ($PLASTER_PARAM_Pester-eq '5') { # https://github.com/pester/Pester [void]$modulesToInstall.Add(([PSCustomObject]@{ ModuleName = 'Pester' - ModuleVersion = '5.5.0' + ModuleVersion = '5.6.1' BucketName = '<%=$PLASTER_PARAM_S3Bucket%>' KeyPrefix = '' })) @@ -68,7 +68,7 @@ elseif ($PLASTER_PARAM_Pester-eq '5') { %> [void]$modulesToInstall.Add(([PSCustomObject]@{ ModuleName = 'InvokeBuild' - ModuleVersion = '5.11.1' + ModuleVersion = '5.11.3' BucketName = '<%=$PLASTER_PARAM_S3Bucket%>' KeyPrefix = '' })) @@ -204,7 +204,14 @@ else { ErrorAction = 'Stop' } try { - Install-Module @installSplat + if ($module.ModuleName -eq 'Pester' -and $IsWindows) { + # special case for Pester certificate mismatch with older Pester versions - https://github.com/pester/Pester/issues/2389 + # this only affects windows builds + Install-Module @installSplat -SkipPublisherCheck + } + else { + Install-Module @installSplat + } Import-Module -Name $module.ModuleName -ErrorAction Stop ' - Successfully installed {0}' -f $module.ModuleName } diff --git a/src/Catesta/Resources/AppVeyor/actions_bootstrap.ps1 b/src/Catesta/Resources/AppVeyor/actions_bootstrap.ps1 index 83bbfb1..2af630a 100644 --- a/src/Catesta/Resources/AppVeyor/actions_bootstrap.ps1 +++ b/src/Catesta/Resources/AppVeyor/actions_bootstrap.ps1 @@ -23,7 +23,7 @@ elseif ($PLASTER_PARAM_Pester-eq '5') { # https://github.com/pester/Pester [void]$modulesToInstall.Add(([PSCustomObject]@{ ModuleName = 'Pester' - ModuleVersion = '5.5.0' + ModuleVersion = '5.6.1' })) '@ } @@ -31,7 +31,7 @@ elseif ($PLASTER_PARAM_Pester-eq '5') { # https://github.com/nightroman/Invoke-Build [void]$modulesToInstall.Add(([PSCustomObject]@{ ModuleName = 'InvokeBuild' - ModuleVersion = '5.11.1' + ModuleVersion = '5.11.3' })) # https://github.com/PowerShell/PSScriptAnalyzer [void]$modulesToInstall.Add(([PSCustomObject]@{ diff --git a/src/Catesta/Resources/Azure/actions_bootstrap.ps1 b/src/Catesta/Resources/Azure/actions_bootstrap.ps1 index 83bbfb1..eaa298a 100644 --- a/src/Catesta/Resources/Azure/actions_bootstrap.ps1 +++ b/src/Catesta/Resources/Azure/actions_bootstrap.ps1 @@ -23,7 +23,7 @@ elseif ($PLASTER_PARAM_Pester-eq '5') { # https://github.com/pester/Pester [void]$modulesToInstall.Add(([PSCustomObject]@{ ModuleName = 'Pester' - ModuleVersion = '5.5.0' + ModuleVersion = '5.6.1' })) '@ } @@ -31,7 +31,7 @@ elseif ($PLASTER_PARAM_Pester-eq '5') { # https://github.com/nightroman/Invoke-Build [void]$modulesToInstall.Add(([PSCustomObject]@{ ModuleName = 'InvokeBuild' - ModuleVersion = '5.11.1' + ModuleVersion = '5.11.3' })) # https://github.com/PowerShell/PSScriptAnalyzer [void]$modulesToInstall.Add(([PSCustomObject]@{ @@ -67,7 +67,14 @@ foreach ($module in $modulesToInstall) { ErrorAction = 'Stop' } try { - Install-Module @installSplat + if ($module.ModuleName -eq 'Pester' -and $IsWindows) { + # special case for Pester certificate mismatch with older Pester versions - https://github.com/pester/Pester/issues/2389 + # this only affects windows builds + Install-Module @installSplat -SkipPublisherCheck + } + else { + Install-Module @installSplat + } Import-Module -Name $module.ModuleName -ErrorAction Stop ' - Successfully installed {0}' -f $module.ModuleName } diff --git a/src/Catesta/Resources/Bitbucket/actions_bootstrap.ps1 b/src/Catesta/Resources/Bitbucket/actions_bootstrap.ps1 index 83bbfb1..eaa298a 100644 --- a/src/Catesta/Resources/Bitbucket/actions_bootstrap.ps1 +++ b/src/Catesta/Resources/Bitbucket/actions_bootstrap.ps1 @@ -23,7 +23,7 @@ elseif ($PLASTER_PARAM_Pester-eq '5') { # https://github.com/pester/Pester [void]$modulesToInstall.Add(([PSCustomObject]@{ ModuleName = 'Pester' - ModuleVersion = '5.5.0' + ModuleVersion = '5.6.1' })) '@ } @@ -31,7 +31,7 @@ elseif ($PLASTER_PARAM_Pester-eq '5') { # https://github.com/nightroman/Invoke-Build [void]$modulesToInstall.Add(([PSCustomObject]@{ ModuleName = 'InvokeBuild' - ModuleVersion = '5.11.1' + ModuleVersion = '5.11.3' })) # https://github.com/PowerShell/PSScriptAnalyzer [void]$modulesToInstall.Add(([PSCustomObject]@{ @@ -67,7 +67,14 @@ foreach ($module in $modulesToInstall) { ErrorAction = 'Stop' } try { - Install-Module @installSplat + if ($module.ModuleName -eq 'Pester' -and $IsWindows) { + # special case for Pester certificate mismatch with older Pester versions - https://github.com/pester/Pester/issues/2389 + # this only affects windows builds + Install-Module @installSplat -SkipPublisherCheck + } + else { + Install-Module @installSplat + } Import-Module -Name $module.ModuleName -ErrorAction Stop ' - Successfully installed {0}' -f $module.ModuleName } diff --git a/src/Catesta/Resources/Editor/VSCode/tasks.json b/src/Catesta/Resources/Editor/VSCode/tasks.json index f5aa4c0..ecef4be 100644 --- a/src/Catesta/Resources/Editor/VSCode/tasks.json +++ b/src/Catesta/Resources/Editor/VSCode/tasks.json @@ -158,7 +158,10 @@ "echo": false, "showReuseMessage": false }, - "group": "test" + "group": { + "kind": "test", + "isDefault": true + } }, { "label": "DevCC", @@ -212,11 +215,12 @@ if ($PLASTER_PARAM_Pester-eq '4') { @' "command": "Import-Module -Name Pester -MaximumVersion 4.99.99;Invoke-Pester '${workspaceFolder}/src/Tests/Unit' -PesterOption @{IncludeVSCodeMarker=$true}", '@ -} + } elseif ($PLASTER_PARAM_Pester-eq '5') { @' "command": "Invoke-Pester '${workspaceFolder}/src/Tests/Unit' -Output Detailed", -'@ } +'@ + } %> "problemMatcher": "$pester", "group": "test" @@ -229,10 +233,11 @@ if ($PLASTER_PARAM_Pester-eq '4') { @' "command": "Import-Module -Name Pester -MaximumVersion 4.99.99;Import-Module -Name '${workspaceFolder}/src/${workspaceFolderBasename}/${workspaceFolderBasename}.psm1';Invoke-Pester '${workspaceFolder}/src/Tests/Unit/*/${input:functionName}.Tests.ps1' -CodeCoverage '${workspaceFolder}/src/${workspaceFolderBasename}/*/${input:functionName}.ps1'", '@ -} + } elseif ($PLASTER_PARAM_Pester-eq '5') { @' "command": "Import-Module -Name '${workspaceFolder}/src/${workspaceFolderBasename}/${workspaceFolderBasename}.psm1';$pesterConfig = New-PesterConfiguration;$pesterConfig.run.Path = '${workspaceFolder}/src/Tests/Unit/*/${input:functionName}.Tests.ps1';$pesterConfig.CodeCoverage.Enabled = $true;$pesterConfig.CodeCoverage.Path = '${workspaceFolder}/src/${workspaceFolderBasename}/*/${input:functionName}.ps1';Invoke-Pester -Configuration $pesterConfig", -'@ } +'@ + } %> "problemMatcher": "$pester", "presentation": { @@ -249,10 +254,11 @@ if ($PLASTER_PARAM_Pester-eq '4') { @' "command": "Import-Module -Name Pester -MaximumVersion 4.99.99;Import-Module -Name '${workspaceFolder}/src/${workspaceFolderBasename}/${workspaceFolderBasename}.psm1';Invoke-Pester '${workspaceFolder}/src/Tests/Unit/*/${input:functionName}.Tests.ps1'", '@ -} + } elseif ($PLASTER_PARAM_Pester-eq '5') { @' "command": "Import-Module -Name '${workspaceFolder}/src/${workspaceFolderBasename}/${workspaceFolderBasename}.psm1';Invoke-Pester '${workspaceFolder}/src/Tests/Unit/*/${input:functionName}.Tests.ps1' -Output Detailed", -'@ } +'@ + } %> "problemMatcher": "$pester", "presentation": { @@ -269,11 +275,12 @@ if ($PLASTER_PARAM_Pester-eq '4') { @' "command": "Import-Module -Name '${workspaceFolder}/src/${workspaceFolderBasename}/${workspaceFolderBasename}.psm1';Import-Module -Name Pester -MaximumVersion 4.99.99;Invoke-Pester '${workspaceFolder}/src/Tests/Unit/*/${input:functionName}.Tests.ps1' -CodeCoverage '${workspaceFolder}/src/${workspaceFolderBasename}/*/${input:functionName}.ps1' -CodeCoverageOutputFile '${workspaceFolder}/cov.xml'", '@ -} + } elseif ($PLASTER_PARAM_Pester-eq '5') { @' "command": "Import-Module -Name '${workspaceFolder}/src/${workspaceFolderBasename}/${workspaceFolderBasename}.psm1';$pesterConfig = New-PesterConfiguration;$pesterConfig.run.Path = '${workspaceFolder}/src/Tests/Unit/*/${input:functionName}.Tests.ps1';$pesterConfig.CodeCoverage.Enabled = $true;$pesterConfig.CodeCoverage.Path = '${workspaceFolder}/src/${workspaceFolderBasename}/*/${input:functionName}.ps1';$pesterConfig.CodeCoverage.OutputPath = '${workspaceFolder}/cov.xml';$pesterConfig.CodeCoverage.OutputFormat = 'CoverageGutters';Invoke-Pester -Configuration $pesterConfig", -'@ } +'@ + } %> "problemMatcher": "$pester", "presentation": { @@ -290,10 +297,11 @@ if ($PLASTER_PARAM_Pester-eq '4') { @' "command": "Import-Module -Name Pester -MaximumVersion 4.99.99;Import-Module -Name '${workspaceFolder}/src/${workspaceFolderBasename}/${workspaceFolderBasename}.psm1';Invoke-Pester '${workspaceFolder}/src/Tests/Integration/*/${input:functionName}.Tests.ps1'", '@ -} + } elseif ($PLASTER_PARAM_Pester-eq '5') { @' "command": "Import-Module -Name '${workspaceFolder}/src/${workspaceFolderBasename}/${workspaceFolderBasename}.psm1';Invoke-Pester '${workspaceFolder}/src/Tests/Integration/*/${input:functionName}.Tests.ps1' -Output Detailed", -'@ } +'@ + } %> "problemMatcher": "$pester", "presentation": { @@ -310,4 +318,4 @@ elseif ($PLASTER_PARAM_Pester-eq '5') { @' "description": "Name of PowerShell function you want to test" } ] -} +} \ No newline at end of file diff --git a/src/Catesta/Resources/GitHubActions/actions_bootstrap.ps1 b/src/Catesta/Resources/GitHubActions/actions_bootstrap.ps1 index 83bbfb1..eaa298a 100644 --- a/src/Catesta/Resources/GitHubActions/actions_bootstrap.ps1 +++ b/src/Catesta/Resources/GitHubActions/actions_bootstrap.ps1 @@ -23,7 +23,7 @@ elseif ($PLASTER_PARAM_Pester-eq '5') { # https://github.com/pester/Pester [void]$modulesToInstall.Add(([PSCustomObject]@{ ModuleName = 'Pester' - ModuleVersion = '5.5.0' + ModuleVersion = '5.6.1' })) '@ } @@ -31,7 +31,7 @@ elseif ($PLASTER_PARAM_Pester-eq '5') { # https://github.com/nightroman/Invoke-Build [void]$modulesToInstall.Add(([PSCustomObject]@{ ModuleName = 'InvokeBuild' - ModuleVersion = '5.11.1' + ModuleVersion = '5.11.3' })) # https://github.com/PowerShell/PSScriptAnalyzer [void]$modulesToInstall.Add(([PSCustomObject]@{ @@ -67,7 +67,14 @@ foreach ($module in $modulesToInstall) { ErrorAction = 'Stop' } try { - Install-Module @installSplat + if ($module.ModuleName -eq 'Pester' -and $IsWindows) { + # special case for Pester certificate mismatch with older Pester versions - https://github.com/pester/Pester/issues/2389 + # this only affects windows builds + Install-Module @installSplat -SkipPublisherCheck + } + else { + Install-Module @installSplat + } Import-Module -Name $module.ModuleName -ErrorAction Stop ' - Successfully installed {0}' -f $module.ModuleName } diff --git a/src/Catesta/Resources/GitHubActionsCodeBuild/actions_bootstrap.ps1 b/src/Catesta/Resources/GitHubActionsCodeBuild/actions_bootstrap.ps1 index 83bbfb1..eaa298a 100644 --- a/src/Catesta/Resources/GitHubActionsCodeBuild/actions_bootstrap.ps1 +++ b/src/Catesta/Resources/GitHubActionsCodeBuild/actions_bootstrap.ps1 @@ -23,7 +23,7 @@ elseif ($PLASTER_PARAM_Pester-eq '5') { # https://github.com/pester/Pester [void]$modulesToInstall.Add(([PSCustomObject]@{ ModuleName = 'Pester' - ModuleVersion = '5.5.0' + ModuleVersion = '5.6.1' })) '@ } @@ -31,7 +31,7 @@ elseif ($PLASTER_PARAM_Pester-eq '5') { # https://github.com/nightroman/Invoke-Build [void]$modulesToInstall.Add(([PSCustomObject]@{ ModuleName = 'InvokeBuild' - ModuleVersion = '5.11.1' + ModuleVersion = '5.11.3' })) # https://github.com/PowerShell/PSScriptAnalyzer [void]$modulesToInstall.Add(([PSCustomObject]@{ @@ -67,7 +67,14 @@ foreach ($module in $modulesToInstall) { ErrorAction = 'Stop' } try { - Install-Module @installSplat + if ($module.ModuleName -eq 'Pester' -and $IsWindows) { + # special case for Pester certificate mismatch with older Pester versions - https://github.com/pester/Pester/issues/2389 + # this only affects windows builds + Install-Module @installSplat -SkipPublisherCheck + } + else { + Install-Module @installSplat + } Import-Module -Name $module.ModuleName -ErrorAction Stop ' - Successfully installed {0}' -f $module.ModuleName } diff --git a/src/Catesta/Resources/GitLab/actions_bootstrap.ps1 b/src/Catesta/Resources/GitLab/actions_bootstrap.ps1 index 83bbfb1..eaa298a 100644 --- a/src/Catesta/Resources/GitLab/actions_bootstrap.ps1 +++ b/src/Catesta/Resources/GitLab/actions_bootstrap.ps1 @@ -23,7 +23,7 @@ elseif ($PLASTER_PARAM_Pester-eq '5') { # https://github.com/pester/Pester [void]$modulesToInstall.Add(([PSCustomObject]@{ ModuleName = 'Pester' - ModuleVersion = '5.5.0' + ModuleVersion = '5.6.1' })) '@ } @@ -31,7 +31,7 @@ elseif ($PLASTER_PARAM_Pester-eq '5') { # https://github.com/nightroman/Invoke-Build [void]$modulesToInstall.Add(([PSCustomObject]@{ ModuleName = 'InvokeBuild' - ModuleVersion = '5.11.1' + ModuleVersion = '5.11.3' })) # https://github.com/PowerShell/PSScriptAnalyzer [void]$modulesToInstall.Add(([PSCustomObject]@{ @@ -67,7 +67,14 @@ foreach ($module in $modulesToInstall) { ErrorAction = 'Stop' } try { - Install-Module @installSplat + if ($module.ModuleName -eq 'Pester' -and $IsWindows) { + # special case for Pester certificate mismatch with older Pester versions - https://github.com/pester/Pester/issues/2389 + # this only affects windows builds + Install-Module @installSplat -SkipPublisherCheck + } + else { + Install-Module @installSplat + } Import-Module -Name $module.ModuleName -ErrorAction Stop ' - Successfully installed {0}' -f $module.ModuleName } diff --git a/src/Catesta/Resources/Module/plasterManifest.xml b/src/Catesta/Resources/Module/plasterManifest.xml index 4591c5e..ae96436 100644 --- a/src/Catesta/Resources/Module/plasterManifest.xml +++ b/src/Catesta/Resources/Module/plasterManifest.xml @@ -5,6 +5,7 @@ @@ -177,11 +182,13 @@ + + @@ -326,7 +333,8 @@ - + + diff --git a/src/Catesta/Resources/Module/src/Module/Classes/SampleClass.ps1 b/src/Catesta/Resources/Module/src/Module/Classes/SampleClass.ps1 new file mode 100644 index 0000000..2c9bf7f --- /dev/null +++ b/src/Catesta/Resources/Module/src/Module/Classes/SampleClass.ps1 @@ -0,0 +1,36 @@ +<# +.NOTES + This class demonstrates basic class structure and functionality in PowerShell. + + # Create an instance of the SampleClass + $person = [SampleClass]::new('John Doe', 30) + + # Call the Greet method + $message = $person.Greet() + Write-Output $message + + # Increment the age and output a birthday message + $person.HaveBirthday() + + # Access the properties + Write-Output "Name: $($person.Name)" + Write-Output "Age: $($person.Age)" +#> +class SampleClass { + [string]$Name + [int]$Age + + SampleClass([string]$Name, [int]$Age) { + $this.Name = $Name + $this.Age = $Age + } + + [string]Greet() { + return "Hello, my name is $($this.Name) and I am $($this.Age) years old." + } + + [string]HaveBirthday() { + $this.Age++ + return "Happy Birthday $($this.Name)! You are now $($this.Age) years old." + } +} diff --git a/src/Catesta/Resources/Module/src/Module/Module.psm1 b/src/Catesta/Resources/Module/src/Module/Module.psm1 index 81f168f..516572b 100644 --- a/src/Catesta/Resources/Module/src/Module/Module.psm1 +++ b/src/Catesta/Resources/Module/src/Module/Module.psm1 @@ -16,7 +16,7 @@ try { } catch { Write-Error $_ - throw "Unable to get get file information from Public & Private src." + throw 'Unable to get get file information from Public & Private src.' } # dot source all .ps1 file(s) found @@ -25,10 +25,9 @@ foreach ($file in @($public + $private)) { . $file.FullName } catch { - throw "Unable to dot source [$($file.FullName)]" - + throw ('Unable to dot source {0}' -f $file.FullName) } } # export all public functions -Export-ModuleMember -Function $public.Basename \ No newline at end of file +Export-ModuleMember -Function $public.Basename diff --git a/src/Catesta/Resources/Module/src/Module/Module_Classes.psm1 b/src/Catesta/Resources/Module/src/Module/Module_Classes.psm1 new file mode 100644 index 0000000..38d5ead --- /dev/null +++ b/src/Catesta/Resources/Module/src/Module/Module_Classes.psm1 @@ -0,0 +1,34 @@ +# this psm1 is for local testing and development use only + +# dot source the parent import for local development variables +. $PSScriptRoot\Imports.ps1 + +# discover all ps1 file(s) in Public and Private paths + +$itemSplat = @{ + Filter = '*.ps1' + Recurse = $true + ErrorAction = 'Stop' +} +try { + $public = @(Get-ChildItem -Path "$PSScriptRoot\Public" @itemSplat) + $private = @(Get-ChildItem -Path "$PSScriptRoot\Private" @itemSplat) + $classes = @(Get-ChildItem -Path "$PSScriptRoot\Classes" @itemSplat) +} +catch { + Write-Error $_ + throw 'Unable to get get file information from Public/Private/Classes src.' +} + +# dot source all .ps1 file(s) found +foreach ($file in @($public + $private + $classes)) { + try { + . $file.FullName + } + catch { + throw ('Unable to dot source {0}' -f $file.FullName) + } +} + +# export all public functions +Export-ModuleMember -Function $public.Basename diff --git a/src/Catesta/Resources/Module/src/PSModule.build.ps1 b/src/Catesta/Resources/Module/src/PSModule.build.ps1 index b19c7c6..6a428e1 100644 --- a/src/Catesta/Resources/Module/src/PSModule.build.ps1 +++ b/src/Catesta/Resources/Module/src/PSModule.build.ps1 @@ -353,7 +353,7 @@ elseif ($PLASTER_PARAM_Pester -eq '5') { $pesterConfiguration.Run.PassThru = $true $pesterConfiguration.Run.Exit = $false $pesterConfiguration.CodeCoverage.Enabled = $true - $pesterConfiguration.CodeCoverage.Path = "..\..\..\$ModuleName\*\*.ps1" + $pesterConfiguration.CodeCoverage.Path = "..\..\..\src\$ModuleName\*\*.ps1" $pesterConfiguration.CodeCoverage.CoveragePercentTarget = $script:coverageThreshold $pesterConfiguration.CodeCoverage.OutputPath = "$codeCovPath\CodeCoverage.xml" $pesterConfiguration.CodeCoverage.OutputFormat = 'JaCoCo' diff --git a/src/Catesta/Resources/Module/src/Tests/v5/Integration/SampleIntegrationTest.Tests.ps1 b/src/Catesta/Resources/Module/src/Tests/v5/Integration/SampleIntegrationTest.Tests.ps1 index ed629e3..b0a334c 100644 --- a/src/Catesta/Resources/Module/src/Tests/v5/Integration/SampleIntegrationTest.Tests.ps1 +++ b/src/Catesta/Resources/Module/src/Tests/v5/Integration/SampleIntegrationTest.Tests.ps1 @@ -1,14 +1,12 @@ -# #------------------------------------------------------------------------- -# Set-Location -Path $PSScriptRoot -# #------------------------------------------------------------------------- -# $ModuleName = '<%=$PLASTER_PARAM_ModuleName%>' -# #------------------------------------------------------------------------- -# #if the module is already in memory, remove it -# Get-Module $ModuleName | Remove-Module -Force -# $PathToManifest = [System.IO.Path]::Combine('..', '..', 'Artifacts', "$ModuleName.psd1") -# #------------------------------------------------------------------------- -# Import-Module $PathToManifest -Force -# #------------------------------------------------------------------------- +# BeforeAll { +# Set-Location -Path $PSScriptRoot +# $ModuleName = '<%=$PLASTER_PARAM_ModuleName%>' +# $PathToManifest = [System.IO.Path]::Combine('..', '..', 'Artifacts', "$ModuleName.psd1") +# #if the module is already in memory, remove it +# Get-Module $ModuleName -ErrorAction SilentlyContinue | Remove-Module -Force +# Import-Module $PathToManifest -Force +# } + # Describe 'Integration Tests' -Tag Integration { # Context 'First Integration Tests' { # It 'should pass the first integration test' { diff --git a/src/Catesta/Resources/Module/src/Tests/v5/Unit/ExportedFunctions.Tests.ps1 b/src/Catesta/Resources/Module/src/Tests/v5/Unit/ExportedFunctions.Tests.ps1 index cced9cf..d12fb9a 100644 --- a/src/Catesta/Resources/Module/src/Tests/v5/Unit/ExportedFunctions.Tests.ps1 +++ b/src/Catesta/Resources/Module/src/Tests/v5/Unit/ExportedFunctions.Tests.ps1 @@ -1,17 +1,14 @@ -#------------------------------------------------------------------------- -Set-Location -Path $PSScriptRoot -#------------------------------------------------------------------------- -$ModuleName = '<%=$PLASTER_PARAM_ModuleName%>' -$PathToManifest = [System.IO.Path]::Combine('..', '..', $ModuleName, "$ModuleName.psd1") -#------------------------------------------------------------------------- -if (Get-Module -Name $ModuleName -ErrorAction 'SilentlyContinue') { - #if the module is already in memory, remove it - Remove-Module -Name $ModuleName -Force -} -Import-Module $PathToManifest -Force -#------------------------------------------------------------------------- - BeforeAll { + Set-Location -Path $PSScriptRoot + $ModuleName = '<%=$PLASTER_PARAM_ModuleName%>' + $PathToManifest = [System.IO.Path]::Combine('..', '..', $ModuleName, "$ModuleName.psd1") + Get-Module $ModuleName -ErrorAction SilentlyContinue | Remove-Module -Force + Import-Module $PathToManifest -Force + $manifestContent = Test-ModuleManifest -Path $PathToManifest + $moduleExported = Get-Command -Module $ModuleName | Select-Object -ExpandProperty Name + $manifestExported = ($manifestContent.ExportedFunctions).Keys +} +BeforeDiscovery { Set-Location -Path $PSScriptRoot $ModuleName = '<%=$PLASTER_PARAM_ModuleName%>' $PathToManifest = [System.IO.Path]::Combine('..', '..', $ModuleName, "$ModuleName.psd1") @@ -24,43 +21,40 @@ Describe $ModuleName { Context 'Exported Commands' -Fixture { Context 'Number of commands' -Fixture { - It -Name 'Exports the same number of public functions as what is listed in the Module Manifest' -Test { + + It 'Exports the same number of public functions as what is listed in the Module Manifest' { $manifestExported.Count | Should -BeExactly $moduleExported.Count } + } - Context 'Explicitly exported commands' -ForEach $moduleExported { - foreach ($command in $moduleExported) { - BeforeAll { - $command = $_ - } - It -Name "Includes the $command in the Module Manifest ExportedFunctions" -Test { - $manifestExported -contains $command | Should -BeTrue - } + Context 'Explicitly exported commands' { + + It 'Includes <_> in the Module Manifest ExportedFunctions' -ForEach $moduleExported { + $manifestExported -contains $_ | Should -BeTrue } + } - } + } #context_ExportedCommands - Context 'Command Help' -ForEach $moduleExported { - foreach ($command in $moduleExported) { - BeforeAll { + Context 'Command Help' -Fixture { + Context '<_>' -Foreach $moduleExported { + + BeforeEach { $help = Get-Help -Name $_ -Full } - Context $command -Fixture { - $help = Get-Help -Name $command -Full - It -Name 'Includes a Synopsis' -Test { - $help.Synopsis | Should -Not -BeNullOrEmpty - } + It -Name 'Includes a Synopsis' -Test { + $help.Synopsis | Should -Not -BeNullOrEmpty + } - It -Name 'Includes a Description' -Test { - $help.description.Text | Should -Not -BeNullOrEmpty - } + It -Name 'Includes a Description' -Test { + $help.description.Text | Should -Not -BeNullOrEmpty + } - It -Name 'Includes an Example' -Test { - $help.examples.example | Should -Not -BeNullOrEmpty - } + It -Name 'Includes an Example' -Test { + $help.examples.example | Should -Not -BeNullOrEmpty } } - } -} \ No newline at end of file + } #context_CommandHelp +} diff --git a/src/Catesta/Resources/Module/src/Tests/v5/Unit/Private/Private-Function.Tests.ps1 b/src/Catesta/Resources/Module/src/Tests/v5/Unit/Private/Private-Function.Tests.ps1 index 1309b17..73e8a2b 100644 --- a/src/Catesta/Resources/Module/src/Tests/v5/Unit/Private/Private-Function.Tests.ps1 +++ b/src/Catesta/Resources/Module/src/Tests/v5/Unit/Private/Private-Function.Tests.ps1 @@ -1,15 +1,11 @@ -#------------------------------------------------------------------------- -Set-Location -Path $PSScriptRoot -#------------------------------------------------------------------------- -$ModuleName = '<%=$PLASTER_PARAM_ModuleName%>' -$PathToManifest = [System.IO.Path]::Combine('..', '..', '..', $ModuleName, "$ModuleName.psd1") -#------------------------------------------------------------------------- -if (Get-Module -Name $ModuleName -ErrorAction 'SilentlyContinue') { +BeforeAll { + Set-Location -Path $PSScriptRoot + $ModuleName = '<%=$PLASTER_PARAM_ModuleName%>' + $PathToManifest = [System.IO.Path]::Combine('..', '..', '..', $ModuleName, "$ModuleName.psd1") #if the module is already in memory, remove it - Remove-Module -Name $ModuleName -Force + Get-Module $ModuleName -ErrorAction SilentlyContinue | Remove-Module -Force + Import-Module $PathToManifest -Force } -Import-Module $PathToManifest -Force -#------------------------------------------------------------------------- InModuleScope '<%=$PLASTER_PARAM_ModuleName%>' { #------------------------------------------------------------------------- @@ -59,5 +55,5 @@ InModuleScope '<%=$PLASTER_PARAM_ModuleName%>' { } #it } #context_Success - } #describe_Get-HellowWorld -} #inModule \ No newline at end of file + } #describe_Get-HelloWorld +} #inModule diff --git a/src/Catesta/Resources/Module/src/Tests/v5/Unit/Public/Public-Function.Tests.ps1 b/src/Catesta/Resources/Module/src/Tests/v5/Unit/Public/Public-Function.Tests.ps1 index 9ac2338..e87dbde 100644 --- a/src/Catesta/Resources/Module/src/Tests/v5/Unit/Public/Public-Function.Tests.ps1 +++ b/src/Catesta/Resources/Module/src/Tests/v5/Unit/Public/Public-Function.Tests.ps1 @@ -1,18 +1,14 @@ -#------------------------------------------------------------------------- -Set-Location -Path $PSScriptRoot -#------------------------------------------------------------------------- -$ModuleName = '<%=$PLASTER_PARAM_ModuleName%>' -$PathToManifest = [System.IO.Path]::Combine('..', '..', '..', $ModuleName, "$ModuleName.psd1") -#------------------------------------------------------------------------- -if (Get-Module -Name $ModuleName -ErrorAction 'SilentlyContinue') { +BeforeAll { + Set-Location -Path $PSScriptRoot + $ModuleName = '<%=$PLASTER_PARAM_ModuleName%>' + $PathToManifest = [System.IO.Path]::Combine('..', '..', '..', $ModuleName, "$ModuleName.psd1") #if the module is already in memory, remove it - Remove-Module -Name $ModuleName -Force + Get-Module $ModuleName -ErrorAction SilentlyContinue | Remove-Module -Force + Import-Module $PathToManifest -Force } -Import-Module $PathToManifest -Force -#------------------------------------------------------------------------- InModuleScope '<%=$PLASTER_PARAM_ModuleName%>' { - Describe 'Get-HellowWorld Public Function Tests' -Tag Unit { + Describe 'Get-HelloWorld Public Function Tests' -Tag Unit { BeforeAll { $WarningPreference = 'SilentlyContinue' $ErrorActionPreference = 'SilentlyContinue' @@ -37,5 +33,5 @@ InModuleScope '<%=$PLASTER_PARAM_ModuleName%>' { } #it } #context_Success - } #describe_Get-HellowWorld -} #inModule \ No newline at end of file + } #describe_Get-HelloWorld +} #inModule diff --git a/src/Catesta/Resources/Vault/plasterManifest.xml b/src/Catesta/Resources/Vault/plasterManifest.xml index bd915ef..d42c627 100644 --- a/src/Catesta/Resources/Vault/plasterManifest.xml +++ b/src/Catesta/Resources/Vault/plasterManifest.xml @@ -6,7 +6,7 @@ Catesta d531e058-52b8-4dd2-8162-01c95d1eb8f7 - 2.12.0 + 2.20.0 Catesta Scaffolds a new PowerShell SecretManagement extension vault module project Jake Morrison diff --git a/src/Catesta/Resources/Vault/src/Tests/v5/Unit/ExportedFunctions.Tests.ps1 b/src/Catesta/Resources/Vault/src/Tests/v5/Unit/ExportedFunctions.Tests.ps1 index d16fb79..aa447e3 100644 --- a/src/Catesta/Resources/Vault/src/Tests/v5/Unit/ExportedFunctions.Tests.ps1 +++ b/src/Catesta/Resources/Vault/src/Tests/v5/Unit/ExportedFunctions.Tests.ps1 @@ -1,17 +1,14 @@ -#------------------------------------------------------------------------- -Set-Location -Path $PSScriptRoot -#------------------------------------------------------------------------- -$ModuleName = '<%=$PLASTER_PARAM_ModuleName%>' -$PathToManifest = [System.IO.Path]::Combine('..', '..', $ModuleName, "$ModuleName.psd1") -#------------------------------------------------------------------------- -if (Get-Module -Name $ModuleName -ErrorAction 'SilentlyContinue') { - #if the module is already in memory, remove it - Remove-Module -Name $ModuleName -Force -} -Import-Module $PathToManifest -Force -#------------------------------------------------------------------------- - BeforeAll { + Set-Location -Path $PSScriptRoot + $ModuleName = '<%=$PLASTER_PARAM_ModuleName%>' + $PathToManifest = [System.IO.Path]::Combine('..', '..', $ModuleName, "$ModuleName.psd1") + Get-Module $ModuleName -ErrorAction SilentlyContinue | Remove-Module -Force + Import-Module $PathToManifest -Force + $manifestContent = Test-ModuleManifest -Path $PathToManifest + $moduleExported = Get-Command -Module $ModuleName | Select-Object -ExpandProperty Name + $manifestExported = ($manifestContent.ExportedFunctions).Keys +} +BeforeDiscovery { Set-Location -Path $PSScriptRoot $ModuleName = '<%=$PLASTER_PARAM_ModuleName%>' $PathToManifest = [System.IO.Path]::Combine('..', '..', $ModuleName, "$ModuleName.psd1") @@ -24,21 +21,20 @@ Describe $ModuleName { Context 'Exported Commands' -Fixture { Context 'Number of commands' -Fixture { - It -Name 'Exports the same number of public functions as what is listed in the Module Manifest' -Test { + + It 'Exports the same number of public functions as what is listed in the Module Manifest' { $manifestExported.Count | Should -BeExactly $moduleExported.Count } + } - Context 'Explicitly exported commands' -ForEach $moduleExported { - foreach ($command in $moduleExported) { - BeforeAll { - $command = $_ - } - It -Name "Includes the $command in the Module Manifest ExportedFunctions" -Test { - $manifestExported -contains $command | Should -BeTrue - } + Context 'Explicitly exported commands' { + + It 'Includes <_> in the Module Manifest ExportedFunctions' -ForEach $moduleExported { + $manifestExported -contains $_ | Should -BeTrue } + } - } + } #context_ExportedCommands -} \ No newline at end of file +} diff --git a/src/Catesta/Resources/Vault/src/Tests/v5/Unit/Module-Function.Tests.ps1 b/src/Catesta/Resources/Vault/src/Tests/v5/Unit/Module-Function.Tests.ps1 index 4a51dc0..0603f14 100644 --- a/src/Catesta/Resources/Vault/src/Tests/v5/Unit/Module-Function.Tests.ps1 +++ b/src/Catesta/Resources/Vault/src/Tests/v5/Unit/Module-Function.Tests.ps1 @@ -1,16 +1,12 @@ -#------------------------------------------------------------------------- -Set-Location -Path $PSScriptRoot -#------------------------------------------------------------------------- -$ModuleName = '<%=$PLASTER_PARAM_ModuleName%>' -$vaultName = '<%=$PLASTER_PARAM_ModuleName%>' -$PathToManifest = [System.IO.Path]::Combine('..', '..', $ModuleName, "$ModuleName.psd1") -#------------------------------------------------------------------------- -if (Get-Module -Name $ModuleName -ErrorAction 'SilentlyContinue') { +BeforeAll { + Set-Location -Path $PSScriptRoot + $ModuleName = '<%=$PLASTER_PARAM_ModuleName%>' + $vaultName = '<%=$PLASTER_PARAM_ModuleName%>' + $PathToManifest = [System.IO.Path]::Combine('..', '..', $ModuleName, "$ModuleName.psd1") #if the module is already in memory, remove it - Remove-Module -Name $ModuleName -Force + Get-Module $ModuleName -ErrorAction SilentlyContinue | Remove-Module -Force + Import-Module $PathToManifest -Force } -Import-Module $PathToManifest -Force -#------------------------------------------------------------------------- Describe '<%=$PLASTER_PARAM_ModuleName%> Vault Extension Tests' -Tag Unit { BeforeAll { @@ -33,4 +29,4 @@ Describe '<%=$PLASTER_PARAM_ModuleName%> Vault Extension Tests' -Tag Unit { } #it } #context_FunctionName -} #describe_vaultExtension \ No newline at end of file +} #describe_vaultExtension diff --git a/src/Tests/Integration/FileChecks.Tests.ps1 b/src/Tests/Integration/FileChecks.Tests.ps1 index 6aa833e..5a10bce 100644 --- a/src/Tests/Integration/FileChecks.Tests.ps1 +++ b/src/Tests/Integration/FileChecks.Tests.ps1 @@ -1,10 +1,10 @@ -#------------------------------------------------------------------------- -Set-Location -Path $PSScriptRoot -#------------------------------------------------------------------------- -$ModuleName = 'Catesta' -$resourcePath1 = [System.IO.Path]::Combine( '..', '..', 'Artifacts', 'Resources') -$manifests = Get-ChildItem -Path $resourcePath1 -Include '*.xml' -Recurse -#------------------------------------------------------------------------- +BeforeAll { + Set-Location -Path $PSScriptRoot + $ModuleName = 'Catesta' + $resourcePath1 = [System.IO.Path]::Combine( '..', '..', 'Artifacts', 'Resources') + $manifests = Get-ChildItem -Path $resourcePath1 -Include '*.xml' -Recurse +} + Describe 'File Checks' { BeforeAll { $WarningPreference = 'Continue' @@ -75,6 +75,10 @@ Describe 'File Checks' { $srcFiles.Name.Contains('Get-Day.ps1') | Should -BeExactly $true } #it + It 'should have a class example' { + $srcFiles.Name.Contains('SampleClass.ps1') | Should -BeExactly $true + } #it + } #context_module Context 'Vault Source Files' { diff --git a/src/Tests/Integration/New-ModuleProject.Tests.ps1 b/src/Tests/Integration/New-ModuleProject.Tests.ps1 index 05088bb..2b7d6f2 100644 --- a/src/Tests/Integration/New-ModuleProject.Tests.ps1 +++ b/src/Tests/Integration/New-ModuleProject.Tests.ps1 @@ -1,17 +1,12 @@ -#------------------------------------------------------------------------- -Set-Location -Path $PSScriptRoot -#------------------------------------------------------------------------- -$ModuleName = 'Catesta' -#------------------------------------------------------------------------- -#if the module is already in memory, remove it -Get-Module $ModuleName | Remove-Module -Force -$PathToManifest = [System.IO.Path]::Combine('..', '..', 'Artifacts', "$ModuleName.psd1") -#------------------------------------------------------------------------- -Import-Module $PathToManifest -Force -#------------------------------------------------------------------------- -$resourcePath1 = [System.IO.Path]::Combine( '..', '..', $ModuleName, 'Resources') -# $manifests = Get-ChildItem -Path $resourcePath1 -Include '*.xml' -Recurse -Force -#------------------------------------------------------------------------- +BeforeAll { + Set-Location -Path $PSScriptRoot + $ModuleName = 'Catesta' + $PathToManifest = [System.IO.Path]::Combine('..', '..', 'Artifacts', "$ModuleName.psd1") + #if the module is already in memory, remove it + Get-Module $ModuleName -ErrorAction SilentlyContinue | Remove-Module -Force + Import-Module $PathToManifest -Force +} + Describe 'Module Integration Tests' { BeforeAll { @@ -48,6 +43,7 @@ Describe 'Module Integration Tests' { Description = 'text' Version = '0.0.1' FN = 'user full name' + psClasses = 'Yes' CICD = 'NONE' RepoType = 'NONE' CodingStyle = 'Stroustrup' @@ -74,6 +70,7 @@ Describe 'Module Integration Tests' { $moduleOnlyFiles.Name.Contains('PSScriptAnalyzerSettings.psd1') | Should -BeExactly $true $moduleOnlyFiles.Name.Contains('Get-HelloWorld.ps1') | Should -BeExactly $true $moduleOnlyFiles.Name.Contains('Get-Day.ps1') | Should -BeExactly $true + $moduleOnlyFiles.Name.Contains('SampleClass.ps1') | Should -BeExactly $true # Tests $moduleOnlyFiles.Name.Contains('SampleIntegrationTest.Tests.ps1') | Should -BeExactly $true @@ -147,6 +144,7 @@ Describe 'Module Integration Tests' { Description = 'text' Version = '0.0.1' FN = 'user full name' + psClasses = 'No' CICD = 'NONE' RepoType = 'NONE' CodingStyle = 'Stroustrup' @@ -172,6 +170,7 @@ Describe 'Module Integration Tests' { Description = 'text' Version = '0.0.1' FN = 'user full name' + psClasses = 'No' CICD = 'NONE' RepoType = 'NONE' CodingStyle = 'Stroustrup' @@ -196,6 +195,7 @@ Describe 'Module Integration Tests' { $moduleOnlyFiles.Name.Contains('PSScriptAnalyzerSettings.psd1') | Should -BeExactly $true $moduleOnlyFiles.Name.Contains('Get-HelloWorld.ps1') | Should -BeExactly $true $moduleOnlyFiles.Name.Contains('Get-Day.ps1') | Should -BeExactly $true + $moduleOnlyFiles.Name.Contains('SampleClass.ps1') | Should -BeExactly $false # Tests $moduleOnlyFiles.Name.Contains('SampleIntegrationTest.Tests.ps1') | Should -BeExactly $true @@ -216,6 +216,7 @@ Describe 'Module Integration Tests' { Description = 'text' Version = '0.0.1' FN = 'user full name' + psClasses = 'No' CICD = 'CODEBUILD' AWSOptions = 'ps', 'pwshcore', 'pwsh' RepoType = 'GITHUB' @@ -278,6 +279,7 @@ Describe 'Module Integration Tests' { Description = 'text' Version = '0.0.1' FN = 'user full name' + psClasses = 'No' CICD = 'CODEBUILD' AWSOptions = 'ps', 'pwshcore', 'pwsh' RepoType = 'GITLAB' @@ -338,6 +340,7 @@ Describe 'Module Integration Tests' { Description = 'text' Version = '0.0.1' FN = 'user full name' + psClasses = 'No' CICD = 'CODEBUILD' AWSOptions = 'ps', 'pwshcore', 'pwsh' RepoType = 'BITBUCKET' @@ -397,6 +400,7 @@ Describe 'Module Integration Tests' { Description = 'text' Version = '0.0.1' FN = 'user full name' + psClasses = 'No' CICD = 'CODEBUILD' AWSOptions = 'ps', 'pwshcore', 'pwsh' RepoType = 'CodeCommit' @@ -449,6 +453,7 @@ Describe 'Module Integration Tests' { Description = 'text' Version = '0.0.1' FN = 'user full name' + psClasses = 'No' CICD = 'CODEBUILD' AWSOptions = 'ps', 'pwshcore', 'pwsh' RepoType = 'AZURE' @@ -486,6 +491,7 @@ Describe 'Module Integration Tests' { Description = 'text' Version = '0.0.1' FN = 'user full name' + psClasses = 'No' CICD = 'CODEBUILD' AWSOptions = 'ps' RepoType = 'GITHUB' @@ -542,6 +548,7 @@ Describe 'Module Integration Tests' { Description = 'text' Version = '0.0.1' FN = 'user full name' + psClasses = 'No' CICD = 'CODEBUILD' AWSOptions = 'ps' RepoType = 'CodeCommit' @@ -598,6 +605,7 @@ Describe 'Module Integration Tests' { Description = 'text' Version = '0.0.1' FN = 'user full name' + psClasses = 'No' CICD = 'AZURE' AzureOptions = 'windows', 'pwshcore', 'linux', 'macos' RepoType = 'GITHUB' @@ -637,6 +645,7 @@ Describe 'Module Integration Tests' { Description = 'text' Version = '0.0.1' FN = 'user full name' + psClasses = 'No' CICD = 'AZURE' AzureOptions = 'windows', 'pwshcore', 'linux', 'macos' RepoType = 'AZURE' @@ -676,6 +685,7 @@ Describe 'Module Integration Tests' { Description = 'text' Version = '0.0.1' FN = 'user full name' + psClasses = 'No' CICD = 'AZURE' AzureOptions = 'windows', 'pwshcore', 'linux', 'macos' RepoType = 'BITBUCKET' @@ -719,6 +729,7 @@ Describe 'Module Integration Tests' { Description = 'text' Version = '0.0.1' FN = 'user full name' + psClasses = 'No' CICD = 'APPVEYOR' AppveyorOptions = 'windows', 'pwshcore', 'linux', 'macos' RepoType = 'GITHUB' @@ -761,6 +772,7 @@ Describe 'Module Integration Tests' { Description = 'text' Version = '0.0.1' FN = 'user full name' + psClasses = 'No' CICD = 'GITHUB' GitHubAOptions = 'windows', 'pwshcore', 'linux', 'macos' RepoType = 'GITHUB' @@ -815,6 +827,7 @@ Describe 'Module Integration Tests' { Description = 'text' Version = '0.0.1' FN = 'user full name' + psClasses = 'No' CICD = 'GHACODEBUILD' GitHubACBOptions = 'ps', 'pwshcore', 'pwsh' RepoType = 'GITHUB' @@ -881,6 +894,7 @@ Describe 'Module Integration Tests' { Description = 'text' Version = '0.0.1' FN = 'user full name' + psClasses = 'No' CICD = 'BITBUCKET' RepoType = 'BITBUCKET' ReadtheDocs = 'NONE' @@ -919,6 +933,7 @@ Describe 'Module Integration Tests' { Description = 'text' Version = '0.0.1' FN = 'user full name' + psClasses = 'No' CICD = 'GITLAB' GitLabOptions = 'windows', 'pwshcore', 'linux' RepoType = 'GITLAB' @@ -965,6 +980,7 @@ Describe 'Module Integration Tests' { Description = 'text' Version = '0.0.1' FN = 'user full name' + psClasses = 'No' CICD = 'NONE' RepoType = 'CODECOMMIT' ReadtheDocs = 'NONE' @@ -1024,6 +1040,7 @@ Describe 'Module Integration Tests' { Description = 'text' Version = '0.0.1' FN = 'user full name' + psClasses = 'No' CICD = 'NONE' RepoType = 'GITHUB' ReadtheDocs = 'NONE' @@ -1104,6 +1121,7 @@ Describe 'Module Integration Tests' { Description = 'text' Version = '0.0.1' FN = 'user full name' + psClasses = 'No' CICD = 'NONE' RepoType = 'GITLAB' ReadtheDocs = 'NONE' @@ -1183,6 +1201,7 @@ Describe 'Module Integration Tests' { Description = 'text' Version = '0.0.1' FN = 'user full name' + psClasses = 'No' CICD = 'NONE' RepoType = 'GITHUB' ReadtheDocs = 'READTHEDOCS' @@ -1228,6 +1247,7 @@ Describe 'Module Integration Tests' { Description = 'text' Version = '0.0.1' FN = 'user full name' + psClasses = 'No' CICD = 'NONE' RepoType = 'GITHUB' ReadtheDocs = 'READTHEDOCS' @@ -1275,6 +1295,7 @@ Describe 'Module Integration Tests' { Description = 'My awesome module is awesome' Version = '0.0.1' FN = 'user full name' + psClasses = 'No' CICD = 'NONE' RepoType = 'NONE' CodingStyle = 'Stroustrup' @@ -1295,6 +1316,7 @@ Describe 'Module Integration Tests' { Description = 'My awesome module is awesome' Version = '0.0.1' FN = 'user full name' + psClasses = 'No' CICD = 'GITHUB' GitHubAOptions = 'windows', 'pwshcore', 'linux', 'macos' RepoType = 'GITHUB' @@ -1324,6 +1346,7 @@ Describe 'Module Integration Tests' { Description = 'My awesome module is awesome' Version = '0.0.1' FN = 'user full name' + psClasses = 'No' CICD = 'CODEBUILD' AWSOptions = 'ps', 'pwshcore', 'pwsh' RepoType = 'GITHUB' @@ -1352,6 +1375,7 @@ Describe 'Module Integration Tests' { Description = 'My awesome module is awesome' Version = '0.0.1' FN = 'user full name' + psClasses = 'No' CICD = 'AZURE' AzureOptions = 'windows', 'pwshcore', 'linux', 'macos' RepoType = 'GITHUB' @@ -1379,6 +1403,7 @@ Describe 'Module Integration Tests' { Description = 'My awesome module is awesome' Version = '0.0.1' FN = 'user full name' + psClasses = 'No' CICD = 'APPVEYOR' AppveyorOptions = 'windows', 'pwshcore', 'linux', 'macos' RepoType = 'GITHUB' @@ -1407,6 +1432,7 @@ Describe 'Module Integration Tests' { Description = 'My awesome module is awesome' Version = '0.0.1' FN = 'user full name' + psClasses = 'No' CICD = 'BITBUCKET' RepoType = 'BITBUCKET' ReadtheDocs = 'NONE' @@ -1434,6 +1460,7 @@ Describe 'Module Integration Tests' { Description = 'My awesome module is awesome' Version = '0.0.1' FN = 'user full name' + psClasses = 'No' CICD = 'GITLAB' RepoType = 'GITLAB' ReadtheDocs = 'READTHEDOCS' diff --git a/src/Tests/Integration/New-VaultProject.Tests.ps1 b/src/Tests/Integration/New-VaultProject.Tests.ps1 index ca3f14d..b6ba715 100644 --- a/src/Tests/Integration/New-VaultProject.Tests.ps1 +++ b/src/Tests/Integration/New-VaultProject.Tests.ps1 @@ -1,17 +1,12 @@ -#------------------------------------------------------------------------- -Set-Location -Path $PSScriptRoot -#------------------------------------------------------------------------- -$ModuleName = 'Catesta' -#------------------------------------------------------------------------- -#if the module is already in memory, remove it -Get-Module $ModuleName | Remove-Module -Force -$PathToManifest = [System.IO.Path]::Combine('..', '..', 'Artifacts', "$ModuleName.psd1") -#------------------------------------------------------------------------- -Import-Module $PathToManifest -Force -#------------------------------------------------------------------------- -$resourcePath1 = [System.IO.Path]::Combine( '..', '..', $ModuleName, 'Resources') -# $manifests = Get-ChildItem -Path $resourcePath1 -Include '*.xml' -Recurse -Force -#------------------------------------------------------------------------- +BeforeAll { + Set-Location -Path $PSScriptRoot + $ModuleName = 'Catesta' + $PathToManifest = [System.IO.Path]::Combine('..', '..', 'Artifacts', "$ModuleName.psd1") + #if the module is already in memory, remove it + Get-Module $ModuleName -ErrorAction SilentlyContinue | Remove-Module -Force + Import-Module $PathToManifest -Force +} + Describe 'Vault Integration Tests' { BeforeAll { diff --git a/src/Tests/Unit/ExportedFunctions.Tests.ps1 b/src/Tests/Unit/ExportedFunctions.Tests.ps1 index 23909a6..cad8586 100644 --- a/src/Tests/Unit/ExportedFunctions.Tests.ps1 +++ b/src/Tests/Unit/ExportedFunctions.Tests.ps1 @@ -1,17 +1,14 @@ -#------------------------------------------------------------------------- -Set-Location -Path $PSScriptRoot -#------------------------------------------------------------------------- -$ModuleName = 'Catesta' -$PathToManifest = [System.IO.Path]::Combine('..', '..', $ModuleName, "$ModuleName.psd1") -#------------------------------------------------------------------------- -if (Get-Module -Name $ModuleName -ErrorAction 'SilentlyContinue') { - #if the module is already in memory, remove it - Remove-Module -Name $ModuleName -Force -} -Import-Module $PathToManifest -Force -#------------------------------------------------------------------------- - BeforeAll { + Set-Location -Path $PSScriptRoot + $ModuleName = 'Catesta' + $PathToManifest = [System.IO.Path]::Combine('..\', '..\', $ModuleName, "$ModuleName.psd1") + Get-Module $ModuleName -ErrorAction SilentlyContinue | Remove-Module -Force + Import-Module $PathToManifest -Force + $manifestContent = Test-ModuleManifest -Path $PathToManifest + $moduleExported = Get-Command -Module $ModuleName | Select-Object -ExpandProperty Name + $manifestExported = ($manifestContent.ExportedFunctions).Keys +} +BeforeDiscovery { Set-Location -Path $PSScriptRoot $ModuleName = 'Catesta' $PathToManifest = [System.IO.Path]::Combine('..\', '..\', $ModuleName, "$ModuleName.psd1") @@ -19,48 +16,45 @@ BeforeAll { $moduleExported = Get-Command -Module $ModuleName | Select-Object -ExpandProperty Name $manifestExported = ($manifestContent.ExportedFunctions).Keys } -Describe $ModuleName { +Describe 'Catesta Functions' -Tag Unit { Context 'Exported Commands' -Fixture { Context 'Number of commands' -Fixture { - It -Name 'Exports the same number of public functions as what is listed in the Module Manifest' -Test { + + It 'Exports the same number of public functions as what is listed in the Module Manifest' { $manifestExported.Count | Should -BeExactly $moduleExported.Count } + } - Context 'Explicitly exported commands' -ForEach $moduleExported { - foreach ($command in $moduleExported) { - BeforeAll { - $command = $_ - } - It -Name "Includes the $command in the Module Manifest ExportedFunctions" -Test { - $manifestExported -contains $command | Should -BeTrue - } + Context 'Explicitly exported commands' { + + It 'Includes <_> in the Module Manifest ExportedFunctions' -ForEach $moduleExported { + $manifestExported -contains $_ | Should -BeTrue } + } - } + } #context_ExportedCommands + + Context 'Command Help' -Fixture { + Context '<_>' -Foreach $moduleExported { - Context 'Command Help' -Foreach $moduleExported { - foreach ($command in $moduleExported) { - BeforeAll { + BeforeEach { $help = Get-Help -Name $_ -Full } - Context $command -Fixture { - $help = Get-Help -Name $command -Full - It -Name 'Includes a Synopsis' -Test { - $help.Synopsis | Should -Not -BeNullOrEmpty - } + It -Name 'Includes a Synopsis' -Test { + $help.Synopsis | Should -Not -BeNullOrEmpty + } - It -Name 'Includes a Description' -Test { - $help.description.Text | Should -Not -BeNullOrEmpty - } + It -Name 'Includes a Description' -Test { + $help.description.Text | Should -Not -BeNullOrEmpty + } - It -Name 'Includes an Example' -Test { - $help.examples.example | Should -Not -BeNullOrEmpty - } + It -Name 'Includes an Example' -Test { + $help.examples.example | Should -Not -BeNullOrEmpty } } - } + } #context_CommandHelp } diff --git a/src/Tests/Unit/Public/New-ModuleProject.Tests.ps1 b/src/Tests/Unit/Public/New-ModuleProject.Tests.ps1 index f5aa3e6..56beb63 100644 --- a/src/Tests/Unit/Public/New-ModuleProject.Tests.ps1 +++ b/src/Tests/Unit/Public/New-ModuleProject.Tests.ps1 @@ -1,14 +1,12 @@ -#------------------------------------------------------------------------- -Set-Location -Path $PSScriptRoot -#------------------------------------------------------------------------- -$ModuleName = 'Catesta' -#------------------------------------------------------------------------- -#if the module is already in memory, remove it -Get-Module $ModuleName | Remove-Module -Force -$PathToManifest = [System.IO.Path]::Combine('..', '..', '..', $ModuleName, "$ModuleName.psd1") -#------------------------------------------------------------------------- -Import-Module $PathToManifest -Force -#------------------------------------------------------------------------- +BeforeAll { + Set-Location -Path $PSScriptRoot + $ModuleName = 'Catesta' + $PathToManifest = [System.IO.Path]::Combine('..', '..', '..', $ModuleName, "$ModuleName.psd1") + #if the module is already in memory, remove it + Get-Module $ModuleName -ErrorAction SilentlyContinue | Remove-Module -Force + Import-Module $PathToManifest -Force +} + InModuleScope $ModuleName { $functionName = 'New-ModuleProject' Describe "$functionName Function Tests" -Tag Unit { diff --git a/src/Tests/Unit/Public/New-VaultProject.Tests.ps1 b/src/Tests/Unit/Public/New-VaultProject.Tests.ps1 index b7e5d8a..7f21060 100644 --- a/src/Tests/Unit/Public/New-VaultProject.Tests.ps1 +++ b/src/Tests/Unit/Public/New-VaultProject.Tests.ps1 @@ -1,14 +1,12 @@ -#------------------------------------------------------------------------- -Set-Location -Path $PSScriptRoot -#------------------------------------------------------------------------- -$ModuleName = 'Catesta' -#------------------------------------------------------------------------- -#if the module is already in memory, remove it -Get-Module $ModuleName | Remove-Module -Force -$PathToManifest = [System.IO.Path]::Combine('..', '..', '..', $ModuleName, "$ModuleName.psd1") -#------------------------------------------------------------------------- -Import-Module $PathToManifest -Force -#------------------------------------------------------------------------- +BeforeAll { + Set-Location -Path $PSScriptRoot + $ModuleName = 'Catesta' + $PathToManifest = [System.IO.Path]::Combine('..', '..', '..', $ModuleName, "$ModuleName.psd1") + #if the module is already in memory, remove it + Get-Module $ModuleName -ErrorAction SilentlyContinue | Remove-Module -Force + Import-Module $PathToManifest -Force +} + InModuleScope $ModuleName { $functionName = 'New-VaultProject' Describe "$functionName Function Tests" -Tag Unit {