github.com/tam7t/terraform@v0.7.0-rc2.0.20160705125922-be2469a05c5e/communicator/ssh/provisioner_test.go (about) 1 package ssh 2 3 import ( 4 "testing" 5 6 "github.com/hashicorp/terraform/terraform" 7 ) 8 9 func TestProvisioner_connInfo(t *testing.T) { 10 r := &terraform.InstanceState{ 11 Ephemeral: terraform.EphemeralState{ 12 ConnInfo: map[string]string{ 13 "type": "ssh", 14 "user": "root", 15 "password": "supersecret", 16 "private_key": "someprivatekeycontents", 17 "host": "127.0.0.1", 18 "port": "22", 19 "timeout": "30s", 20 21 "bastion_host": "127.0.1.1", 22 }, 23 }, 24 } 25 26 conf, err := parseConnectionInfo(r) 27 if err != nil { 28 t.Fatalf("err: %v", err) 29 } 30 31 if conf.User != "root" { 32 t.Fatalf("bad: %v", conf) 33 } 34 if conf.Password != "supersecret" { 35 t.Fatalf("bad: %v", conf) 36 } 37 if conf.PrivateKey != "someprivatekeycontents" { 38 t.Fatalf("bad: %v", conf) 39 } 40 if conf.Host != "127.0.0.1" { 41 t.Fatalf("bad: %v", conf) 42 } 43 if conf.Port != 22 { 44 t.Fatalf("bad: %v", conf) 45 } 46 if conf.Timeout != "30s" { 47 t.Fatalf("bad: %v", conf) 48 } 49 if conf.ScriptPath != DefaultScriptPath { 50 t.Fatalf("bad: %v", conf) 51 } 52 if conf.BastionHost != "127.0.1.1" { 53 t.Fatalf("bad: %v", conf) 54 } 55 if conf.BastionPort != 22 { 56 t.Fatalf("bad: %v", conf) 57 } 58 if conf.BastionUser != "root" { 59 t.Fatalf("bad: %v", conf) 60 } 61 if conf.BastionPassword != "supersecret" { 62 t.Fatalf("bad: %v", conf) 63 } 64 if conf.BastionPrivateKey != "someprivatekeycontents" { 65 t.Fatalf("bad: %v", conf) 66 } 67 } 68 69 func TestProvisioner_connInfoLegacy(t *testing.T) { 70 r := &terraform.InstanceState{ 71 Ephemeral: terraform.EphemeralState{ 72 ConnInfo: map[string]string{ 73 "type": "ssh", 74 "key_file": "/my/key/file.pem", 75 "bastion_host": "127.0.1.1", 76 }, 77 }, 78 } 79 80 conf, err := parseConnectionInfo(r) 81 if err != nil { 82 t.Fatalf("err: %v", err) 83 } 84 85 if conf.PrivateKey != "/my/key/file.pem" { 86 t.Fatalf("bad: %v", conf) 87 } 88 if conf.BastionPrivateKey != "/my/key/file.pem" { 89 t.Fatalf("bad: %v", conf) 90 } 91 }