2014-11-24 11:36:14 -05:00
|
|
|
package googlecompute
|
|
|
|
|
|
|
|
import (
|
2018-01-22 19:03:49 -05:00
|
|
|
"context"
|
2014-11-24 11:36:14 -05:00
|
|
|
"testing"
|
2018-01-22 20:21:10 -05:00
|
|
|
|
2018-01-22 18:32:33 -05:00
|
|
|
"github.com/hashicorp/packer/helper/multistep"
|
2014-11-24 11:36:14 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestStepTeardownInstance_impl(t *testing.T) {
|
|
|
|
var _ multistep.Step = new(StepTeardownInstance)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStepTeardownInstance(t *testing.T) {
|
|
|
|
state := testState(t)
|
|
|
|
step := new(StepTeardownInstance)
|
|
|
|
defer step.Cleanup(state)
|
|
|
|
|
|
|
|
config := state.Get("config").(*Config)
|
|
|
|
driver := state.Get("driver").(*DriverMock)
|
|
|
|
|
|
|
|
// run the step
|
2018-01-22 19:03:49 -05:00
|
|
|
if action := step.Run(context.Background(), state); action != multistep.ActionContinue {
|
2014-11-24 11:36:14 -05:00
|
|
|
t.Fatalf("bad action: %#v", action)
|
|
|
|
}
|
|
|
|
|
|
|
|
if driver.DeleteInstanceName != config.InstanceName {
|
|
|
|
t.Fatal("should've deleted instance")
|
|
|
|
}
|
|
|
|
if driver.DeleteInstanceZone != config.Zone {
|
2014-12-15 13:16:19 -05:00
|
|
|
t.Fatalf("bad zone: %#v", driver.DeleteInstanceZone)
|
2014-11-24 11:36:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// cleanup
|
|
|
|
step.Cleanup(state)
|
|
|
|
|
|
|
|
if driver.DeleteDiskName != config.InstanceName {
|
|
|
|
t.Fatal("should've deleted disk")
|
|
|
|
}
|
|
|
|
if driver.DeleteDiskZone != config.Zone {
|
2014-12-15 13:16:19 -05:00
|
|
|
t.Fatalf("bad zone: %#v", driver.DeleteDiskZone)
|
2014-11-24 11:36:14 -05:00
|
|
|
}
|
|
|
|
}
|