diff --git a/CHANGELOG.md b/CHANGELOG.md index b0f30626e..c63549140 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +## 2019-10-18 + +### Changed [ Various cmdlets updated to remove boolean parameters and change to Switch] + +* Migrated boolean parameters to switch parameters in order to provide a more consistent approach accross all cmdlets. +* **Note: This has the possibility of providing breaking changes as the syntax of calling the parameters like '-Parameter $true' will no longer be supported.** +* For Example: Export-RubrikVM -PowerOn $False will continue to run, however the $False gets assigned to the VM Name. Get-RubrikOrganization -isGlobal $true will now fail. Will need to ensure these are addressed in the release notes. +* Cmdlets affected are `Export-RubrikVM`, `Get-RubrikEvent`, `Get-RubrikOrganization`, `New-RubrikHost`, `New-RubrikMount`, `Set-RubrikMount`, `Set-RubrikNutanixVM`, `Set-RubrikSupportTunnel` and `Set-RubrikVM` +* Addresses [Issue 352](https://github.com/rubrikinc/rubrik-sdk-for-powershell/issues/352) + ## 2019-10-17 ### Changed [Added Nutanix/Hyper-V support to New-RubrikSnapshot] diff --git a/Rubrik/Public/Export-RubrikVM.ps1 b/Rubrik/Public/Export-RubrikVM.ps1 index 2fd54d36b..1c0dca3c2 100644 --- a/Rubrik/Public/Export-RubrikVM.ps1 +++ b/Rubrik/Public/Export-RubrikVM.ps1 @@ -39,18 +39,18 @@ function Export-RubrikVM # Name of the exported VM [String]$VMName, # Whether the network should be disabled upon restoration. This should be set true to avoid ip conflict if source VM still exists. - [Bool]$DisableNetwork, + [Switch]$DisableNetwork, # Whether to remove network interfaces from the restored virtual machine. Default is false. - [Bool]$RemoveNetworkDevices, + [Switch]$RemoveNetworkDevices, # Whether to assign MAC addresses from source virtual machine to exported virtual machine. Default is false. - [Bool]$KeepMACAddresses, + [Switch]$KeepMACAddresses, # Whether the newly restored virtual machine is unregistered from vCenter. Default is false. - [Bool]$UnregisterVM, + [Switch]$UnregisterVM, # Whether the VM should be powered on after restoration. Default is true. - [Bool]$PowerOn, + [Switch]$PowerOn, # Whether to recover vSphere tags [Alias('shouldRecoverTags')] - [Bool]$RecoverTags, + [Switch]$RecoverTags, # Rubrik server IP or FQDN [String]$Server = $global:RubrikConnection.server, # API version @@ -79,6 +79,14 @@ function Export-RubrikVM Process { + # If the switch parameter was not explicitly specified remove from body params + if(-not $PSBoundParameters.ContainsKey('DisableNetwork')) { $Resources.Body.Remove('disableNetwork') } + if(-not $PSBoundParameters.ContainsKey('RemoveNetworkDevices')) { $Resources.Body.Remove('removeNetworkDevices') } + if(-not $PSBoundParameters.ContainsKey('KeepMACAddresses')) { $Resources.Body.Remove('keepMacAddresses') } + if(-not $PSBoundParameters.ContainsKey('UnregisterVM')) { $Resources.Body.Remove('unregisterVm') } + if(-not $PSBoundParameters.ContainsKey('PowerOn')) { $Resources.Body.Remove('powerOn') } + if(-not $PSBoundParameters.ContainsKey('RecoverTags')) { $Resources.Body.Remove('shouldRecoverTags') } + $uri = New-URIString -server $Server -endpoint ($resources.URI) -id $id $uri = Test-QueryParam -querykeys ($resources.Query.Keys) -parameters ((Get-Command $function).Parameters.Values) -uri $uri $body = New-BodyString -bodykeys ($resources.Body.Keys) -parameters ((Get-Command $function).Parameters.Values) diff --git a/Rubrik/Public/Get-RubrikEvent.ps1 b/Rubrik/Public/Get-RubrikEvent.ps1 index 477963b65..579fdee51 100644 --- a/Rubrik/Public/Get-RubrikEvent.ps1 +++ b/Rubrik/Public/Get-RubrikEvent.ps1 @@ -76,14 +76,14 @@ function Get-RubrikEvent [Alias('object_type')] [parameter()] [string]$ObjectType, - # A Boolean value that determines whether to show only on the most recent event in the series. When 'true' only the most recent event in the series are shown. When 'false' all events in the series are shown. The default value is 'true'. + # A switch value that determines whether to show only on the most recent event in the series. When 'true' only the most recent event in the series are shown. When 'false' all events in the series are shown. The default value is 'true'. [Alias('show_only_latest')] [parameter()] - [bool]$ShowOnlyLatest, - # A Boolean value that determines whether to filter only on the most recent event in the series. When 'true' only the most recent event in the series are filtered. When 'false' all events in the series are filtered. The default value is 'true'. + [Switch]$ShowOnlyLatest, + # A Switch value that determines whether to filter only on the most recent event in the series. When 'true' only the most recent event in the series are filtered. When 'false' all events in the series are filtered. The default value is 'true'. [Alias('filter_only_on_latest')] [parameter()] - [bool]$FilterOnlyOnLatest, + [Switch]$FilterOnlyOnLatest, # Rubrik server IP or FQDN [String]$Server = $global:RubrikConnection.server, # API version @@ -112,6 +112,10 @@ function Get-RubrikEvent Process { + # If the switch parameter was not explicitly specified remove from query params + if(-not $PSBoundParameters.ContainsKey('ShowOnlyLatest')) { $Resources.Query.Remove('show_only_latest') } + if(-not $PSBoundParameters.ContainsKey('FilterOnlyOnLatest')) { $Resources.Query.Remove('filter_only_on_latest') } + $uri = New-URIString -server $Server -endpoint ($resources.URI) $uri = Test-QueryParam -querykeys ($resources.Query.Keys) -parameters ((Get-Command $function).Parameters.Values) -uri $uri $body = New-BodyString -bodykeys ($resources.Body.Keys) -parameters ((Get-Command $function).Parameters.Values) diff --git a/Rubrik/Public/Get-RubrikOrganization.ps1 b/Rubrik/Public/Get-RubrikOrganization.ps1 index bbc35229a..c24d93302 100644 --- a/Rubrik/Public/Get-RubrikOrganization.ps1 +++ b/Rubrik/Public/Get-RubrikOrganization.ps1 @@ -19,8 +19,11 @@ function Get-RubrikOrganization .EXAMPLE Get-RubrikOrganization - Returns a complete list of all Rubrik organizations. + + .EXAMPLE + Get-RubrikOrganization -isGlobal:$false + Returns a list of non global of all Rubrik organizations. #> [CmdletBinding()] @@ -31,7 +34,7 @@ function Get-RubrikOrganization [String]$name, # Filter results on if the org is global or not [Alias('is_global')] - [bool]$isGlobal, + [Switch]$isGlobal, # Rubrik server IP or FQDN [String]$Server = $global:RubrikConnection.server, # API version @@ -59,7 +62,11 @@ function Get-RubrikOrganization } Process { - + # If the switch parameter was not explicitly specified remove from query params + if(-not $PSBoundParameters.ContainsKey('isGlobal')) { + $Resources.Query.Remove('is_global') + } + $uri = New-URIString -server $Server -endpoint ($resources.URI) -id $id $uri = Test-QueryParam -querykeys ($resources.Query.Keys) -parameters ((Get-Command $function).Parameters.Values) -uri $uri $body = New-BodyString -bodykeys ($resources.Body.Keys) -parameters ((Get-Command $function).Parameters.Values) diff --git a/Rubrik/Public/New-RubrikHost.ps1 b/Rubrik/Public/New-RubrikHost.ps1 index bedf9ce45..4108739e9 100644 --- a/Rubrik/Public/New-RubrikHost.ps1 +++ b/Rubrik/Public/New-RubrikHost.ps1 @@ -21,7 +21,7 @@ function New-RubrikHost This will register a host that resolves to the name "Server1.example.com" .EXAMPLE - New-RubrikHost -Name 'NAS.example.com' -HasAgent $false + New-RubrikHost -Name 'NAS.example.com' -HasAgent:$false This will register a host that resolves to the name "NAS.example.com" without using the Rubrik Backup Service In this case, the example host is a NAS share. #> @@ -33,7 +33,7 @@ function New-RubrikHost [Alias('Hostname')] [String]$Name, # Set to $false to register a host that will be accessed through network shares - [Bool]$HasAgent, + [Switch]$HasAgent, # Rubrik server IP or FQDN [String]$Server = $global:RubrikConnection.server, # API version @@ -61,7 +61,8 @@ function New-RubrikHost } Process { - + # If the switch parameter was not explicitly specified remove from query params + if(-not $PSBoundParameters.ContainsKey('HasAgent')) { $Resources.Body.Remove('hasAgent') } $uri = New-URIString -server $Server -endpoint ($resources.URI) -id $id $uri = Test-QueryParam -querykeys ($resources.Query.Keys) -parameters ((Get-Command $function).Parameters.Values) -uri $uri $body = New-BodyString -bodykeys ($resources.Body.Keys) -parameters ((Get-Command $function).Parameters.Values) diff --git a/Rubrik/Public/New-RubrikMount.ps1 b/Rubrik/Public/New-RubrikMount.ps1 index eed805273..ad5faad8d 100644 --- a/Rubrik/Public/New-RubrikMount.ps1 +++ b/Rubrik/Public/New-RubrikMount.ps1 @@ -47,11 +47,11 @@ function New-RubrikMount # Name of the data store to use/create on the host [String]$DatastoreName, # Whether the network should be disabled on mount.This should be set true to avoid ip conflict in case of static IPs. - [Bool]$DisableNetwork, + [Switch]$DisableNetwork, # Whether the network devices should be removed on mount. - [Bool]$RemoveNetworkDevices, + [Switch]$RemoveNetworkDevices, # Whether the VM should be powered on after mount. - [Bool]$PowerOn, + [Switch]$PowerOn, # Rubrik server IP or FQDN [String]$Server = $global:RubrikConnection.server, # API version @@ -79,7 +79,11 @@ function New-RubrikMount } Process { - + # If the switch parameter was not explicitly specified remove from body params + if(-not $PSBoundParameters.ContainsKey('DisableNetwork')) { $Resources.Body.Remove('disableNetwork') } + if(-not $PSBoundParameters.ContainsKey('RemoveNetworkDevices')) { $Resources.Body.Remove('removeNetworkDevices') } + if(-not $PSBoundParameters.ContainsKey('PowerOn')) { $Resources.Body.Remove('powerOn') } + $uri = New-URIString -server $Server -endpoint ($resources.URI) -id $id $uri = Test-QueryParam -querykeys ($resources.Query.Keys) -parameters ((Get-Command $function).Parameters.Values) -uri $uri $body = New-BodyString -bodykeys ($resources.Body.Keys) -parameters ((Get-Command $function).Parameters.Values) diff --git a/Rubrik/Public/Set-RubrikMount.ps1 b/Rubrik/Public/Set-RubrikMount.ps1 index 5b8229d0d..9982dd861 100644 --- a/Rubrik/Public/Set-RubrikMount.ps1 +++ b/Rubrik/Public/Set-RubrikMount.ps1 @@ -17,7 +17,7 @@ function Set-RubrikMount http://rubrikinc.github.io/rubrik-sdk-for-powershell/reference/Set-RubrikMount.html .EXAMPLE - Get-RubrikMount -id '11111111-2222-3333-4444-555555555555' | Set-RubrikMount -PowerOn:$true + Get-RubrikMount -id '11111111-2222-3333-4444-555555555555' | Set-RubrikMount -PowerOn This will send a power on request to "Server1" .EXAMPLE @@ -32,7 +32,7 @@ function Set-RubrikMount [String]$id, # Configuration for the change power status request [Alias('powerStatus')] - [Bool]$PowerOn, + [Switch]$PowerOn, # Rubrik server IP or FQDN [String]$Server = $global:RubrikConnection.server, # API version @@ -60,7 +60,7 @@ function Set-RubrikMount } Process { - + if(-not $PSBoundParameters.ContainsKey('PowerOn')) { $Resources.Body.Remove('powerStatus') } $uri = New-URIString -server $Server -endpoint ($resources.URI) -id $id $uri = Test-QueryParam -querykeys ($resources.Query.Keys) -parameters ((Get-Command $function).Parameters.Values) -uri $uri $body = New-BodyString -bodykeys ($resources.Body.Keys) -parameters ((Get-Command $function).Parameters.Values) diff --git a/Rubrik/Public/Set-RubrikNutanixVM.ps1 b/Rubrik/Public/Set-RubrikNutanixVM.ps1 index 3615d706d..72a6fee90 100644 --- a/Rubrik/Public/Set-RubrikNutanixVM.ps1 +++ b/Rubrik/Public/Set-RubrikNutanixVM.ps1 @@ -20,6 +20,10 @@ function Set-RubrikNutanixVM Get-RubrikNutanixVM 'Server1' | Set-RubrikNutanixVM -PauseBackups This will pause backups on any virtual machine named "Server1" + .EXAMPLE + Get-RubrikNutanixVM 'Server1' | Set-RubrikNutanixVM -PauseBackups:$false + This will unpause backups on any virtual machine named "Server1" + .EXAMPLE Get-RubrikNutanixVM -SLA Platinum | Set-RubrikNutanixVM -SnapConsistency 'CRASH_CONSISTENT' -MaxNestedSnapshots 2 -UseArrayIntegration This will find all virtual machines in the Platinum SLA Domain and set their snapshot consistency to crash consistent (no application quiescence) @@ -38,7 +42,7 @@ function Set-RubrikNutanixVM [String]$SnapConsistency, # Whether to pause or resume backups/archival for this VM. [Alias('isPaused')] - [Bool]$PauseBackups, + [Switch]$PauseBackups, # Rubrik server IP or FQDN [String]$Server = $global:RubrikConnection.server, # API version @@ -74,6 +78,7 @@ function Set-RubrikNutanixVM Process { + if(-not $PSBoundParameters.ContainsKey('PauseBackups')) { $Resources.Body.Remove('isPaused') } $uri = New-URIString -server $Server -endpoint ($resources.URI) -id $id $uri = Test-QueryParam -querykeys ($resources.Query.Keys) -parameters ((Get-Command $function).Parameters.Values) -uri $uri diff --git a/Rubrik/Public/Set-RubrikSupportTunnel.ps1 b/Rubrik/Public/Set-RubrikSupportTunnel.ps1 index cb996727c..7f84734cd 100644 --- a/Rubrik/Public/Set-RubrikSupportTunnel.ps1 +++ b/Rubrik/Public/Set-RubrikSupportTunnel.ps1 @@ -18,24 +18,24 @@ function Set-RubrikSupportTunnel http://rubrikinc.github.io/rubrik-sdk-for-powershell/ .EXAMPLE - Set-RubrikSupportTunnel -EnableTunnel $false + Set-RubrikSupportTunnel -EnableTunnel:$false This will disable the Support Tunnel for the Rubrik cluster .EXAMPLE - Set-RubrikSupportTunnel -EnableTunnel $true + Set-RubrikSupportTunnel -EnableTunnel This will enable the Support Tunnel for the Rubrik cluster and set the inactivity timeout to infinite (no timeout) .EXAMPLE - Set-RubrikSupportTunnel -EnableTunnel $true -Timeout 100 + Set-RubrikSupportTunnel -EnableTunnel -Timeout 100 This will enable the Support Tunnel for the Rubrik cluster and set the inactivity timeout to 100 seconds #> [CmdletBinding()] Param( - # Status of the Support Tunnel. Choose $true to enable or $false to disable. + # Status of the Support Tunnel. Choose to enable or -EnableTunnel:$false to disable. [Parameter(Mandatory = $true)] [Alias('isTunnelEnabled')] - [Bool]$EnableTunnel, + [Switch]$EnableTunnel, # Tunnel inactivity timeout in seconds. Only valid when setting $EnableTunnel to $true. [Alias('inactivityTimeoutInSeconds')] [int]$Timeout, @@ -66,7 +66,7 @@ function Set-RubrikSupportTunnel } Process { - + if(-not $PSBoundParameters.ContainsKey('EnableTunnel')) { $Resources.Body.Remove('isTunnelEnabled') } $uri = New-URIString -server $Server -endpoint ($resources.URI) -id $id $uri = Test-QueryParam -querykeys ($resources.Query.Keys) -parameters ((Get-Command $function).Parameters.Values) -uri $uri $body = New-BodyString -bodykeys ($resources.Body.Keys) -parameters ((Get-Command $function).Parameters.Values) diff --git a/Rubrik/Public/Set-RubrikVM.ps1 b/Rubrik/Public/Set-RubrikVM.ps1 index 76a88c946..8838213de 100644 --- a/Rubrik/Public/Set-RubrikVM.ps1 +++ b/Rubrik/Public/Set-RubrikVM.ps1 @@ -20,6 +20,10 @@ function Set-RubrikVM Get-RubrikVM 'Server1' | Set-RubrikVM -PauseBackups This will pause backups on any virtual machine named "Server1" + .EXAMPLE + Get-RubrikVM 'Server1' | Set-RubrikVM -PauseBackups:$false + This will unpause backups on any virtual machine named "Server1" + .EXAMPLE Get-RubrikVM -SLA Platinum | Set-RubrikVM -SnapConsistency 'CRASH_CONSISTENT' -MaxNestedSnapshots 2 -UseArrayIntegration This will find all virtual machines in the Platinum SLA Domain and set their snapshot consistency to crash consistent (no application quiescence) @@ -44,10 +48,10 @@ function Set-RubrikVM [int]$MaxNestedSnapshots, # Whether to pause or resume backups/archival for this VM. [Alias('isVmPaused')] - [Bool]$PauseBackups, + [Switch]$PauseBackups, # User setting to dictate whether to use storage array snaphots for ingest. This setting only makes sense for VMs where array based ingest is possible. [Alias('isArrayIntegrationEnabled')] - [Bool]$UseArrayIntegration, + [Switch]$UseArrayIntegration, # Rubrik server IP or FQDN [String]$Server = $global:RubrikConnection.server, # API version @@ -82,7 +86,8 @@ function Set-RubrikVM $SnapConsistency = $SnapConsistency -replace 'AUTOMATIC', 'UNKNOWN' } #endregion - + if(-not $PSBoundParameters.ContainsKey('PauseBackups')) { $Resources.Body.Remove('isVmPaused') } + if(-not $PSBoundParameters.ContainsKey('UseArrayIntegration')) { $Resources.Body.Remove('isArrayIntegrationEnabled') } $uri = New-URIString -server $Server -endpoint ($resources.URI) -id $id $uri = Test-QueryParam -querykeys ($resources.Query.Keys) -parameters ((Get-Command $function).Parameters.Values) -uri $uri $body = New-BodyString -bodykeys ($resources.Body.Keys) -parameters ((Get-Command $function).Parameters.Values) diff --git a/Rubrik/Rubrik.psd1 b/Rubrik/Rubrik.psd1 index ece26f130..3eeebc25c 100755 --- a/Rubrik/Rubrik.psd1 +++ b/Rubrik/Rubrik.psd1 @@ -126,8 +126,8 @@ FunctionsToExport = @('Connect-Rubrik', 'Disconnect-Rubrik', 'Export-RubrikDatab 'Set-RubrikLogShipping', 'Set-RubrikManagedVolume', 'Set-RubrikMount', 'Set-RubrikNASShare', 'Set-RubrikNutanixVM', 'Set-RubrikSetting', 'Set-RubrikSLA', 'Set-RubrikSQLInstance', 'Set-RubrikSupportTunnel', - 'Set-RubrikUserRole', 'Set-RubrikVCD', 'Set-RubrikVCenter', - 'Set-RubrikVM', 'Set-RubrikVolumeFilterDriver', + 'Set-RubrikUser','Set-RubrikUserRole', 'Set-RubrikVCD', + 'Set-RubrikVCenter', 'Set-RubrikVM', 'Set-RubrikVolumeFilterDriver', 'Start-RubrikManagedVolumeSnapshot', 'Stop-RubrikManagedVolumeSnapshot', 'Sync-RubrikAnnotation', 'Sync-RubrikTag', 'Update-RubrikHost', 'Update-RubrikVCD', diff --git a/Tests/Export-RubrikVM.Tests.ps1 b/Tests/Export-RubrikVM.Tests.ps1 index d2a2b28db..c0da471de 100644 --- a/Tests/Export-RubrikVM.Tests.ps1 +++ b/Tests/Export-RubrikVM.Tests.ps1 @@ -19,6 +19,141 @@ Describe -Name 'Public/Export-RubrikVM' -Tag 'Public', 'Export-RubrikVM' -Fixtur } #endregion + Context -Name 'Switch Parameters' { + Mock -CommandName Test-RubrikConnection -Verifiable -ModuleName 'Rubrik' -MockWith {} + Mock -CommandName Submit-Request -Verifiable -ModuleName 'Rubrik' -MockWith {} + + It -Name 'Verify switch param - DisableNetwork:$true - Switch Param' -Test { + $Output = & { + Export-RubrikVM -id 1 -HostId 3 -DatastoreId 2 -DisableNetwork -Verbose 4>&1 + } + (-join $Output) | Should -BeLike '*disableNetwork*true*' + } + + It -Name 'Verify switch param - DisableNetwork:$false - Switch Param' -Test { + $Output = & { + Export-RubrikVM -id 1 -HostId 3 -DatastoreId 2 -DisableNetwork:$false -Verbose 4>&1 + } + (-join $Output) | Should -BeLike '*disableNetwork*false*' + } + + It -Name 'Verify switch param - No DisableNetwork - Switch Param' -Test { + $Output = & { + Export-RubrikVM -id 1 -HostId 3 -DatastoreId 2 -Verbose 4>&1 + } + (-join $Output) | Should -Not -BeLike '*disableNetwork*' + } + + It -Name 'Verify switch param - RemoveNetworkDevices:$true - Switch Param' -Test { + $Output = & { + Export-RubrikVM -id 1 -HostId 3 -DatastoreId 2 -RemoveNetworkDevices -Verbose 4>&1 + } + (-join $Output) | Should -BeLike '*RemoveNetworkDevices*true*' + } + + It -Name 'Verify switch param - RemoveNetworkDevices:$false - Switch Param' -Test { + $Output = & { + Export-RubrikVM -id 1 -HostId 3 -DatastoreId 2 -RemoveNetworkDevices:$false -Verbose 4>&1 + } + (-join $Output) | Should -BeLike '*RemoveNetworkDevices*false*' + } + + It -Name 'Verify switch param - No RemoveNetworkDevices - Switch Param' -Test { + $Output = & { + Export-RubrikVM -id 1 -HostId 3 -DatastoreId 2 -Verbose 4>&1 + } + (-join $Output) | Should -Not -BeLike '*RemoveNetworkDevices*' + } + + It -Name 'Verify switch param - KeepMACAddresses:$true - Switch Param' -Test { + $Output = & { + Export-RubrikVM -id 1 -HostId 3 -DatastoreId 2 -KeepMACAddresses -Verbose 4>&1 + } + (-join $Output) | Should -BeLike '*KeepMACAddresses*true*' + } + + It -Name 'Verify switch param - KeepMACAddresses:$false - Switch Param' -Test { + $Output = & { + Export-RubrikVM -id 1 -HostId 3 -DatastoreId 2 -KeepMACAddresses:$false -Verbose 4>&1 + } + (-join $Output) | Should -BeLike '*KeepMACAddresses*false*' + } + + It -Name 'Verify switch param - No KeepMACAddresses - Switch Param' -Test { + $Output = & { + Export-RubrikVM -id 1 -HostId 3 -DatastoreId 2 -Verbose 4>&1 + } + (-join $Output) | Should -Not -BeLike '*KeepMACAddresses*' + } + + It -Name 'Verify switch param - UnregisterVM:$true - Switch Param' -Test { + $Output = & { + Export-RubrikVM -id 1 -HostId 3 -DatastoreId 2 -UnregisterVM -Verbose 4>&1 + } + (-join $Output) | Should -BeLike '*UnregisterVM*true*' + } + + It -Name 'Verify switch param - UnregisterVM:$false - Switch Param' -Test { + $Output = & { + Export-RubrikVM -id 1 -HostId 3 -DatastoreId 2 -UnregisterVM:$false -Verbose 4>&1 + } + (-join $Output) | Should -BeLike '*UnregisterVM*false*' + } + + It -Name 'Verify switch param - No UnregisterVM - Switch Param' -Test { + $Output = & { + Export-RubrikVM -id 1 -HostId 3 -DatastoreId 2 -Verbose 4>&1 + } + (-join $Output) | Should -Not -BeLike '*UnregisterVM*' + } + + It -Name 'Verify switch param - PowerOn:$true - Switch Param' -Test { + $Output = & { + Export-RubrikVM -id 1 -HostId 3 -DatastoreId 2 -PowerOn -Verbose 4>&1 + } + (-join $Output) | Should -BeLike '*PowerOn*true*' + } + + It -Name 'Verify switch param - PowerOn:$false - Switch Param' -Test { + $Output = & { + Export-RubrikVM -id 1 -HostId 3 -DatastoreId 2 -PowerOn:$false -Verbose 4>&1 + } + (-join $Output) | Should -BeLike '*PowerOn*false*' + } + + It -Name 'Verify switch param - No PowerOn - Switch Param' -Test { + $Output = & { + Export-RubrikVM -id 1 -HostId 3 -DatastoreId 2 -Verbose 4>&1 + } + (-join $Output) | Should -Not -BeLike '*PowerOn*' + } + + It -Name 'Verify switch param - RecoverTags:$true - Switch Param' -Test { + $Output = & { + Export-RubrikVM -id 1 -HostId 3 -DatastoreId 2 -RecoverTags -Verbose 4>&1 + } + (-join $Output) | Should -BeLike '*RecoverTags*true*' + } + + It -Name 'Verify switch param - RecoverTags:$false - Switch Param' -Test { + $Output = & { + Export-RubrikVM -id 1 -HostId 3 -DatastoreId 2 -RecoverTags:$false -Verbose 4>&1 + } + (-join $Output) | Should -BeLike '*RecoverTags*false*' + } + + It -Name 'Verify switch param - No RecoverTags - Switch Param' -Test { + $Output = & { + Export-RubrikVM -id 1 -HostId 3 -DatastoreId 2 -Verbose 4>&1 + } + (-join $Output) | Should -Not -BeLike '*RecoverTags*' + } + + Assert-VerifiableMock + Assert-MockCalled -CommandName Test-RubrikConnection -ModuleName 'Rubrik' -Times 18 + Assert-MockCalled -CommandName Submit-Request -ModuleName 'Rubrik' -Times 18 + } + Context -Name 'Parameters' { Mock -CommandName Test-RubrikConnection -Verifiable -ModuleName 'Rubrik' -MockWith {} Mock -CommandName Submit-Request -Verifiable -ModuleName 'Rubrik' -MockWith { diff --git a/Tests/Get-RubrikEvent.Tests.ps1 b/Tests/Get-RubrikEvent.Tests.ps1 index c9ac65373..9d4642234 100644 --- a/Tests/Get-RubrikEvent.Tests.ps1 +++ b/Tests/Get-RubrikEvent.Tests.ps1 @@ -66,8 +66,50 @@ Describe -Name 'Public/Get-RubrikEvent' -Tag 'Public', 'Get-RubrikEvent' -Fixtur Should -BeOfType DateTime } + It -Name 'Verify switch param - ShowOnlyLatest:$true - Switch Param' -Test { + $Output = & { + Get-RubrikEvent -ShowOnlyLatest -Verbose 4>&1 + } + (-join $Output) | Should -BeLike '*show_only_latest=true*' + } + + It -Name 'Verify switch param - ShowOnlyLatest:$false - Switch Param' -Test { + $Output = & { + Get-RubrikEvent -ShowOnlyLatest:$false -Verbose 4>&1 + } + (-join $Output) | Should -BeLike '*show_only_latest=false*' + } + + It -Name 'Verify switch param - No ShowOnlyLatest - Switch Param' -Test { + $Output = & { + Get-RubrikEvent -Verbose 4>&1 + } + (-join $Output) | Should -Not -BeLike '*show_only_latest=' + } + + It -Name 'Verify switch param - FilterOnlyOnLatest:$true - Switch Param' -Test { + $Output = & { + Get-RubrikEvent -FilterOnlyOnLatest -Verbose 4>&1 + } + (-join $Output) | Should -BeLike '*filter_only_on_latest=true*' + } + + It -Name 'Verify switch param - FilterOnlyOnLatest:$false - Switch Param' -Test { + $Output = & { + Get-RubrikEvent -FilterOnlyOnLatest:$false -Verbose 4>&1 + } + (-join $Output) | Should -BeLike '*filter_only_on_latest=false*' + } + + It -Name 'Verify switch param - No FilterOnlyOnLatest - Switch Param' -Test { + $Output = & { + Get-RubrikEvent -Verbose 4>&1 + } + (-join $Output) | Should -Not -BeLike '*filter_only_on_latest=' + } + Assert-VerifiableMock - Assert-MockCalled -CommandName Test-RubrikConnection -ModuleName 'Rubrik' -Exactly 2 - Assert-MockCalled -CommandName Submit-Request -ModuleName 'Rubrik' -Exactly 2 + Assert-MockCalled -CommandName Test-RubrikConnection -ModuleName 'Rubrik' -Exactly 8 + Assert-MockCalled -CommandName Submit-Request -ModuleName 'Rubrik' -Exactly 8 } } diff --git a/Tests/Get-RubrikOrganization.Tests.ps1 b/Tests/Get-RubrikOrganization.Tests.ps1 index 9f408baf7..5de7fd849 100644 --- a/Tests/Get-RubrikOrganization.Tests.ps1 +++ b/Tests/Get-RubrikOrganization.Tests.ps1 @@ -64,9 +64,31 @@ Describe -Name 'Public/Get-RubrikOrganization' -Tag 'Public', 'Get-RubrikOrganiz (Get-RubrikOrganization -Name 'nonexistant').count | Should -BeExactly 0 } + + It -Name 'Verify switch param - isGlobal:$true - Switch Param' -Test { + $Output = & { + Get-RubrikOrganization -isGlobal -Verbose 4>&1 + } + (-join $Output) | Should -BeLike '*is_global=True*' + } + + It -Name 'Verify switch param - isGlobal:$false - Switch Param' -Test { + $Output = & { + Get-RubrikOrganization -isGlobal:$false -Verbose 4>&1 + } + (-join $Output) | Should -BeLike '*is_global=False*' + } + + It -Name 'Verify switch param - No isGlobal - Switch Param' -Test { + $Output = & { + Get-RubrikOrganization -Verbose 4>&1 + } + (-join $Output) | Should -Not -BeLike '*isGlobal*' + } + Assert-VerifiableMock - Assert-MockCalled -CommandName Test-RubrikConnection -ModuleName 'Rubrik' -Times 1 - Assert-MockCalled -CommandName Submit-Request -ModuleName 'Rubrik' -Times 4 + Assert-MockCalled -CommandName Test-RubrikConnection -ModuleName 'Rubrik' -Exactly 7 + Assert-MockCalled -CommandName Submit-Request -ModuleName 'Rubrik' -Exactly 7 } Context -Name 'Parameter Validation' { It -Name 'Name Missing' -Test { @@ -77,9 +99,5 @@ Describe -Name 'Public/Get-RubrikOrganization' -Tag 'Public', 'Get-RubrikOrganiz { Get-RubrikOrganization -id } | Should -Throw "Missing an argument for parameter 'ID'. Specify a parameter of type 'System.String' and try again." } - It -Name 'isGlobal must be Boolean' -Test { - { Get-RubrikOrganization -isGlobal 'notabool' } | - Should -Throw "Cannot process argument transformation on parameter 'isGlobal'. " - } } } \ No newline at end of file diff --git a/Tests/New-RubrikMount.Tests.ps1 b/Tests/New-RubrikMount.Tests.ps1 index aedd26a8e..b4f0d651b 100644 --- a/Tests/New-RubrikMount.Tests.ps1 +++ b/Tests/New-RubrikMount.Tests.ps1 @@ -34,6 +34,69 @@ Describe -Name 'Public/New-RubrikMount' -Tag 'Public', 'New-RubrikMount' -Fixtur Should -BeExactly 'QUEUED' } + It -Name 'Verify switch param - DisableNetwork:$true - Switch Param' -Test { + $Output = & { + New-RubrikMount -Id 'snapshotid' -DisableNetwork -Verbose 4>&1 + } + (-join $Output) | Should -BeLike '*disableNetwork*true*' + } + + It -Name 'Verify switch param - DisableNetwork:$false - Switch Param' -Test { + $Output = & { + New-RubrikMount -Id 'snapshotid' -DisableNetwork:$false -Verbose 4>&1 + } + (-join $Output) | Should -BeLike '*disableNetwork*false*' + } + + It -Name 'Verify switch param - No DisableNetwork - Switch Param' -Test { + $Output = & { + New-RubrikMount -Id 'snapshotid' -Verbose 4>&1 + } + (-join $Output) | Should -Not -BeLike '*disableNetwork*' + } + + It -Name 'Verify switch param - RemoveNetworkDevices:$true - Switch Param' -Test { + $Output = & { + New-RubrikMount -Id 'snapshotid' -RemoveNetworkDevices -Verbose 4>&1 + } + (-join $Output) | Should -BeLike '*RemoveNetworkDevices*true*' + } + + It -Name 'Verify switch param - RemoveNetworkDevices:$false - Switch Param' -Test { + $Output = & { + New-RubrikMount -Id 'snapshotid' -RemoveNetworkDevices:$false -Verbose 4>&1 + } + (-join $Output) | Should -BeLike '*RemoveNetworkDevices*false*' + } + + It -Name 'Verify switch param - No RemoveNetworkDevices - Switch Param' -Test { + $Output = & { + New-RubrikMount -Id 'snapshotid' -Verbose 4>&1 + } + (-join $Output) | Should -Not -BeLike '*RemoveNetworkDevices*' + } + + It -Name 'Verify switch param - PowerOn:$true - Switch Param' -Test { + $Output = & { + New-RubrikMount -Id 'snapshotid' -PowerOn -Verbose 4>&1 + } + (-join $Output) | Should -BeLike '*PowerOn*true*' + } + + It -Name 'Verify switch param - PowerOn:$false - Switch Param' -Test { + $Output = & { + New-RubrikMount -Id 'snapshotid' -PowerOn:$false -Verbose 4>&1 + } + (-join $Output) | Should -BeLike '*PowerOn*false*' + } + + It -Name 'Verify switch param - No PowerOn - Switch Param' -Test { + $Output = & { + New-RubrikMount -Id 'snapshotid' -Verbose 4>&1 + } + (-join $Output) | Should -Not -BeLike '*PowerOn*' + } + It -Name 'Parameter id is missing' -Test { { New-RubrikMount -Id } | Should -Throw "Missing an argument for parameter 'Id'. Specify a parameter of type 'System.String' and try again." @@ -42,20 +105,9 @@ Describe -Name 'Public/New-RubrikMount' -Tag 'Public', 'New-RubrikMount' -Fixtur { New-RubrikMount -id '' } | Should -Throw "Cannot bind argument to parameter 'Id' because it is an empty string." } - It -Name 'Validate Disable Network Boolean' -Test { - { New-RubrikMount -id 'id' -DisableNetwork yes } | - Should -Throw "Cannot process argument transformation on parameter 'DisableNetwork'. Cannot convert value `"System.String`" to type `"System.Boolean`"." - } - It -Name 'Validate Remove Network Devices Boolean' -Test { - { New-RubrikMount -id 'id' -RemoveNetworkDevices yes } | - Should -Throw "Cannot process argument transformation on parameter 'RemoveNetworkDevices'. Cannot convert value `"System.String`" to type `"System.Boolean`"." - } - It -Name 'Validate PowerOn Boolean' -Test { - { New-RubrikMount -id 'id' -PowerOn yes } | - Should -Throw "Cannot process argument transformation on parameter 'PowerOn'. Cannot convert value `"System.String`" to type `"System.Boolean`"." - } + Assert-VerifiableMock - Assert-MockCalled -CommandName Test-RubrikConnection -ModuleName 'Rubrik' -Exactly 1 - Assert-MockCalled -CommandName Submit-Request -ModuleName 'Rubrik' -Exactly 1 + Assert-MockCalled -CommandName Test-RubrikConnection -ModuleName 'Rubrik' -Exactly 10 + Assert-MockCalled -CommandName Submit-Request -ModuleName 'Rubrik' -Exactly 10 } } \ No newline at end of file diff --git a/Tests/Set-RubrikMount.Tests.ps1 b/Tests/Set-RubrikMount.Tests.ps1 index da7a65fb0..70f03118a 100644 --- a/Tests/Set-RubrikMount.Tests.ps1 +++ b/Tests/Set-RubrikMount.Tests.ps1 @@ -31,9 +31,31 @@ Describe -Name 'Public/Set-RubrikMount' -Tag 'Public', 'Set-RubrikMount' -Fixtur } } It -Name 'Should return poweredOff status' -Test { - (Set-RubrikMount -id '11-22-33' -PowerOn $false).powerStatus | + (Set-RubrikMount -id '11-22-33' -PowerOn:$false).powerStatus | Should -BeExactly 'poweredOff' } + + It -Name 'Verify switch param - PowerOn:$true - Switch Param' -Test { + $Output = & { + Set-RubrikMount -id '11-22-33' -PowerOn -Verbose 4>&1 + } + (-join $Output) | Should -BeLike '*powerStatus*true*' + } + + It -Name 'Verify switch param - PowerOn:$false - Switch Param' -Test { + $Output = & { + Set-RubrikMount -id '11-22-33' -PowerOn:$false -Verbose 4>&1 + } + (-join $Output) | Should -BeLike '*powerStatus*false*' + } + + It -Name 'Verify switch param - No PowerOn - Switch Param' -Test { + $Output = & { + Set-RubrikMount -id '11-22-33' -Verbose 4>&1 + } + (-join $Output) | Should -Not -BeLike '*powerStatus*' + } + It -Name 'Parameter ID cannot be $null' -Test { { Set-RubrikMount -Id $null } | Should -Throw "Cannot bind argument to parameter 'id' because it is an empty string." @@ -42,12 +64,8 @@ Describe -Name 'Public/Set-RubrikMount' -Tag 'Public', 'Set-RubrikMount' -Fixtur { Set-RubrikMount -Id '' } | Should -Throw "Cannot bind argument to parameter 'id' because it is an empty string." } - It -Name 'Validate PowerOn Boolean' -Test { - { Set-RubrikMount -id 'id' -PowerOn yes } | - Should -Throw "Cannot process argument transformation on parameter 'PowerOn'. Cannot convert value `"System.String`" to type `"System.Boolean`"." - } Assert-VerifiableMock - Assert-MockCalled -CommandName Test-RubrikConnection -ModuleName 'Rubrik' -Exactly 1 - Assert-MockCalled -CommandName Submit-Request -ModuleName 'Rubrik' -Exactly 1 + Assert-MockCalled -CommandName Test-RubrikConnection -ModuleName 'Rubrik' -Exactly 4 + Assert-MockCalled -CommandName Submit-Request -ModuleName 'Rubrik' -Exactly 4 } } \ No newline at end of file diff --git a/Tests/Set-RubrikNutanixVM.Tests.ps1 b/Tests/Set-RubrikNutanixVM.Tests.ps1 index d73c8fcd4..6f24a4e0e 100644 --- a/Tests/Set-RubrikNutanixVM.Tests.ps1 +++ b/Tests/Set-RubrikNutanixVM.Tests.ps1 @@ -25,16 +25,38 @@ Describe -Name 'Public/Set-RubrikNutanixVM' -Tag 'Public', 'Set-RubrikNutanixVM' Mock -CommandName Submit-Request -Verifiable -ModuleName 'Rubrik' -MockWith { @{ 'id' = 'NutanixVirtualMachine:::aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee-vm-ffffffff-0000-1111-2222-333333333333' - 'isVmPaused' = $true + 'isPaused' = $true } } It -Name 'Should set PauseBackups' -Test { - ( Set-RubrikNutanixVM -id 'NutanixVirtualMachine:::aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee-vm-ffffffff-0000-1111-2222-333333333333' -PauseBackups $true).isVmPaused | + ( Set-RubrikNutanixVM -id 'NutanixVirtualMachine:::aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee-vm-ffffffff-0000-1111-2222-333333333333' -PauseBackups).isPaused | Should -BeExactly $true } + + It -Name 'Verify switch param - PauseBackups:$true - Switch Param' -Test { + $Output = & { + Set-RubrikNutanixVM -id 'NutanixVirtualMachine:::aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee-vm-ffffffff-0000-1111-2222-333333333333' -PauseBackups -Verbose 4>&1 + } + (-join $Output) | Should -BeLike '*isPaused*true*' + } + + It -Name 'Verify switch param - PauseBackups:$false - Switch Param' -Test { + $Output = & { + Set-RubrikNutanixVM -id 'NutanixVirtualMachine:::aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee-vm-ffffffff-0000-1111-2222-333333333333' -PauseBackups:$false -Verbose 4>&1 + } + (-join $Output) | Should -BeLike '*isPaused*false*' + } + + It -Name 'Verify switch param - No PauseBackups - Switch Param' -Test { + $Output = & { + Set-RubrikNutanixVM -id 'NutanixVirtualMachine:::aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee-vm-ffffffff-0000-1111-2222-333333333333' -Verbose 4>&1 + } + (-join $Output) | Should -Not -BeLike '*isPaused*' + } + Assert-VerifiableMock - Assert-MockCalled -CommandName Test-RubrikConnection -ModuleName 'Rubrik' -Times 1 - Assert-MockCalled -CommandName Submit-Request -ModuleName 'Rubrik' -Times 1 + Assert-MockCalled -CommandName Test-RubrikConnection -ModuleName 'Rubrik' -Exactly 4 + Assert-MockCalled -CommandName Submit-Request -ModuleName 'Rubrik' -Exactly 4 } Context -Name 'Parameter/SnapConsistency' { @@ -49,9 +71,10 @@ Describe -Name 'Public/Set-RubrikNutanixVM' -Tag 'Public', 'Set-RubrikNutanixVM' ( Set-RubrikNutanixVM -id 'NutanixVirtualMachine:::aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee-vm-ffffffff-0000-1111-2222-333333333333' -SnapConsistency 'CRASH_CONSISTENT').snapshotConsistencyMandate | Should -BeExactly 'CRASH_CONSISTENT' } + Assert-VerifiableMock - Assert-MockCalled -CommandName Test-RubrikConnection -ModuleName 'Rubrik' -Times 1 - Assert-MockCalled -CommandName Submit-Request -ModuleName 'Rubrik' -Times 1 + Assert-MockCalled -CommandName Test-RubrikConnection -ModuleName 'Rubrik' -Exactly 1 + Assert-MockCalled -CommandName Submit-Request -ModuleName 'Rubrik' -Exactly 1 } Context -Name 'Parameter Validation' { diff --git a/Tests/Set-RubrikSupportTunnel.Tests.ps1 b/Tests/Set-RubrikSupportTunnel.Tests.ps1 index 3e5a31943..e88d7e82d 100644 --- a/Tests/Set-RubrikSupportTunnel.Tests.ps1 +++ b/Tests/Set-RubrikSupportTunnel.Tests.ps1 @@ -29,19 +29,26 @@ Describe -Name 'Public/Set-RubrikSupportTunnel' -Tag 'Public', 'Set-RubrikSuppor } } It -Name 'Enabling Tunnel' -Test { - (Set-RubrikSupportTunnel -EnableTunnel $true).isTunnelEnabled | + (Set-RubrikSupportTunnel -EnableTunnel).isTunnelEnabled | Should -BeExactly 'True' } - It -Name 'Parameter EnableTunnel cannot be $null' -Test { - { Set-RubrikSupportTunnel -EnableTunnel $null } | - Should -Throw "Cannot process argument transformation on parameter 'EnableTunnel'. Cannot convert value `"`" to type `"System.Boolean`". Boolean parameters accept only Boolean values and numbers, such as `$True, `$False, 1 or 0." + + It -Name 'Verify switch param - EnableTunnel:$true - Switch Param' -Test { + $Output = & { + Set-RubrikSupportTunnel -EnableTunnel -Verbose 4>&1 + } + (-join $Output) | Should -BeLike '*isTunnelEnabled*true*' } - It -Name 'Parameter EnableTunnel must be specified' -Test { - { Set-RubrikSupportTunnel -EnableTunnel } | - Should -Throw "Missing an argument for parameter 'EnableTunnel'. Specify a parameter of type 'System.Boolean' and try again." + + It -Name 'Verify switch param - EnableTunnel:$false - Switch Param' -Test { + $Output = & { + Set-RubrikSupportTunnel -EnableTunnel:$false -Verbose 4>&1 + } + (-join $Output) | Should -BeLike '*isTunnelEnabled*false*' } + Assert-VerifiableMock - Assert-MockCalled -CommandName Test-RubrikConnection -ModuleName 'Rubrik' -Exactly 1 - Assert-MockCalled -CommandName Submit-Request -ModuleName 'Rubrik' -Exactly 1 + Assert-MockCalled -CommandName Test-RubrikConnection -ModuleName 'Rubrik' -Exactly 3 + Assert-MockCalled -CommandName Submit-Request -ModuleName 'Rubrik' -Exactly 3 } } \ No newline at end of file diff --git a/Tests/Set-RubrikVM.Tests.ps1 b/Tests/Set-RubrikVM.Tests.ps1 index 374657c3b..01c0eaa87 100644 --- a/Tests/Set-RubrikVM.Tests.ps1 +++ b/Tests/Set-RubrikVM.Tests.ps1 @@ -28,13 +28,36 @@ Describe -Name 'Public/Set-RubrikVM' -Tag 'Public', 'Set-RubrikVM' -Fixture { 'isVmPaused' = $true } } + It -Name 'Should set PauseBackups' -Test { - ( Set-RubrikVM -id 'VirtualMachine:::aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee-vm-12345' -PauseBackups $true).isVmPaused | + ( Set-RubrikVM -id 'VirtualMachine:::aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee-vm-12345' -PauseBackups ).isVmPaused | Should -BeExactly $true } + + It -Name 'Verify switch param - PauseBackups:$true - Switch Param' -Test { + $Output = & { + Set-RubrikVM -id 'VirtualMachine:::aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee-vm-12345' -PauseBackups -Verbose 4>&1 + } + (-join $Output) | Should -BeLike '*isVmPaused*true*' + } + + It -Name 'Verify switch param - PauseBackups:$false - Switch Param' -Test { + $Output = & { + Set-RubrikVM -id 'VirtualMachine:::aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee-vm-12345' -PauseBackups:$false -Verbose 4>&1 + } + (-join $Output) | Should -BeLike '*isVmPaused*false*' + } + + It -Name 'Verify switch param - No PauseBackups - Switch Param' -Test { + $Output = & { + Set-RubrikVM -id 'VirtualMachine:::aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee-vm-12345' -Verbose 4>&1 + } + (-join $Output) | Should -Not -BeLike '*isVmPaused*' + } + Assert-VerifiableMock - Assert-MockCalled -CommandName Test-RubrikConnection -ModuleName 'Rubrik' -Times 1 - Assert-MockCalled -CommandName Submit-Request -ModuleName 'Rubrik' -Times 1 + Assert-MockCalled -CommandName Test-RubrikConnection -ModuleName 'Rubrik' -Exactly 4 + Assert-MockCalled -CommandName Submit-Request -ModuleName 'Rubrik' -Exactly 4 } Context -Name 'Parameter/SnapConsistency' { @@ -50,8 +73,8 @@ Describe -Name 'Public/Set-RubrikVM' -Tag 'Public', 'Set-RubrikVM' -Fixture { Should -BeExactly 'CRASH_CONSISTENT' } Assert-VerifiableMock - Assert-MockCalled -CommandName Test-RubrikConnection -ModuleName 'Rubrik' -Times 1 - Assert-MockCalled -CommandName Submit-Request -ModuleName 'Rubrik' -Times 1 + Assert-MockCalled -CommandName Test-RubrikConnection -ModuleName 'Rubrik' -Exactly 1 + Assert-MockCalled -CommandName Submit-Request -ModuleName 'Rubrik' -Exactly 1 } Context -Name 'Parameter Validation' {