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
|
|
|
|
2020-12-17 16:29:25 -05:00
|
|
|
packersdk "github.com/hashicorp/packer-plugin-sdk/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")
|
2019-12-17 00:23:05 -05:00
|
|
|
_, warns, err := b.Prepare(config)
|
2014-05-12 21:24:03 -04:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2020-12-17 17:41:36 -05:00
|
|
|
floppies_path := "../../test-fixtures/floppies"
|
2016-07-26 15:42:04 -04:00
|
|
|
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{}
|
2019-12-17 00:23:05 -05:00
|
|
|
_, warns, err = b.Prepare(config)
|
2014-05-12 21:24:03 -04:00
|
|
|
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{}
|
2019-12-17 00:23:05 -05:00
|
|
|
_, _, errs := b.Prepare(config)
|
2016-07-26 15:42:04 -04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-11-19 15:07:02 -05:00
|
|
|
if len(errs.(*packersdk.MultiError).Errors) != 2 {
|
2016-07-26 15:42:04 -04:00
|
|
|
t.Fatalf("Multierror should work and report 2 errors")
|
|
|
|
}
|
|
|
|
}
|