github.com/mitchellh/packer@v1.3.2/builder/vmware/iso/driver_esx5_test.go (about)

     1  package iso
     2  
     3  import (
     4  	"fmt"
     5  	"net"
     6  	"testing"
     7  
     8  	vmwcommon "github.com/hashicorp/packer/builder/vmware/common"
     9  	"github.com/hashicorp/packer/helper/multistep"
    10  )
    11  
    12  func TestESX5Driver_implDriver(t *testing.T) {
    13  	var _ vmwcommon.Driver = new(ESX5Driver)
    14  }
    15  
    16  func TestESX5Driver_UpdateVMX(t *testing.T) {
    17  	var driver ESX5Driver
    18  	data := make(map[string]string)
    19  	driver.UpdateVMX("0.0.0.0", "", 5900, data)
    20  	if _, ok := data["remotedisplay.vnc.ip"]; ok {
    21  		// Do not add the remotedisplay.vnc.ip on ESXi
    22  		t.Fatal("invalid VMX data key: remotedisplay.vnc.ip")
    23  	}
    24  	if enabled := data["remotedisplay.vnc.enabled"]; enabled != "TRUE" {
    25  		t.Errorf("bad VMX data for key remotedisplay.vnc.enabled: %v", enabled)
    26  	}
    27  	if port := data["remotedisplay.vnc.port"]; port != fmt.Sprint(port) {
    28  		t.Errorf("bad VMX data for key remotedisplay.vnc.port: %v", port)
    29  	}
    30  }
    31  
    32  func TestESX5Driver_implOutputDir(t *testing.T) {
    33  	var _ vmwcommon.OutputDir = new(ESX5Driver)
    34  }
    35  
    36  func TestESX5Driver_implVNCAddressFinder(t *testing.T) {
    37  	var _ vmwcommon.VNCAddressFinder = new(ESX5Driver)
    38  }
    39  
    40  func TestESX5Driver_implRemoteDriver(t *testing.T) {
    41  	var _ RemoteDriver = new(ESX5Driver)
    42  }
    43  
    44  func TestESX5Driver_HostIP(t *testing.T) {
    45  	expected_host := "127.0.0.1"
    46  
    47  	//create mock SSH server
    48  	listen, _ := net.Listen("tcp", fmt.Sprintf("%s:0", expected_host))
    49  	port := listen.Addr().(*net.TCPAddr).Port
    50  	defer listen.Close()
    51  
    52  	driver := ESX5Driver{Host: "localhost", Port: uint(port)}
    53  	state := new(multistep.BasicStateBag)
    54  
    55  	if host, _ := driver.HostIP(state); host != expected_host {
    56  		t.Error(fmt.Sprintf("Expected string, %s but got %s", expected_host, host))
    57  	}
    58  }
    59  
    60  func TestESX5Driver_CommHost(t *testing.T) {
    61  	const expected_host = "127.0.0.1"
    62  
    63  	config := testConfig()
    64  	config["communicator"] = "winrm"
    65  	config["winrm_username"] = "username"
    66  	config["winrm_password"] = "password"
    67  	config["winrm_host"] = expected_host
    68  
    69  	var b Builder
    70  	warns, err := b.Prepare(config)
    71  	if len(warns) > 0 {
    72  		t.Fatalf("bad: %#v", warns)
    73  	}
    74  	if err != nil {
    75  		t.Fatalf("should not have error: %s", err)
    76  	}
    77  	if host := b.config.CommConfig.Host(); host != expected_host {
    78  		t.Fatalf("setup failed, bad host name: %s", host)
    79  	}
    80  
    81  	state := new(multistep.BasicStateBag)
    82  	state.Put("config", &b.config)
    83  
    84  	var driver ESX5Driver
    85  	host, err := driver.CommHost(state)
    86  	if err != nil {
    87  		t.Fatalf("should not have error: %s", err)
    88  	}
    89  	if host != expected_host {
    90  		t.Errorf("bad host name: %s", host)
    91  	}
    92  }