github.com/bigkraig/terraform@v0.6.4-0.20151219155159-c90d1b074e31/communicator/winrm/provisioner_test.go (about) 1 package winrm 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": "winrm", 14 "user": "Administrator", 15 "password": "supersecret", 16 "host": "127.0.0.1", 17 "port": "5985", 18 "https": "true", 19 "timeout": "30s", 20 }, 21 }, 22 } 23 24 conf, err := parseConnectionInfo(r) 25 if err != nil { 26 t.Fatalf("err: %v", err) 27 } 28 29 if conf.User != "Administrator" { 30 t.Fatalf("expected: %v: got: %v", "Administrator", conf) 31 } 32 if conf.Password != "supersecret" { 33 t.Fatalf("expected: %v: got: %v", "supersecret", conf) 34 } 35 if conf.Host != "127.0.0.1" { 36 t.Fatalf("expected: %v: got: %v", "127.0.0.1", conf) 37 } 38 if conf.Port != 5985 { 39 t.Fatalf("expected: %v: got: %v", 5985, conf) 40 } 41 if conf.HTTPS != true { 42 t.Fatalf("expected: %v: got: %v", true, conf) 43 } 44 if conf.Timeout != "30s" { 45 t.Fatalf("expected: %v: got: %v", "30s", conf) 46 } 47 if conf.ScriptPath != DefaultScriptPath { 48 t.Fatalf("expected: %v: got: %v", DefaultScriptPath, conf) 49 } 50 } 51 52 func TestProvisioner_formatDuration(t *testing.T) { 53 cases := map[string]struct { 54 InstanceState *terraform.InstanceState 55 Result string 56 }{ 57 "testSeconds": { 58 InstanceState: &terraform.InstanceState{ 59 Ephemeral: terraform.EphemeralState{ 60 ConnInfo: map[string]string{ 61 "timeout": "90s", 62 }, 63 }, 64 }, 65 66 Result: "PT1M30S", 67 }, 68 "testMinutes": { 69 InstanceState: &terraform.InstanceState{ 70 Ephemeral: terraform.EphemeralState{ 71 ConnInfo: map[string]string{ 72 "timeout": "5m", 73 }, 74 }, 75 }, 76 77 Result: "PT5M", 78 }, 79 "testHours": { 80 InstanceState: &terraform.InstanceState{ 81 Ephemeral: terraform.EphemeralState{ 82 ConnInfo: map[string]string{ 83 "timeout": "1h", 84 }, 85 }, 86 }, 87 88 Result: "PT1H", 89 }, 90 } 91 92 for name, tc := range cases { 93 conf, err := parseConnectionInfo(tc.InstanceState) 94 if err != nil { 95 t.Fatalf("err: %v", err) 96 } 97 98 result := formatDuration(conf.TimeoutVal) 99 if result != tc.Result { 100 t.Fatalf("%s: expected: %s got: %s", name, tc.Result, result) 101 } 102 } 103 }