* Drop the iso_checksum_type & iso_checksum_url fields In favor of simply using iso_checksum that will know what to do. * fix after master merge * Update builder_test.go * Update builder_test.go * Update builder_test.go * Update builder_test.go * Update builder_test.go * remove checksum lowercasing tests * Update builder_test.go * Update builder_test.go * better docs * Update builder_test.go * even better docs * Update config.go * Update builder_test.go * Update step_create_vmx_test.go * make generate * better docs * fix imports * up tests * Update _ISOConfig-required.html.md * Update builder_test.go * don't use sha1.Sum("none") as a caching path * Update builder_test.go * better docs * Update iso_config_test.go remove ISOChecksumType/ISOChecksumURL references * Update step_download_test.go * add iso_checksum_url and iso_checksum_type fixers + tests * add concrete examples of checksum values * add examples of checksumming from local file * update go-getter dep * up deps * use new go-getter version * up ESX5Driver.VerifyChecksum: use go-getter's checksumming * ISOConfig.Prepare: get checksum there in case we need it as a string in ESX5Driver.VerifyChecksum * Update iso_config.go * get go-getter from v2 branch * Update driver_esx5.go add more comments * Update driver_esx5.go * show better error message when the checksum is invalid * Update builder_test.go put in a valid checksum to fix tests, checksum is md5("packer") * Update builder_test.go test invalid and valid checksum * more test updating * fix default md5 string to be a valid md5 * TestChecksumFileNameMixedCaseBug: use 'file:' prefix for file checksumming * Update iso_config_test.go * Update iso_config_test.go * Update builder_test.go * Update builder_test.go * Update builder_test.go * Update CHANGELOG.md * Update CHANGELOG.md * Update go.mod * Update go.mod * Update CHANGELOG.md
242 lines
5.2 KiB
Go
242 lines
5.2 KiB
Go
package iso
|
|
|
|
import (
|
|
"fmt"
|
|
"reflect"
|
|
"testing"
|
|
|
|
"github.com/hashicorp/packer/packer"
|
|
)
|
|
|
|
func testConfig() map[string]interface{} {
|
|
return map[string]interface{}{
|
|
"iso_checksum": "md5:0B0F137F17AC10944716020B018F8126",
|
|
"iso_url": "http://www.google.com/",
|
|
"shutdown_command": "yes",
|
|
"ssh_username": "foo",
|
|
"parallels_tools_flavor": "lin",
|
|
|
|
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.GuestOSType != "other" {
|
|
t.Errorf("bad guest OS type: %s", b.config.GuestOSType)
|
|
}
|
|
|
|
if b.config.VMName != "packer-foo" {
|
|
t.Errorf("bad vm name: %s", b.config.VMName)
|
|
}
|
|
}
|
|
|
|
func TestBuilderPrepare_FloppyFiles(t *testing.T) {
|
|
var b Builder
|
|
config := testConfig()
|
|
|
|
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)
|
|
}
|
|
|
|
floppies_path := "../../../common/test-fixtures/floppies"
|
|
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)
|
|
}
|
|
|
|
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)
|
|
}
|
|
}
|
|
|
|
func TestBuilderPrepare_InvalidFloppies(t *testing.T) {
|
|
var b Builder
|
|
config := testConfig()
|
|
config["floppy_files"] = []string{"nonexistent.bat", "nonexistent.ps1"}
|
|
b = Builder{}
|
|
_, _, errs := b.Prepare(config)
|
|
if errs == nil {
|
|
t.Fatalf("Nonexistent floppies should trigger multierror")
|
|
}
|
|
|
|
if len(errs.(*packer.MultiError).Errors) != 2 {
|
|
t.Fatalf("Multierror should work and report 2 errors")
|
|
}
|
|
}
|
|
|
|
func TestBuilderPrepare_DiskSize(t *testing.T) {
|
|
var b Builder
|
|
config := testConfig()
|
|
|
|
delete(config, "disk_size")
|
|
_, warns, err := b.Prepare(config)
|
|
if len(warns) > 0 {
|
|
t.Fatalf("bad: %#v", warns)
|
|
}
|
|
if err != nil {
|
|
t.Fatalf("bad err: %s", err)
|
|
}
|
|
|
|
if b.config.DiskSize != 40000 {
|
|
t.Fatalf("bad size: %d", b.config.DiskSize)
|
|
}
|
|
|
|
config["disk_size"] = 60000
|
|
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)
|
|
}
|
|
|
|
if b.config.DiskSize != 60000 {
|
|
t.Fatalf("bad size: %d", b.config.DiskSize)
|
|
}
|
|
}
|
|
|
|
func TestBuilderPrepare_DiskType(t *testing.T) {
|
|
var b Builder
|
|
config := testConfig()
|
|
|
|
// Test a default disk_type
|
|
delete(config, "disk_type")
|
|
_, warns, err := b.Prepare(config)
|
|
if len(warns) > 0 {
|
|
t.Fatalf("bad: %#v", warns)
|
|
}
|
|
if err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
|
|
if b.config.DiskType != "expand" {
|
|
t.Fatalf("bad: %s", b.config.DiskType)
|
|
}
|
|
|
|
// Test with a bad
|
|
config["disk_type"] = "fake"
|
|
b = Builder{}
|
|
_, warns, err = b.Prepare(config)
|
|
if len(warns) > 0 {
|
|
t.Fatalf("bad: %#v", warns)
|
|
}
|
|
if err == nil {
|
|
t.Fatal("should have error")
|
|
}
|
|
|
|
// Test with plain disk with wrong setting for compaction
|
|
config["disk_type"] = "plain"
|
|
config["skip_compaction"] = false
|
|
b = Builder{}
|
|
_, warns, err = b.Prepare(config)
|
|
if len(warns) == 0 {
|
|
t.Fatalf("should have warning")
|
|
}
|
|
if err != nil {
|
|
t.Fatalf("should not have error: %s", err)
|
|
}
|
|
|
|
// Test with plain disk with correct setting for compaction
|
|
config["disk_type"] = "plain"
|
|
config["skip_compaction"] = true
|
|
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_HardDriveInterface(t *testing.T) {
|
|
var b Builder
|
|
config := testConfig()
|
|
|
|
// Test a default boot_wait
|
|
delete(config, "hard_drive_interface")
|
|
_, warns, err := b.Prepare(config)
|
|
if len(warns) > 0 {
|
|
t.Fatalf("bad: %#v", warns)
|
|
}
|
|
if err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
|
|
if b.config.HardDriveInterface != "sata" {
|
|
t.Fatalf("bad: %s", b.config.HardDriveInterface)
|
|
}
|
|
|
|
// Test with a bad
|
|
config["hard_drive_interface"] = "fake"
|
|
b = Builder{}
|
|
_, warns, err = b.Prepare(config)
|
|
if len(warns) > 0 {
|
|
t.Fatalf("bad: %#v", warns)
|
|
}
|
|
if err == nil {
|
|
t.Fatal("should have error")
|
|
}
|
|
|
|
// Test with a good
|
|
config["hard_drive_interface"] = "scsi"
|
|
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")
|
|
}
|
|
}
|