23c947acf0
The new flow: 1) Provision the instance 2) Tear down the instance, but keep the boot disk 3) Create an image from the disk 4) Tear down the disk The step to update gcloud is no longer needed, since gceimagebundle isn't used anymore. Fixes #1507 and addresses https://github.com/mitchellh/packer/issues/1447#issuecomment-61610235.
75 lines
1.7 KiB
Go
75 lines
1.7 KiB
Go
package googlecompute
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
|
|
"github.com/mitchellh/multistep"
|
|
)
|
|
|
|
func TestStepCreateImage_impl(t *testing.T) {
|
|
var _ multistep.Step = new(StepCreateImage)
|
|
}
|
|
|
|
func TestStepCreateImage(t *testing.T) {
|
|
state := testState(t)
|
|
step := new(StepCreateImage)
|
|
defer step.Cleanup(state)
|
|
|
|
config := state.Get("config").(*Config)
|
|
driver := state.Get("driver").(*DriverMock)
|
|
|
|
// run the step
|
|
if action := step.Run(state); action != multistep.ActionContinue {
|
|
t.Fatalf("bad action: %#v", action)
|
|
}
|
|
|
|
// Verify state
|
|
if driver.CreateImageName != config.ImageName {
|
|
t.Fatalf("bad: %#v", driver.CreateImageName)
|
|
}
|
|
if driver.CreateImageDesc != config.ImageDescription {
|
|
t.Fatalf("bad: %#v", driver.CreateImageDesc)
|
|
}
|
|
if driver.CreateImageZone != config.Zone {
|
|
t.Fatalf("bad: %#v", driver.CreateImageZone)
|
|
}
|
|
if driver.CreateImageDisk != config.DiskName {
|
|
t.Fatalf("bad: %#v", driver.CreateImageDisk)
|
|
}
|
|
|
|
nameRaw, ok := state.GetOk("image_name")
|
|
if !ok {
|
|
t.Fatal("should have name")
|
|
}
|
|
if name, ok := nameRaw.(string); !ok {
|
|
t.Fatal("name is not a string")
|
|
} else if name != config.ImageName {
|
|
t.Fatalf("bad name: %s", name)
|
|
}
|
|
}
|
|
|
|
func TestStepCreateImage_errorOnChannel(t *testing.T) {
|
|
state := testState(t)
|
|
step := new(StepCreateImage)
|
|
defer step.Cleanup(state)
|
|
|
|
errCh := make(chan error, 1)
|
|
errCh <- errors.New("error")
|
|
|
|
driver := state.Get("driver").(*DriverMock)
|
|
driver.CreateImageErrCh = errCh
|
|
|
|
// run the step
|
|
if action := step.Run(state); action != multistep.ActionHalt {
|
|
t.Fatalf("bad action: %#v", action)
|
|
}
|
|
|
|
if _, ok := state.GetOk("error"); !ok {
|
|
t.Fatal("should have error")
|
|
}
|
|
if _, ok := state.GetOk("image_name"); ok {
|
|
t.Fatal("should NOT have image")
|
|
}
|
|
}
|