Skip to content
Open
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
7 changes: 7 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ jobs:
Install-Module Pester -MinimumVersion 5.0 -Force -Scope CurrentUser
}

- name: Install PSFramework
shell: pwsh
run: |
if (-not (Get-Module PSFramework -ListAvailable | Where-Object Version -ge '1.0.0')) {
Install-Module PSFramework -MinimumVersion 1.0.0 -Force -Scope CurrentUser
}

- name: Run Pester tests
shell: pwsh
run: |
Expand Down
4 changes: 3 additions & 1 deletion MyModule/MyModule.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ PowerShellVersion = '7.0'
# ProcessorArchitecture = ''

# Modules that must be imported into the global environment prior to importing this module
# RequiredModules = @()
RequiredModules = @(
@{ ModuleName = 'PSFramework'; ModuleVersion = '1.0.0' }
)

# Assemblies that must be loaded prior to importing this module
# RequiredAssemblies = @()
Expand Down
27 changes: 27 additions & 0 deletions MyModule/MyModule.psm1
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#Requires -Version 7.0
#Requires -Modules PSFramework
# MyModule.psm1
# Replace this placeholder implementation with your module's functions.
# Add each public function to FunctionsToExport in MyModule.psd1.
Expand All @@ -8,11 +9,37 @@ if ($MyInvocation.MyCommand.ScriptBlock.Module.Guid -eq [guid]'00000000-0000-000
Write-Warning 'MyModule: GUID is still the template placeholder. Run Initialize-Module.ps1 before publishing this module.'
}

# ---------------------------------------------------------------------------
# Module configuration (PSFramework)
# ---------------------------------------------------------------------------
Set-PSFConfig -Module 'MyModule' -Name 'LogLevel' `
-Value 'Verbose' `
-Description 'Minimum message level written to the PSFramework log provider.' `
-Initialize -Validation string

# ---------------------------------------------------------------------------
# Public functions
# ---------------------------------------------------------------------------

# Example function — delete and replace with the real implementation:
function Get-MyModuleInfo {
<#
.SYNOPSIS
Returns basic information about the MyModule module.

.DESCRIPTION
Returns the module name and version. Replace this with your own
implementation after running Initialize-Module.ps1.

.EXAMPLE
PS> Get-MyModuleInfo
#>
[CmdletBinding()]
[OutputType([PSCustomObject])]
param()

Write-PSFMessage -Level Verbose -Message 'Gathering module information.'

[PSCustomObject]@{
Module = 'MyModule'
Version = (Get-Module MyModule).Version
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ in the manifest's `FunctionsToExport`, and write tests.

- PowerShell 7+
- [Pester](https://pester.dev) 5.x (`Install-Module Pester -MinimumVersion 5.0 -Scope CurrentUser`)
- [PSFramework](https://psframework.org) 1.x (`Install-Module PSFramework -MinimumVersion 1.0.0 -Scope CurrentUser`)

### Running tests

Expand Down
17 changes: 17 additions & 0 deletions tests/MyModule.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#Requires -Modules @{ ModuleName = 'Pester'; ModuleVersion = '5.0' }
#Requires -Modules @{ ModuleName = 'PSFramework'; ModuleVersion = '1.0.0' }

BeforeAll {
$modulePath = Join-Path $PSScriptRoot '..' 'MyModule' 'MyModule.psd1'
Expand All @@ -21,5 +22,21 @@ Describe 'MyModule module' {
$commands = Get-Command -Module MyModule
$commands | Should -Not -BeNullOrEmpty
}

It 'PSFramework is available as a dependency' {
Get-Module PSFramework -ListAvailable | Should -Not -BeNullOrEmpty
}
}

Context 'PSFramework configuration' {
It 'registers MyModule.LogLevel config entry' {
$config = Get-PSFConfig -Module MyModule -Name LogLevel
$config | Should -Not -BeNullOrEmpty
}

It 'MyModule.LogLevel defaults to Verbose' {
$value = Get-PSFConfigValue -FullName 'MyModule.LogLevel'
$value | Should -Be 'Verbose'
}
}
}