@@ -2,27 +2,42 @@ BeforeAll {
22 $repoRoot = Split-Path - Parent (Split-Path - Parent $PSCommandPath )
33 $moduleDir = Join-Path $repoRoot " PowerShellDevToolkit"
44 Import-Module $moduleDir - Force
5+
6+ $configPath = Join-Path $repoRoot " config.json"
7+ $examplePath = Join-Path $repoRoot " config.example.json"
8+ $script :hadConfig = Test-Path $configPath
9+ if (-not $script :hadConfig -and (Test-Path $examplePath )) {
10+ Copy-Item $examplePath $configPath
11+ $script :createdConfig = $true
12+ }
13+ }
14+
15+ AfterAll {
16+ if ($script :createdConfig ) {
17+ $configPath = Join-Path $repoRoot " config.json"
18+ Remove-Item $configPath - ErrorAction SilentlyContinue
19+ }
520}
621
722Describe " Get-ScriptConfig" {
823 It " Should load config.json when present" {
9- $config = Get-ScriptConfig
24+ $config = & ( Get-Module PowerShellDevToolkit) { Get- ScriptConfig }
1025 $config | Should -Not - BeNullOrEmpty
1126 }
1227
1328 It " Should have ssh section with servers" {
14- $config = Get-ScriptConfig
29+ $config = & ( Get-Module PowerShellDevToolkit) { Get- ScriptConfig }
1530 $config.ssh | Should -Not - BeNullOrEmpty
1631 $config.ssh.servers | Should -Not - BeNullOrEmpty
1732 }
1833
1934 It " Should have databasePorts section" {
20- $config = Get-ScriptConfig
35+ $config = & ( Get-Module PowerShellDevToolkit) { Get- ScriptConfig }
2136 $config.ssh.databasePorts | Should -Not - BeNullOrEmpty
2237 }
2338
2439 It " Should have editor section" {
25- $config = Get-ScriptConfig
40+ $config = & ( Get-Module PowerShellDevToolkit) { Get- ScriptConfig }
2641 $config.editor | Should -Not - BeNullOrEmpty
2742 }
2843
@@ -36,7 +51,7 @@ Describe "Get-ScriptConfig" {
3651 Copy-Item " $moduleDir \Private" " $tempDir \PowerShellDevToolkit\Private" - Recurse
3752 Copy-Item " $moduleDir \Public" " $tempDir \PowerShellDevToolkit\Public" - Recurse
3853 Set-Content " $tempDir \config.json" " NOT VALID JSON {{{{"
39- $output = powershell - NoProfile - ExecutionPolicy Bypass - Command " Import-Module '$tempDir \PowerShellDevToolkit' -Force; `$ r = Get-ScriptConfig 2>`$ null; if (`$ null -eq `$ r) { 'NULL' } else { 'NOTNULL' }"
54+ $output = pwsh - NoProfile - Command " Import-Module '$tempDir \PowerShellDevToolkit' -Force; `$ r = & ( Get-Module PowerShellDevToolkit) { Get- ScriptConfig } 2>`$ null; if (`$ null -eq `$ r) { 'NULL' } else { 'NOTNULL' }"
4055 ($output -match ' NULL' ) | Should - Be $true
4156 } finally {
4257 Remove-Item $tempDir - Recurse - Force - ErrorAction SilentlyContinue
0 commit comments