github.com/ezbercih/terraform@v0.1.1-0.20140729011846-3c33865e0839/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.ResourceState{
    11  		ConnInfo: map[string]string{
    12  			"type": "telnet",
    13  		},
    14  	}
    15  	if err := VerifySSH(r); err == nil {
    16  		t.Fatalf("expected error with telnet")
    17  	}
    18  	r.ConnInfo["type"] = "ssh"
    19  	if err := VerifySSH(r); err != nil {
    20  		t.Fatalf("err: %v", err)
    21  	}
    22  }
    23  
    24  func TestResourceProvider_sshConfig(t *testing.T) {
    25  	r := &terraform.ResourceState{
    26  		ConnInfo: map[string]string{
    27  			"type":     "ssh",
    28  			"user":     "root",
    29  			"password": "supersecret",
    30  			"key_file": "/my/key/file.pem",
    31  			"host":     "127.0.0.1",
    32  			"port":     "22",
    33  			"timeout":  "30s",
    34  		},
    35  	}
    36  
    37  	conf, err := ParseSSHConfig(r)
    38  	if err != nil {
    39  		t.Fatalf("err: %v", err)
    40  	}
    41  
    42  	if conf.User != "root" {
    43  		t.Fatalf("bad: %v", conf)
    44  	}
    45  	if conf.Password != "supersecret" {
    46  		t.Fatalf("bad: %v", conf)
    47  	}
    48  	if conf.KeyFile != "/my/key/file.pem" {
    49  		t.Fatalf("bad: %v", conf)
    50  	}
    51  	if conf.Host != "127.0.0.1" {
    52  		t.Fatalf("bad: %v", conf)
    53  	}
    54  	if conf.Port != 22 {
    55  		t.Fatalf("bad: %v", conf)
    56  	}
    57  	if conf.Timeout != "30s" {
    58  		t.Fatalf("bad: %v", conf)
    59  	}
    60  	if conf.ScriptPath != DefaultScriptPath {
    61  		t.Fatalf("bad: %v", conf)
    62  	}
    63  }