Skip to content

Commit 040685a

Browse files
committed
Modules: Replace Write-Host with Write-Log
- add assertion in spec to catch errors early - formatting fixes in spec
1 parent edbf4f5 commit 040685a

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

modules/BOSH.Utils/BOSH.Utils.Tests.ps1

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
BeforeAll {
2+
Remove-Module -Name BOSH.Utils -ErrorAction Ignore
23
Import-Module ./BOSH.Utils.psm1
34

45
# As of now, this function only supports DWords and Strings.
@@ -303,8 +304,7 @@ Describe "BOSH.Utils" {
303304
}
304305
}
305306

306-
# TODO resolve
307-
Describe "Disable-DCOM" -Tag 'Focused' {
307+
Describe "Disable-DCOM" {
308308
It "Disables the use of DCOM" {
309309
$DCOMPath = 'HKLM:\Software\Microsoft\OLE'
310310
$oldDCOMValue = (Get-ItemProperty -Path $DCOMPath).'EnableDCOM'
@@ -379,9 +379,7 @@ Describe "BOSH.Utils" {
379379
$( $args[0] -join "," ) -eq $( $args[1] -join "," )
380380
}
381381

382-
Mock Set-ItemProperty {
383-
"Property set"
384-
} -ModuleName BOSH.Utils
382+
Mock Set-ItemProperty { "Property set" } -ModuleName BOSH.Utils
385383

386384
{ Set-ProxySettings "http-proxy" "https-proxy" "bypass-list" } | Should -Not -Throw
387385

@@ -401,10 +399,7 @@ Describe "BOSH.Utils" {
401399
}
402400

403401
It "exits when the registry can't be set or there's an error because the arguments are wrong" {
404-
Mock Set-ItemProperty {
405-
Write-Error "Property not set"
406-
} -ModuleName BOSH.Utils
407-
402+
Mock Set-ItemProperty { Write-Error "Property not set" } -ModuleName BOSH.Utils
408403

409404
{ Set-ProxySettings "http-proxy" "https-proxy" "bypass-list" } | Should -Throw "Failed to set proxy settings: Property not set"
410405
}
@@ -417,9 +412,10 @@ Describe "BOSH.Utils" {
417412

418413
It "Should remove proxy settings if they were set" {
419414
$regKeyConnections = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections"
420-
Set-ItemProperty -Path $regKeyConnections -Name "DefaultConnectionSettings" -Value "test-value" -ErrorVariable err 2>&1 | Out-Null
415+
Set-ItemProperty -Path $regKeyConnections -Name "DefaultConnectionSettings" -Value "test-value" -ErrorVariable err
416+
$err | Should -Be $null
421417

422-
$set_proxy = & cmd.exe /c "netsh winhttp set proxy proxy-server=`"127.0.0.1`""
418+
& cmd.exe /c "netsh winhttp set proxy proxy-server=`"127.0.0.1`""
423419

424420
Clear-ProxySettings
425421

modules/BOSH.Utils/BOSH.Utils.psm1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,8 @@ function Set-ProxySettings
201201
[byte[]]$data = [System.Text.Encoding]::ASCII.GetBytes($text);
202202

203203
$regKeyConnections = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections"
204-
Set-ItemProperty -Path $regKeyConnections -Name "DefaultConnectionSettings" -Value $data -ErrorVariable err 2>&1 | Out-Null
205-
Write-Host "Added the IE registry key"
204+
Write-Log "Running: 'Set-ItemProperty -Path $regKeyConnections -Name DefaultConnectionSettings -Value ([System.Text.Encoding]::ASCII.GetBytes($text))'"
205+
Set-ItemProperty -Path $regKeyConnections -Name "DefaultConnectionSettings" -Value $data -ErrorVariable err
206206
if ($err -ne "")
207207
{
208208
throw "Failed to set proxy settings: $( $err )"

0 commit comments

Comments
 (0)