Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable automatic snapshots #64

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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