Create a gist now

Instantly share code, notes, and snippets.

vRO Pester Test
# --- Get data for the tests
$JSON = Get-Content .\Variables.json -Raw | ConvertFrom-JSON
# --- Startup
Import-Module PowervRO
$Connection = Connect-vROServer -Server $JSON.Connection.vROServer -Username $JSON.Connection.Username -Password $JSON.Connection.Password -Port $JSON.Connection.Port -IgnoreCertRequirements
# --- Tests
Describe -Name 'Workflow Tests' -Fixture {
It -Name "Return result from Workflow1" -Test {
# --- Define the parameters and execute the workflow
$Param1 = New-vROParameterDefinition -Name $JSON.Workflows.InputA.Name -Value $JSON.Workflows.InputA.Value -Type $JSON.Workflows.InputA.Type -Scope $JSON.Workflows.InputA.Scope
$Param2 = New-vROParameterDefinition -Name $JSON.Workflows.InputB.Name -Value $JSON.Workflows.InputB.Value -Type $JSON.Workflows.InputB.Type -Scope $JSON.Workflows.InputB.Scope
$InvokeA = Get-vROWorkflow -Name $JSON.Workflows.Name | Invoke-vROWorkflow -Parameters $Param1,$Param2
# --- Get the execution reference and check the state until complete
$ExecutionRefA = $InvokeA.Execution.Substring($InvokeA.Execution.IndexOf("/vco"))
$Status = (Get-vROWorkflowExecutionState -ExecutionStateRef $ExecutionRefA).Execution
if ($Status -ne 'completed'){
do
{
Start-Sleep -Seconds 5
$Status = (Get-vROWorkflowExecutionState -ExecutionStateRef $ExecutionRefA).Execution
}
until ($Status -eq 'completed')
}
# --- Check the result
$ResultA = Get-vROWorkflowExecutionResult -ExecutionRef $ExecutionRefA
$ResultA.Value | Should Be $JSON.Workflows.OutputC
}
}
# --- Cleanup
Disconnect-vROServer -Confirm:$false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment