diff --git a/builder/hyperv/common/driver_mock.go b/builder/hyperv/common/driver_mock.go index 35dc5ced1..e3ddada15 100644 --- a/builder/hyperv/common/driver_mock.go +++ b/builder/hyperv/common/driver_mock.go @@ -190,6 +190,11 @@ type DriverMock struct { PreserveLegacyExportBehaviour_DstPath string PreserveLegacyExportBehaviour_Err error + MoveCreatedVHDsToOutputDir_Called bool + MoveCreatedVHDsToOutputDir_SrcPath string + MoveCreatedVHDsToOutputDir_DstPath string + MoveCreatedVHDsToOutputDir_Err error + CompactDisks_Called bool CompactDisks_Path string CompactDisks_Result string @@ -492,6 +497,13 @@ func (d *DriverMock) PreserveLegacyExportBehaviour(srcPath string, dstPath strin return d.PreserveLegacyExportBehaviour_Err } +func (d *DriverMock) MoveCreatedVHDsToOutputDir(srcPath string, dstPath string) error { + d.MoveCreatedVHDsToOutputDir_Called = true + d.MoveCreatedVHDsToOutputDir_SrcPath = srcPath + d.MoveCreatedVHDsToOutputDir_DstPath = dstPath + return d.MoveCreatedVHDsToOutputDir_Err +} + func (d *DriverMock) CompactDisks(path string) (result string, err error) { d.CompactDisks_Called = true d.CompactDisks_Path = path diff --git a/builder/hyperv/common/step_collate_artifacts_test.go b/builder/hyperv/common/step_collate_artifacts_test.go index d138fb87d..4892e76e8 100644 --- a/builder/hyperv/common/step_collate_artifacts_test.go +++ b/builder/hyperv/common/step_collate_artifacts_test.go @@ -46,18 +46,20 @@ func TestStepCollateArtifacts_exportedArtifacts(t *testing.T) { driver.PreserveLegacyExportBehaviour_DstPath, step.OutputDir) } - // TODO: Create MoveCreatedVHDsToOutput func etc - // if driver.MoveCreatedVHDsToOutput_Called { - // t.Fatal("Should NOT have called MoveCreatedVHDsToOutput") - // } + // Should only be called when skip_export is true + if driver.MoveCreatedVHDsToOutputDir_Called { + t.Fatal("Should NOT have called MoveCreatedVHDsToOutputDir") + } } -func TestStepCollateArtifacts_skipExportedArtifacts(t *testing.T) { +func TestStepCollateArtifacts_skipExportArtifacts(t *testing.T) { state := testState(t) step := new(StepCollateArtifacts) - // TODO: Needs the path to the main output directory - // outputDir := "foopath" + // Needs the path to the main output directory and build directory + step.OutputDir = "foopath" + packerTempDir := "fooBuildPath" + state.Put("packerTempDir", packerTempDir) // Export has been skipped step.SkipExport = true @@ -71,10 +73,18 @@ func TestStepCollateArtifacts_skipExportedArtifacts(t *testing.T) { t.Fatal("Should NOT have error") } - // TODO: Create MoveCreatedVHDsToOutput func etc - // if !driver.MoveCreatedVHDsToOutput_Called { - // t.Fatal("Should have called MoveCreatedVHDsToOutput") - // } + // Test the driver + if !driver.MoveCreatedVHDsToOutputDir_Called { + t.Fatal("Should have called MoveCreatedVHDsToOutputDir") + } + if driver.MoveCreatedVHDsToOutputDir_SrcPath != packerTempDir { + t.Fatalf("Should call with correct srcPath. Got: %s Wanted: %s", + driver.MoveCreatedVHDsToOutputDir_SrcPath, packerTempDir) + } + if driver.MoveCreatedVHDsToOutputDir_DstPath != step.OutputDir { + t.Fatalf("Should call with correct dstPath. Got: %s Wanted: %s", + driver.MoveCreatedVHDsToOutputDir_DstPath, step.OutputDir) + } if driver.PreserveLegacyExportBehaviour_Called { t.Fatal("Should NOT have called PreserveLegacyExportBehaviour")