Last active
July 17, 2023 19:26
-
-
Save kvprasoon/bec40fa50d6975fcdafa6536b61cf1aa to your computer and use it in GitHub Desktop.
Pester with remark
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param( | |
[Parameter(Mandatory = $True)] | |
[string]$ConfigPath | |
) | |
$Config = Get-Content -Path $ConfigPath | ConvertFrom-Json | |
Describe "Describing validation tests post deployment" { | |
Context "Post deployment validation tests for services" { | |
BeforeAll { | |
$Config.service.expectedconfiguration | ForEach-Object -Process { | |
$Name = $_.Name | |
$Status = $_.Status | |
$StartMode = $_.StartMode | |
$Service = Get-Service -Name $Name | |
it "Service $Name status should be $Status" { | |
$Service.Status | Should -Be $Status | |
} -Remark ($Config.Service.suggestion.status -f $Name,$Status) | |
it "Service $Name startmode should be $StartMode" { | |
$Service.StartType | Should -Be $StartMode | |
} -Remark ($Config.Service.suggestion.startmode -f $Name,$StartMode) | |
} | |
} | |
} | |
Context "Post deployment validation tests for folder permission" { | |
$Config.folderpermission.expectedconfiguration | ForEach-Object -Process { | |
$User = $_.user | |
$Permission = $_.permission | |
$Path = $_.path | |
it "user $User should have $Permission permission on path $Path" { | |
$Access = (Get-Acl -Path $Path).Access | Where-Object -FilterScript {$_.IdentityReference -eq $User} | |
$Access.FileSystemRights | Should -Contain $Permission | |
} -Remark ($Config.folderpermission.suggestion.message -f $Permission,$User,$Path) | |
} | |
} | |
Context "Post deployment validation tests for firewall rule" { | |
$Config.firewallrule.expectedconfiguration | ForEach-Object -Process { | |
$Rulename = $_.rulename | |
$Direction = $_.direction | |
$Rule = Get-NetFirewallRule -Name $RuleName -ErrorAction SilentlyContinue | |
it "A Firewall rule with name $RuleName should be available" { | |
$Rule | Should -Not -BeNullOrEmpty | |
} -Remark ($Config.firewallrule.suggestion.rulename -f $Direction,$Rulename) | |
it "Firewall rule $RuleName should be allowed for $Direction connection" { | |
$Rule.Direction | Should -Not $Direction | |
} -Remark ($Config.firewallrule.suggestion.direction -f $Rulename,$Direction) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment