github.com/kimor79/packer@v0.8.7-0.20151221212622-d507b18eb4cf/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(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  
    50  func testContext(t *testing.T) *interpolate.Context {
    51  	return nil
    52  }