github.com/adamar/terraform@v0.2.2-0.20141016210445-2e703afdad0e/helper/ssh/provisioner_test.go (about)

     1  package ssh
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/hashicorp/terraform/terraform"
     7  )
     8  
     9  func TestResourceProvider_verifySSH(t *testing.T) {
    10  	r := &terraform.InstanceState{
    11  		Ephemeral: terraform.EphemeralState{
    12  			ConnInfo: map[string]string{
    13  				"type": "telnet",
    14  			},
    15  		},
    16  	}
    17  	if err := VerifySSH(r); err == nil {
    18  		t.Fatalf("expected error with telnet")
    19  	}
    20  	r.Ephemeral.ConnInfo["type"] = "ssh"
    21  	if err := VerifySSH(r); err != nil {
    22  		t.Fatalf("err: %v", err)
    23  	}
    24  }
    25  
    26  func TestResourceProvider_sshConfig(t *testing.T) {
    27  	r := &terraform.InstanceState{
    28  		Ephemeral: terraform.EphemeralState{
    29  			ConnInfo: map[string]string{
    30  				"type":     "ssh",
    31  				"user":     "root",
    32  				"password": "supersecret",
    33  				"key_file": "/my/key/file.pem",
    34  				"host":     "127.0.0.1",
    35  				"port":     "22",
    36  				"timeout":  "30s",
    37  			},
    38  		},
    39  	}
    40  
    41  	conf, err := ParseSSHConfig(r)
    42  	if err != nil {
    43  		t.Fatalf("err: %v", err)
    44  	}
    45  
    46  	if conf.User != "root" {
    47  		t.Fatalf("bad: %v", conf)
    48  	}
    49  	if conf.Password != "supersecret" {
    50  		t.Fatalf("bad: %v", conf)
    51  	}
    52  	if conf.KeyFile != "/my/key/file.pem" {
    53  		t.Fatalf("bad: %v", conf)
    54  	}
    55  	if conf.Host != "127.0.0.1" {
    56  		t.Fatalf("bad: %v", conf)
    57  	}
    58  	if conf.Port != 22 {
    59  		t.Fatalf("bad: %v", conf)
    60  	}
    61  	if conf.Timeout != "30s" {
    62  		t.Fatalf("bad: %v", conf)
    63  	}
    64  	if conf.ScriptPath != DefaultScriptPath {
    65  		t.Fatalf("bad: %v", conf)
    66  	}
    67  }