github.com/agvvsivakiran/terraform@v0.11.12-beta1/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_connInfoIpv6(t *testing.T) { 70 r := &terraform.InstanceState{ 71 Ephemeral: terraform.EphemeralState{ 72 ConnInfo: map[string]string{ 73 "type": "ssh", 74 "user": "root", 75 "password": "supersecret", 76 "private_key": "someprivatekeycontents", 77 "host": "::1", 78 "port": "22", 79 "timeout": "30s", 80 81 "bastion_host": "::1", 82 }, 83 }, 84 } 85 86 conf, err := parseConnectionInfo(r) 87 if err != nil { 88 t.Fatalf("err: %v", err) 89 } 90 91 if conf.Host != "[::1]" { 92 t.Fatalf("bad: %v", conf) 93 } 94 95 if conf.BastionHost != "[::1]" { 96 t.Fatalf("bad %v", conf) 97 } 98 } 99 100 func TestProvisioner_connInfoHostname(t *testing.T) { 101 r := &terraform.InstanceState{ 102 Ephemeral: terraform.EphemeralState{ 103 ConnInfo: map[string]string{ 104 "type": "ssh", 105 "user": "root", 106 "password": "supersecret", 107 "private_key": "someprivatekeycontents", 108 "host": "example.com", 109 "port": "22", 110 "timeout": "30s", 111 112 "bastion_host": "example.com", 113 }, 114 }, 115 } 116 117 conf, err := parseConnectionInfo(r) 118 if err != nil { 119 t.Fatalf("err: %v", err) 120 } 121 122 if conf.Host != "example.com" { 123 t.Fatalf("bad: %v", conf) 124 } 125 126 if conf.BastionHost != "example.com" { 127 t.Fatalf("bad %v", conf) 128 } 129 }