Skip to content

Instantly share code, notes, and snippets.

@jonathanmedd
Created October 24, 2016 16:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonathanmedd/e9f7f6cd0205c8b2a3e9d9c9c55c1c52 to your computer and use it in GitHub Desktop.
Save jonathanmedd/e9f7f6cd0205c8b2a3e9d9c9c55c1c52 to your computer and use it in GitHub Desktop.
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