2013-12-25 17:52:40 -05:00
|
|
|
package vmx
|
2014-05-12 21:24:03 -04:00
|
|
|
|
|
|
|
import (
|
2016-07-26 15:42:04 -04:00
|
|
|
"fmt"
|
2014-05-12 21:24:03 -04:00
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
2016-07-26 15:42:04 -04:00
|
|
|
|
2017-04-04 16:39:01 -04:00
|
|
|
"github.com/hashicorp/packer/packer"
|
2014-05-12 21:24:03 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestBuilderPrepare_FloppyFiles(t *testing.T) {
|
|
|
|
var b Builder
|
|
|
|
|
|
|
|
tf, err := ioutil.TempFile("", "packer")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
tf.Close()
|
|
|
|
defer os.Remove(tf.Name())
|
|
|
|
|
|
|
|
config := testConfig(t)
|
|
|
|
config["source_path"] = tf.Name()
|
|
|
|
|
|
|
|
delete(config, "floppy_files")
|
|
|
|
warns, err := b.Prepare(config)
|
|
|
|
if len(warns) > 0 {
|
|
|
|
t.Fatalf("bad: %#v", warns)
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("bad err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(b.config.FloppyFiles) != 0 {
|
|
|
|
t.Fatalf("bad: %#v", b.config.FloppyFiles)
|
|
|
|
}
|
|
|
|
|
2016-07-26 15:42:04 -04:00
|
|
|
floppies_path := "../../../common/test-fixtures/floppies"
|
|
|
|
config["floppy_files"] = []string{fmt.Sprintf("%s/bar.bat", floppies_path), fmt.Sprintf("%s/foo.ps1", floppies_path)}
|
2014-05-12 21:24:03 -04: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)
|
|
|
|
}
|
|
|
|
|
2016-07-26 15:42:04 -04:00
|
|
|
expected := []string{fmt.Sprintf("%s/bar.bat", floppies_path), fmt.Sprintf("%s/foo.ps1", floppies_path)}
|
2014-05-12 21:24:03 -04:00
|
|
|
if !reflect.DeepEqual(b.config.FloppyFiles, expected) {
|
|
|
|
t.Fatalf("bad: %#v", b.config.FloppyFiles)
|
|
|
|
}
|
|
|
|
}
|
2016-07-26 15:42:04 -04:00
|
|
|
|
|
|
|
func TestBuilderPrepare_InvalidFloppies(t *testing.T) {
|
|
|
|
var b Builder
|
|
|
|
config := testConfig(t)
|
2017-03-28 20:45:01 -04:00
|
|
|
config["floppy_files"] = []string{"nonexistent.bat", "nonexistent.ps1"}
|
2016-07-26 15:42:04 -04:00
|
|
|
b = Builder{}
|
|
|
|
_, errs := b.Prepare(config)
|
|
|
|
if errs == nil {
|
2017-03-29 15:38:33 -04:00
|
|
|
t.Fatalf("Nonexistent floppies should trigger multierror")
|
2016-07-26 15:42:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if len(errs.(*packer.MultiError).Errors) != 2 {
|
|
|
|
t.Fatalf("Multierror should work and report 2 errors")
|
|
|
|
}
|
|
|
|
}
|