github.phpd.cn/hashicorp/packer@v1.3.2/builder/googlecompute/step_wait_startup_script_test.go (about) 1 package googlecompute 2 3 import ( 4 "context" 5 "testing" 6 7 "github.com/hashicorp/packer/helper/multistep" 8 "github.com/stretchr/testify/assert" 9 ) 10 11 func TestStepWaitStartupScript(t *testing.T) { 12 state := testState(t) 13 step := new(StepWaitStartupScript) 14 c := state.Get("config").(*Config) 15 d := state.Get("driver").(*DriverMock) 16 17 testZone := "test-zone" 18 testInstanceName := "test-instance-name" 19 20 c.Zone = testZone 21 state.Put("instance_name", testInstanceName) 22 23 // This step stops when it gets Done back from the metadata. 24 d.GetInstanceMetadataResult = StartupScriptStatusDone 25 26 // Run the step. 27 assert.Equal(t, step.Run(context.Background(), state), multistep.ActionContinue, "Step should have passed and continued.") 28 29 // Check that GetInstanceMetadata was called properly. 30 assert.Equal(t, d.GetInstanceMetadataZone, testZone, "Incorrect zone passed to GetInstanceMetadata.") 31 assert.Equal(t, d.GetInstanceMetadataName, testInstanceName, "Incorrect instance name passed to GetInstanceMetadata.") 32 }