2016-05-24 17:13:36 -07:00
|
|
|
package googlecompute
|
|
|
|
|
|
|
|
|
|
import (
|
2018-01-22 16:03:49 -08:00
|
|
|
"context"
|
2018-01-22 15:32:33 -08:00
|
|
|
"testing"
|
|
|
|
|
|
2018-01-19 16:18:44 -08:00
|
|
|
"github.com/hashicorp/packer/helper/multistep"
|
2016-09-07 19:00:30 -07:00
|
|
|
"github.com/stretchr/testify/assert"
|
2016-05-24 17:13:36 -07:00
|
|
|
)
|
|
|
|
|
|
2016-11-02 14:35:06 -07:00
|
|
|
func TestStepWaitStartupScript(t *testing.T) {
|
2016-05-24 17:13:36 -07:00
|
|
|
state := testState(t)
|
2016-11-02 14:35:06 -07:00
|
|
|
step := new(StepWaitStartupScript)
|
2016-09-07 19:00:30 -07:00
|
|
|
c := state.Get("config").(*Config)
|
|
|
|
|
d := state.Get("driver").(*DriverMock)
|
2016-09-29 14:13:04 -07:00
|
|
|
|
2016-05-24 17:13:36 -07:00
|
|
|
testZone := "test-zone"
|
|
|
|
|
testInstanceName := "test-instance-name"
|
|
|
|
|
|
2016-09-07 19:00:30 -07:00
|
|
|
c.Zone = testZone
|
2016-05-24 17:13:36 -07:00
|
|
|
state.Put("instance_name", testInstanceName)
|
2016-09-07 19:00:30 -07:00
|
|
|
|
|
|
|
|
// This step stops when it gets Done back from the metadata.
|
|
|
|
|
d.GetInstanceMetadataResult = StartupScriptStatusDone
|
2016-09-29 14:13:04 -07:00
|
|
|
|
2016-05-24 17:13:36 -07:00
|
|
|
// Run the step.
|
2018-01-22 16:03:49 -08:00
|
|
|
assert.Equal(t, step.Run(context.Background(), state), multistep.ActionContinue, "Step should have passed and continued.")
|
2016-09-29 14:13:04 -07:00
|
|
|
|
2016-09-07 19:00:30 -07:00
|
|
|
// Check that GetInstanceMetadata was called properly.
|
|
|
|
|
assert.Equal(t, d.GetInstanceMetadataZone, testZone, "Incorrect zone passed to GetInstanceMetadata.")
|
|
|
|
|
assert.Equal(t, d.GetInstanceMetadataName, testInstanceName, "Incorrect instance name passed to GetInstanceMetadata.")
|
2016-09-29 14:13:04 -07:00
|
|
|
}
|