Fix test - reporting compaction results requires a tmp file
This commit is contained in:
parent
08f9d619a9
commit
f342975ff3
|
@ -2,6 +2,8 @@ package common
|
|||
|
||||
import (
|
||||
"context"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/packer/helper/multistep"
|
||||
|
@ -15,8 +17,25 @@ func TestStepCompactDisk(t *testing.T) {
|
|||
state := testState(t)
|
||||
step := new(StepCompactDisk)
|
||||
|
||||
diskPaths := []string{"foo"}
|
||||
state.Put("disk_full_paths", diskPaths)
|
||||
// Create a fake vmdk file for disk file size operations
|
||||
diskFile, err := ioutil.TempFile("", "disk.vmdk")
|
||||
if err != nil {
|
||||
t.Fatalf("Error creating fake vmdk file: %s", err)
|
||||
}
|
||||
|
||||
diskPath := diskFile.Name()
|
||||
defer os.Remove(diskPath)
|
||||
|
||||
content := []byte("I am the fake vmdk's contents")
|
||||
if _, err := diskFile.Write(content); err != nil {
|
||||
t.Fatalf("Error writing to fake vmdk file: %s", err)
|
||||
}
|
||||
if err := diskFile.Close(); err != nil {
|
||||
t.Fatalf("Error closing fake vmdk file: %s", err)
|
||||
}
|
||||
|
||||
// Set up required state
|
||||
state.Put("disk_full_paths", []string{diskPath})
|
||||
|
||||
driver := state.Get("driver").(*DriverMock)
|
||||
|
||||
|
@ -32,7 +51,7 @@ func TestStepCompactDisk(t *testing.T) {
|
|||
if !driver.CompactDiskCalled {
|
||||
t.Fatal("should've called")
|
||||
}
|
||||
if driver.CompactDiskPath != "foo" {
|
||||
if driver.CompactDiskPath != diskPath {
|
||||
t.Fatal("should call with right path")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue