2013-12-25 01:09:22 -05:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
2018-01-22 19:03:49 -05:00
|
|
|
"context"
|
2013-12-25 01:09:22 -05:00
|
|
|
"testing"
|
|
|
|
|
2018-01-19 19:18:44 -05:00
|
|
|
"github.com/hashicorp/packer/helper/multistep"
|
2013-12-25 01:09:22 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestStepCompactDisk_impl(t *testing.T) {
|
|
|
|
var _ multistep.Step = new(StepCompactDisk)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStepCompactDisk(t *testing.T) {
|
|
|
|
state := testState(t)
|
|
|
|
step := new(StepCompactDisk)
|
|
|
|
|
2018-05-16 08:10:33 -04:00
|
|
|
diskFullPaths := []string{"foo"}
|
|
|
|
state.Put("disk_full_paths", diskFullPaths)
|
2013-12-25 01:09:22 -05:00
|
|
|
|
|
|
|
driver := state.Get("driver").(*DriverMock)
|
|
|
|
|
|
|
|
// Test the run
|
2018-01-22 19:03:49 -05:00
|
|
|
if action := step.Run(context.Background(), state); action != multistep.ActionContinue {
|
2013-12-25 01:09:22 -05:00
|
|
|
t.Fatalf("bad action: %#v", action)
|
|
|
|
}
|
|
|
|
if _, ok := state.GetOk("error"); ok {
|
|
|
|
t.Fatal("should NOT have error")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test the driver
|
|
|
|
if !driver.CompactDiskCalled {
|
|
|
|
t.Fatal("should've called")
|
|
|
|
}
|
2018-05-16 08:10:33 -04:00
|
|
|
if driver.CompactDiskPath != "foo" {
|
2013-12-25 01:09:22 -05:00
|
|
|
t.Fatal("should call with right path")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStepCompactDisk_skip(t *testing.T) {
|
|
|
|
state := testState(t)
|
|
|
|
step := new(StepCompactDisk)
|
|
|
|
step.Skip = true
|
|
|
|
|
2018-04-27 15:09:19 -04:00
|
|
|
diskFullPaths := []string{"foo"}
|
|
|
|
state.Put("disk_full_paths", diskFullPaths)
|
2013-12-25 01:09:22 -05:00
|
|
|
|
|
|
|
driver := state.Get("driver").(*DriverMock)
|
|
|
|
|
|
|
|
// Test the run
|
2018-01-22 19:03:49 -05:00
|
|
|
if action := step.Run(context.Background(), state); action != multistep.ActionContinue {
|
2013-12-25 01:09:22 -05:00
|
|
|
t.Fatalf("bad action: %#v", action)
|
|
|
|
}
|
|
|
|
if _, ok := state.GetOk("error"); ok {
|
|
|
|
t.Fatal("should NOT have error")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test the driver
|
|
|
|
if driver.CompactDiskCalled {
|
|
|
|
t.Fatal("should not have called")
|
|
|
|
}
|
|
|
|
}
|