Tests for func to move VHDs to output dir when skip_export: true

This commit is contained in:
DanHam 2018-07-08 17:12:51 +01:00
parent 32148168bd
commit 0a4ec13323
No known key found for this signature in database
GPG Key ID: 58E79AEDD6AA987E
2 changed files with 33 additions and 11 deletions

View File

@ -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

View File

@ -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")