packer-cn/builder/vmware/vmx/builder_test.go

69 lines
1.6 KiB
Go
Raw Normal View History

2013-12-25 17:52:40 -05:00
package vmx
import (
2016-07-26 15:42:04 -04:00
"fmt"
"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"
)
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)
}
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)}
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)}
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)
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
}
if len(errs.(*packersdk.MultiError).Errors) != 2 {
2016-07-26 15:42:04 -04:00
t.Fatalf("Multierror should work and report 2 errors")
}
}