Skip to content

Commit

Permalink
Add a test for updating a line with a leading space
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Hunt committed Jun 11, 2024
1 parent 5e04637 commit 9f5e4a5
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/Unit/DSC_HostsFile.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,39 @@ try
(Get-TargetResource @testParams).Ensure | Should -Be 'Present'
}
}

Context 'When a host entry exists and is not correct, but has a leading space' {
$testParams = @{
HostName = 'www.contoso.com'
IPAddress = '192.168.0.156'
Verbose = $true
}

Mock -CommandName Get-Content -MockWith {
return @(
'# A mocked example of a host file - this line is a comment',
'',
'127.0.0.1 localhost',
'127.0.0.1 www.anotherexample.com',
" 127.0.0.1 $($testParams.HostName)",
'127.0.0.5 anotherexample.com',
''
)
}

It 'Should return present from the get method' {
(Get-TargetResource @testParams).Ensure | Should -Be 'Present'
}

It 'Should return false from the test method' {
Test-TargetResource @testParams | Should -Be $false
}

It 'Should update the entry in the set method' {
Set-TargetResource @testParams
Assert-MockCalled -CommandName Set-Content
}
}
} #end InModuleScope $DSCResourceName
}
finally
Expand Down

0 comments on commit 9f5e4a5

Please sign in to comment.