Created
October 1, 2015 20:21
-
-
Save trondhindenes/3c337fe57cf4c1f05bb5 to your computer and use it in GitHub Desktop.
My test scripts for get-AnsibleParam
This file contains hidden or 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
Set-StrictMode -Version 2 | |
$params = "" | Select Firstname, Lastname, ensure | |
$params.Lastname = "Hindenes" | |
$params.Ensure = "present" | |
$returnobj = "" | |
. "D:\trond.hindenes\Documents\Scripts\Ansible\fork\trondhindenes\ansible\lib\ansible\module_utils\powershell.ps1" | |
#simple - should succeed | |
Get-AnsibleParam -obj $params -name Firstname | |
#Use alias | |
Get-AnsibleParam -obj $params -name Name -aliases FirstName | |
#use multi alias | |
Get-AnsibleParam -obj $params -name Name -aliases FirstName,Something | |
#use multi alias reversed | |
Get-AnsibleParam -obj $params -name Name -aliases Something, Firstname | |
#should return null | |
Get-AnsibleParam -obj $params -name State | |
Get-AnsibleParam -obj $params -name State -aliases Status | |
#Param validation, should return value | |
Get-AnsibleParam -obj $params -name State -aliases Ensure -ValidateSet "Absent","Present" | |
#param validation, should fail (and return name of the original prop, not the aliased one) | |
Get-AnsibleParam -obj $params -name State -aliases Ensure -ValidateSet "somethingelse","something" | |
#param validation, should fail (custom validation warning) | |
Get-AnsibleParam -obj $params -name State -aliases Ensure -ValidateSet "somethingelse","something" -ValidateSetErrorMessage "blah." | |
#should fail (will quit script) | |
Get-AnsibleParam -obj $params -name State -failifempty $true -resultobj $returnobj | |
Get-AnsibleParam -obj $params -name State -aliases Status -failifempty $true -resultobj $returnobj |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment