Skip to content

Commit

Permalink
Merge pull request #64 from ebjornset/feature_disable_automatic_snaps…
Browse files Browse the repository at this point in the history
…hots

Disable automatic snapshots
  • Loading branch information
smurawski authored Mar 20, 2019
2 parents f234df7 + 9de9e82 commit c8edb62
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
41 changes: 41 additions & 0 deletions spec/support/hyperv.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,44 @@ Describe "New-KitchenVM with StaticMacAddress" {
}
}
}

Describe "New-KitchenVM handling of AutomaticCheckpointsEnabled" {
function New-VM {}
function Set-VM {param ($Name, $AutomaticCheckpointsEnabled)}
function Set-VMMemory {}
function Set-VMNetworkAdapter {}
function Start-VM {}
function Get-Command {param ($Name)}

Mock New-VM
Mock Set-VM
Mock Set-VMMemory
Mock Set-VMNetworkAdapter
Mock Start-VM

Context "When AutomaticCheckpointsEnabled is supported by Set-VM" {
Mock Get-Command -ParameterFilter { $Name -eq "Set-VM" } -MockWith {@{Parameters = @{AutomaticCheckpointsEnabled = "dummy"}}}

New-KitchenVM

It "Should set AutomaticCheckpointsEnabled to false for the VM" {
Assert-MockCalled Set-VM -Exactly 1 -ParameterFilter {
$Name -eq $VM.VMName -and
$AutomaticCheckpointsEnabled -eq $false
}
}
}

Context "When AutomaticCheckpointsEnabled is unsupported by Set-VM" {
Mock Get-Command -ParameterFilter { $Name -eq "Set-VM" } -MockWith {@{Parameters = @{}}}

New-KitchenVM

It "Should not set AutomaticCheckpointsEnabled for the VM" {
Assert-MockCalled Set-VM -Exactly 0 -ParameterFilter {
$Name -eq $VM.VMName -and
$AutomaticCheckpointsEnabled -eq $false
}
}
}
}
3 changes: 3 additions & 0 deletions support/hyperv.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ function New-KitchenVM {
if ($DisableSecureBoot -and ($Generation -eq 2) -and (Get-command Set-VMFirmware -ErrorAction SilentlyContinue)) {
Set-VMFirmware -VM $vm -EnableSecureBoot Off
}
if ((Get-Command -Name Set-Vm).Parameters["AutomaticCheckpointsEnabled"]) {
Set-VM -Name $vm.VMName -AutomaticCheckpointsEnabled $false
}
$vm | Start-Vm -passthru |
foreach {
$vm = $_
Expand Down

0 comments on commit c8edb62

Please sign in to comment.