github.phpd.cn/hashicorp/packer@v1.3.2/builder/googlecompute/step_teardown_instance_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 TestStepTeardownInstance_impl(t *testing.T) {
    11  	var _ multistep.Step = new(StepTeardownInstance)
    12  }
    13  
    14  func TestStepTeardownInstance(t *testing.T) {
    15  	state := testState(t)
    16  	step := new(StepTeardownInstance)
    17  	defer step.Cleanup(state)
    18  
    19  	config := state.Get("config").(*Config)
    20  	driver := state.Get("driver").(*DriverMock)
    21  
    22  	// run the step
    23  	if action := step.Run(context.Background(), state); action != multistep.ActionContinue {
    24  		t.Fatalf("bad action: %#v", action)
    25  	}
    26  
    27  	if driver.DeleteInstanceName != config.InstanceName {
    28  		t.Fatal("should've deleted instance")
    29  	}
    30  	if driver.DeleteInstanceZone != config.Zone {
    31  		t.Fatalf("bad zone: %#v", driver.DeleteInstanceZone)
    32  	}
    33  
    34  	// cleanup
    35  	step.Cleanup(state)
    36  
    37  	if driver.DeleteDiskName != config.InstanceName {
    38  		t.Fatal("should've deleted disk")
    39  	}
    40  	if driver.DeleteDiskZone != config.Zone {
    41  		t.Fatalf("bad zone: %#v", driver.DeleteDiskZone)
    42  	}
    43  }