github.phpd.cn/hashicorp/packer@v1.3.2/builder/googlecompute/step_check_existing_image_test.go (about)

     1  package googlecompute
     2  
     3  import (
     4  	"context"
     5  	"testing"
     6  
     7  	"github.com/hashicorp/packer/helper/multistep"
     8  )
     9  
    10  func TestStepCheckExistingImage_impl(t *testing.T) {
    11  	var _ multistep.Step = new(StepCheckExistingImage)
    12  }
    13  
    14  func TestStepCheckExistingImage(t *testing.T) {
    15  	state := testState(t)
    16  	step := new(StepCheckExistingImage)
    17  	defer step.Cleanup(state)
    18  
    19  	state.Put("instance_name", "foo")
    20  
    21  	config := state.Get("config").(*Config)
    22  	driver := state.Get("driver").(*DriverMock)
    23  	driver.ImageExistsResult = true
    24  
    25  	// run the step
    26  	if action := step.Run(context.Background(), state); action != multistep.ActionHalt {
    27  		t.Fatalf("bad action: %#v", action)
    28  	}
    29  
    30  	// Verify state
    31  	if driver.ImageExistsName != config.ImageName {
    32  		t.Fatalf("bad: %#v", driver.ImageExistsName)
    33  	}
    34  }