2014-12-29 06:46:54 -06:00
|
|
|
package xva
|
2014-12-22 11:11:43 -06:00
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/mitchellh/packer/packer"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func testConfig() map[string]interface{} {
|
|
|
|
return map[string]interface{}{
|
2015-03-13 08:23:20 -05:00
|
|
|
"remote_host": "localhost",
|
|
|
|
"remote_username": "admin",
|
|
|
|
"remote_password": "admin",
|
|
|
|
"vm_name": "foo",
|
|
|
|
"shutdown_command": "yes",
|
|
|
|
"ssh_username": "foo",
|
|
|
|
"source_path": ".",
|
2014-12-22 11:11:43 -06:00
|
|
|
|
|
|
|
packer.BuildNameConfigKey: "foo",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBuilder_ImplementsBuilder(t *testing.T) {
|
|
|
|
var raw interface{}
|
|
|
|
raw = &Builder{}
|
|
|
|
if _, ok := raw.(packer.Builder); !ok {
|
|
|
|
t.Error("Builder must implement builder.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBuilderPrepare_Defaults(t *testing.T) {
|
|
|
|
var b Builder
|
|
|
|
config := testConfig()
|
|
|
|
warns, err := b.Prepare(config)
|
|
|
|
if len(warns) > 0 {
|
|
|
|
t.Fatalf("bad: %#v", warns)
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("should not have error: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if b.config.ToolsIsoName != "xs-tools.iso" {
|
|
|
|
t.Errorf("bad tools ISO name: %s", b.config.ToolsIsoName)
|
|
|
|
}
|
|
|
|
|
|
|
|
if b.config.VMName == "" {
|
|
|
|
t.Errorf("bad vm name: %s", b.config.VMName)
|
|
|
|
}
|
|
|
|
|
2015-01-02 10:48:12 -06:00
|
|
|
if b.config.Format != "xva" {
|
|
|
|
t.Errorf("bad format: %s", b.config.Format)
|
2014-12-22 11:11:43 -06:00
|
|
|
}
|
|
|
|
|
2015-01-02 10:48:12 -06:00
|
|
|
if b.config.KeepVM != "never" {
|
|
|
|
t.Errorf("bad keep instance: %s", b.config.KeepVM)
|
2014-12-22 11:11:43 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBuilderPrepare_Format(t *testing.T) {
|
|
|
|
var b Builder
|
|
|
|
config := testConfig()
|
|
|
|
|
|
|
|
// Bad
|
2015-01-02 10:48:12 -06:00
|
|
|
config["format"] = "foo"
|
2014-12-22 11:11:43 -06:00
|
|
|
warns, err := b.Prepare(config)
|
|
|
|
if len(warns) > 0 {
|
|
|
|
t.Fatalf("bad: %#v", warns)
|
|
|
|
}
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal("should have error")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Good
|
2015-01-02 10:48:12 -06:00
|
|
|
config["format"] = "vdi_raw"
|
2014-12-22 11:11:43 -06:00
|
|
|
b = Builder{}
|
|
|
|
warns, err = b.Prepare(config)
|
|
|
|
if len(warns) > 0 {
|
|
|
|
t.Fatalf("bad: %#v", warns)
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("should not have error: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBuilderPrepare_HTTPPort(t *testing.T) {
|
|
|
|
var b Builder
|
|
|
|
config := testConfig()
|
|
|
|
|
|
|
|
// Bad
|
|
|
|
config["http_port_min"] = 1000
|
|
|
|
config["http_port_max"] = 500
|
|
|
|
warns, err := b.Prepare(config)
|
|
|
|
if len(warns) > 0 {
|
|
|
|
t.Fatalf("bad: %#v", warns)
|
|
|
|
}
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal("should have error")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Bad
|
|
|
|
config["http_port_min"] = -500
|
|
|
|
b = Builder{}
|
|
|
|
warns, err = b.Prepare(config)
|
|
|
|
if len(warns) > 0 {
|
|
|
|
t.Fatalf("bad: %#v", warns)
|
|
|
|
}
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal("should have error")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Good
|
|
|
|
config["http_port_min"] = 500
|
|
|
|
config["http_port_max"] = 1000
|
|
|
|
b = Builder{}
|
|
|
|
warns, err = b.Prepare(config)
|
|
|
|
if len(warns) > 0 {
|
|
|
|
t.Fatalf("bad: %#v", warns)
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("should not have error: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBuilderPrepare_InvalidKey(t *testing.T) {
|
|
|
|
var b Builder
|
|
|
|
config := testConfig()
|
|
|
|
|
|
|
|
// Add a random key
|
|
|
|
config["i_should_not_be_valid"] = true
|
|
|
|
warns, err := b.Prepare(config)
|
|
|
|
if len(warns) > 0 {
|
|
|
|
t.Fatalf("bad: %#v", warns)
|
|
|
|
}
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal("should have error")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-02 10:48:12 -06:00
|
|
|
func TestBuilderPrepare_KeepVM(t *testing.T) {
|
2014-12-22 11:11:43 -06:00
|
|
|
var b Builder
|
|
|
|
config := testConfig()
|
|
|
|
|
2015-01-02 10:48:12 -06:00
|
|
|
// Bad
|
|
|
|
config["keep_vm"] = "foo"
|
2014-12-22 11:11:43 -06:00
|
|
|
warns, err := b.Prepare(config)
|
|
|
|
if len(warns) > 0 {
|
|
|
|
t.Fatalf("bad: %#v", warns)
|
|
|
|
}
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal("should have error")
|
|
|
|
}
|
|
|
|
|
2015-01-02 10:48:12 -06:00
|
|
|
// Good
|
|
|
|
config["keep_vm"] = "always"
|
2014-12-22 11:11:43 -06:00
|
|
|
b = Builder{}
|
|
|
|
warns, err = b.Prepare(config)
|
|
|
|
if len(warns) > 0 {
|
|
|
|
t.Fatalf("bad: %#v", warns)
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("should not have error: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-02 10:48:12 -06:00
|
|
|
func TestBuilderPrepare_SourcePath(t *testing.T) {
|
2014-12-22 11:11:43 -06:00
|
|
|
var b Builder
|
|
|
|
config := testConfig()
|
|
|
|
|
|
|
|
// Bad
|
2015-01-02 10:48:12 -06:00
|
|
|
config["source_path"] = ""
|
2014-12-22 11:11:43 -06:00
|
|
|
warns, err := b.Prepare(config)
|
|
|
|
if len(warns) > 0 {
|
|
|
|
t.Fatalf("bad: %#v", warns)
|
|
|
|
}
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal("should have error")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Good
|
2015-01-02 10:48:12 -06:00
|
|
|
config["source_path"] = "."
|
2014-12-22 11:11:43 -06:00
|
|
|
b = Builder{}
|
|
|
|
warns, err = b.Prepare(config)
|
|
|
|
if len(warns) > 0 {
|
|
|
|
t.Fatalf("bad: %#v", warns)
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("should not have error: %s", err)
|
|
|
|
}
|
|
|
|
}
|