github.com/sneal/packer@v0.5.2/builder/googlecompute/step_create_ssh_key_test.go (about)

     1  package googlecompute
     2  
     3  import (
     4  	"github.com/mitchellh/multistep"
     5  
     6  	"io/ioutil"
     7  	"os"
     8  	"testing"
     9  )
    10  
    11  func TestStepCreateSSHKey_impl(t *testing.T) {
    12  	var _ multistep.Step = new(StepCreateSSHKey)
    13  }
    14  
    15  func TestStepCreateSSHKey(t *testing.T) {
    16  	state := testState(t)
    17  	step := new(StepCreateSSHKey)
    18  	defer step.Cleanup(state)
    19  
    20  	// run the step
    21  	if action := step.Run(state); action != multistep.ActionContinue {
    22  		t.Fatalf("bad action: %#v", action)
    23  	}
    24  
    25  	// Verify that we have a public/private key
    26  	if _, ok := state.GetOk("ssh_private_key"); !ok {
    27  		t.Fatal("should have key")
    28  	}
    29  	if _, ok := state.GetOk("ssh_public_key"); !ok {
    30  		t.Fatal("should have key")
    31  	}
    32  }
    33  
    34  func TestStepCreateSSHKey_debug(t *testing.T) {
    35  	tf, err := ioutil.TempFile("", "packer")
    36  	if err != nil {
    37  		t.Fatalf("err: %s", err)
    38  	}
    39  	tf.Close()
    40  
    41  	state := testState(t)
    42  	step := new(StepCreateSSHKey)
    43  	step.Debug = true
    44  	step.DebugKeyPath = tf.Name()
    45  
    46  	defer step.Cleanup(state)
    47  
    48  	// run the step
    49  	if action := step.Run(state); action != multistep.ActionContinue {
    50  		t.Fatalf("bad action: %#v", action)
    51  	}
    52  
    53  	// Verify that we have a public/private key
    54  	if _, ok := state.GetOk("ssh_private_key"); !ok {
    55  		t.Fatal("should have key")
    56  	}
    57  	if _, ok := state.GetOk("ssh_public_key"); !ok {
    58  		t.Fatal("should have key")
    59  	}
    60  	if _, err := os.Stat(tf.Name()); err != nil {
    61  		t.Fatalf("err: %s", err)
    62  	}
    63  }