2013-12-13 21:26:00 -05:00
|
|
|
package googlecompute
|
|
|
|
|
|
|
|
import (
|
2014-11-24 11:36:14 -05:00
|
|
|
"errors"
|
2013-12-13 21:26:00 -05:00
|
|
|
"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)
|
|
|
|
|
2014-11-24 11:36:14 -05:00
|
|
|
config := state.Get("config").(*Config)
|
|
|
|
driver := state.Get("driver").(*DriverMock)
|
2013-12-13 21:26:00 -05:00
|
|
|
|
|
|
|
// run the step
|
|
|
|
if action := step.Run(state); action != multistep.ActionContinue {
|
|
|
|
t.Fatalf("bad action: %#v", action)
|
|
|
|
}
|
|
|
|
|
2014-11-24 11:36:14 -05:00
|
|
|
// Verify state
|
|
|
|
if driver.CreateImageName != config.ImageName {
|
|
|
|
t.Fatalf("bad: %#v", driver.CreateImageName)
|
|
|
|
}
|
|
|
|
if driver.CreateImageDesc != config.ImageDescription {
|
|
|
|
t.Fatalf("bad: %#v", driver.CreateImageDesc)
|
2013-12-13 21:26:00 -05:00
|
|
|
}
|
2014-11-24 11:36:14 -05:00
|
|
|
if driver.CreateImageZone != config.Zone {
|
|
|
|
t.Fatalf("bad: %#v", driver.CreateImageZone)
|
2013-12-13 21:26:00 -05:00
|
|
|
}
|
2014-11-24 11:36:14 -05:00
|
|
|
if driver.CreateImageDisk != config.DiskName {
|
|
|
|
t.Fatalf("bad: %#v", driver.CreateImageDisk)
|
2013-12-13 21:26:00 -05:00
|
|
|
}
|
|
|
|
|
2014-11-24 11:36:14 -05:00
|
|
|
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)
|
2013-12-13 21:26:00 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-24 11:36:14 -05:00
|
|
|
func TestStepCreateImage_errorOnChannel(t *testing.T) {
|
2013-12-13 21:26:00 -05:00
|
|
|
state := testState(t)
|
|
|
|
step := new(StepCreateImage)
|
|
|
|
defer step.Cleanup(state)
|
|
|
|
|
2014-11-24 11:36:14 -05:00
|
|
|
errCh := make(chan error, 1)
|
|
|
|
errCh <- errors.New("error")
|
|
|
|
|
|
|
|
driver := state.Get("driver").(*DriverMock)
|
|
|
|
driver.CreateImageErrCh = errCh
|
2013-12-13 21:26:00 -05:00
|
|
|
|
|
|
|
// 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")
|
|
|
|
}
|
2014-11-24 11:36:14 -05:00
|
|
|
if _, ok := state.GetOk("image_name"); ok {
|
2013-12-13 21:26:00 -05:00
|
|
|
t.Fatal("should NOT have image")
|
|
|
|
}
|
|
|
|
}
|