github.com/marksheahan/packer@v0.10.2-0.20160613200515-1acb2d6645a0/helper/communicator/config_test.go (about)

     1  package communicator
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/mitchellh/packer/template/interpolate"
     7  )
     8  
     9  func testConfig() *Config {
    10  	return &Config{
    11  		SSHUsername: "root",
    12  	}
    13  }
    14  
    15  func TestConfigType(t *testing.T) {
    16  	c := testConfig()
    17  	if err := c.Prepare(testContext(t)); len(err) > 0 {
    18  		t.Fatalf("bad: %#v", err)
    19  	}
    20  
    21  	if c.Type != "ssh" {
    22  		t.Fatalf("bad: %#v", c)
    23  	}
    24  }
    25  
    26  func TestConfig_none(t *testing.T) {
    27  	c := &Config{Type: "none"}
    28  	if err := c.Prepare(testContext(t)); len(err) > 0 {
    29  		t.Fatalf("bad: %#v", err)
    30  	}
    31  }
    32  
    33  func TestConfig_badtype(t *testing.T) {
    34  	c := &Config{Type: "foo"}
    35  	if err := c.Prepare(testContext(t)); len(err) != 1 {
    36  		t.Fatalf("bad: %#v", err)
    37  	}
    38  }
    39  
    40  func TestConfig_winrm_noport(t *testing.T) {
    41  	c := &Config{
    42  		Type:      "winrm",
    43  		WinRMUser: "admin",
    44  	}
    45  	if err := c.Prepare(testContext(t)); len(err) > 0 {
    46  		t.Fatalf("bad: %#v", err)
    47  	}
    48  
    49  	if c.WinRMPort != 5985 {
    50  		t.Fatalf("WinRMPort doesn't match default port 5985 when SSL is not enabled and no port is specified.")
    51  	}
    52  
    53  }
    54  
    55  func TestConfig_winrm_noport_ssl(t *testing.T) {
    56  	c := &Config{
    57  		Type:        "winrm",
    58  		WinRMUser:   "admin",
    59  		WinRMUseSSL: true,
    60  	}
    61  	if err := c.Prepare(testContext(t)); len(err) > 0 {
    62  		t.Fatalf("bad: %#v", err)
    63  	}
    64  
    65  	if c.WinRMPort != 5986 {
    66  		t.Fatalf("WinRMPort doesn't match default port 5986 when SSL is enabled and no port is specified.")
    67  	}
    68  
    69  }
    70  
    71  func TestConfig_winrm_port(t *testing.T) {
    72  	c := &Config{
    73  		Type:      "winrm",
    74  		WinRMUser: "admin",
    75  		WinRMPort: 5509,
    76  	}
    77  	if err := c.Prepare(testContext(t)); len(err) > 0 {
    78  		t.Fatalf("bad: %#v", err)
    79  	}
    80  
    81  	if c.WinRMPort != 5509 {
    82  		t.Fatalf("WinRMPort doesn't match custom port 5509 when SSL is not enabled.")
    83  	}
    84  
    85  }
    86  
    87  func TestConfig_winrm_port_ssl(t *testing.T) {
    88  	c := &Config{
    89  		Type:        "winrm",
    90  		WinRMUser:   "admin",
    91  		WinRMPort:   5510,
    92  		WinRMUseSSL: true,
    93  	}
    94  	if err := c.Prepare(testContext(t)); len(err) > 0 {
    95  		t.Fatalf("bad: %#v", err)
    96  	}
    97  
    98  	if c.WinRMPort != 5510 {
    99  		t.Fatalf("WinRMPort doesn't match custom port 5510 when SSL is enabled.")
   100  	}
   101  
   102  }
   103  
   104  func TestConfig_winrm(t *testing.T) {
   105  	c := &Config{
   106  		Type:      "winrm",
   107  		WinRMUser: "admin",
   108  	}
   109  	if err := c.Prepare(testContext(t)); len(err) > 0 {
   110  		t.Fatalf("bad: %#v", err)
   111  	}
   112  }
   113  
   114  func testContext(t *testing.T) *interpolate.Context {
   115  	return nil
   116  }