feat(branding): registry helper + Pester harness
This commit is contained in:
16
windows/branding/lib/RegistryHelpers.ps1
Normal file
16
windows/branding/lib/RegistryHelpers.ps1
Normal file
@@ -0,0 +1,16 @@
|
||||
Set-StrictMode -Version Latest
|
||||
|
||||
# Write a registry value under an arbitrary hive root (a live HKLM:/HKCU: path
|
||||
# OR a loaded offline hive exposed as a PSDrive). Creates intermediate keys.
|
||||
function Set-SmRegValue {
|
||||
param(
|
||||
[Parameter(Mandatory)][string]$Root,
|
||||
[Parameter(Mandatory)][string]$SubKey,
|
||||
[Parameter(Mandatory)][string]$Name,
|
||||
[Parameter(Mandatory)][ValidateSet('String','ExpandString','DWord','Binary')][string]$Type,
|
||||
[Parameter(Mandatory)]$Value
|
||||
)
|
||||
$key = Join-Path $Root $SubKey
|
||||
if (-not (Test-Path $key)) { New-Item -Path $key -Force | Out-Null }
|
||||
New-ItemProperty -Path $key -Name $Name -PropertyType $Type -Value $Value -Force | Out-Null
|
||||
}
|
||||
22
windows/tests/Branding.Tests.ps1
Normal file
22
windows/tests/Branding.Tests.ps1
Normal file
@@ -0,0 +1,22 @@
|
||||
#Requires -Modules @{ ModuleName='Pester'; ModuleVersion='5.0.0' }
|
||||
|
||||
Describe 'Set-SmRegValue' {
|
||||
BeforeAll {
|
||||
. "$PSScriptRoot\..\branding\lib\RegistryHelpers.ps1"
|
||||
$script:root = 'HKCU:\Software\SilverMetalTest'
|
||||
if (Test-Path $script:root) { Remove-Item $script:root -Recurse -Force }
|
||||
}
|
||||
AfterAll {
|
||||
if (Test-Path $script:root) { Remove-Item $script:root -Recurse -Force }
|
||||
}
|
||||
|
||||
It 'creates the key path and writes a string value' {
|
||||
Set-SmRegValue -Root $script:root -SubKey 'A\B' -Name 'Greeting' -Type String -Value 'hi'
|
||||
(Get-ItemProperty "$script:root\A\B").Greeting | Should -Be 'hi'
|
||||
}
|
||||
|
||||
It 'writes a dword value' {
|
||||
Set-SmRegValue -Root $script:root -SubKey 'A' -Name 'Flag' -Type DWord -Value 1
|
||||
(Get-ItemProperty "$script:root\A").Flag | Should -Be 1
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user