Create Set-ZertoAlert function and tests

This commit is contained in:
Wes Carroll
2019-02-24 20:18:02 -05:00
parent 04dba27f0c
commit 89bb9704df
3 changed files with 66 additions and 2 deletions
+22
View File
@@ -0,0 +1,22 @@
$moduleFileName = "ZertoApiWrapper.psm1"
$filePath = (Split-Path -Parent $MyInvocation.MyCommand.Path) -replace 'Tests', 'ZertoApiWrapper'
$fileName = (Split-Path -Leaf $MyInvocation.MyCommand.Path ) -replace '.Tests.', '.'
$modulePath = $filePath -replace "Public", ""
Import-Module $modulePath\$moduleFileName -Force
$userName = "zerto\build"
$password = ConvertTo-SecureString -String "ZertoBuild" -AsPlainText -Force
$credential = New-Object -TypeName System.Management.Automation.PSCredential($userName, $password)
# $credential = Import-Clixml -Path C:\ZertoScripts\Creds.xml
$zertoServer = "192.168.1.100"
$zertoPort = "7669"
Describe "Set-ZertoAlert" {
it "file should exist" {
"$filePath\$fileName" | should exist
}
it "module should have a function called Set-ZertoAlert" {
get-command Connect-ZertoServer | should be $true
}
}
+2 -2
View File
@@ -69,9 +69,9 @@ function Get-ZertoAlert {
[string]$entity,
[Parameter(
ParameterSetName = "filter",
HelpMessage = "Returns alerts that are dismissed"
HelpMessage = 'Returns alerts that are dismissed when set to $true an undismissed alerts when set to $false'
)]
[switch]$isDismissed
[bool]$isDismissed
)
begin {
+42
View File
@@ -0,0 +1,42 @@
function Set-ZertoAlert {
[cmdletbinding( SupportsShouldProcess = $true )]
param (
[Alias("identifier")]
[Parameter(
ValueFromPipeline = $true,
ValueFromPipelineByPropertyName = $true,
Mandatory = $true,
HelpMessage = "Alert identifier(s) to be dismissed or undismissed."
)]
[string[]]$alertId,
[Parameter(
ParameterSetName = "dismiss",
Mandatory = $true,
HelpMessage = "Will dismiss the selected alert."
)]
[switch]$dismiss,
[Parameter(
ParameterSetName = "undismiss",
Mandatory = $true,
HelpMessage = "Will undismiss the selected alert."
)]
[switch]$undismiss
)
begin {
$baseUri = "alerts"
}
process {
foreach ($id in $alertId) {
$uri = "{0}/{1}/{2}" -f $baseUri, $id, $PSCmdlet.ParameterSetName
if ($PSCmdlet.ShouldProcess($PSCmdlet.ParameterSetName + " alertId $id")) {
Invoke-ZertoRestRequest -uri $uri -method "POST" | Out-Null
}
}
}
end {
# Nothing to do.
}
}