Skip to content

Commit

Permalink
tests actually test the floppies
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardclau committed Jul 27, 2016
1 parent f9cea9e commit acededf
Show file tree
Hide file tree
Showing 22 changed files with 350 additions and 81 deletions.
18 changes: 0 additions & 18 deletions builder/parallels/common/floppy_config_test.go

This file was deleted.

2 changes: 1 addition & 1 deletion builder/parallels/iso/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type Config struct {
common.PackerConfig `mapstructure:",squash"`
common.HTTPConfig `mapstructure:",squash"`
common.ISOConfig `mapstructure:",squash"`
parallelscommon.FloppyConfig `mapstructure:",squash"`
common.FloppyConfig `mapstructure:",squash"`
parallelscommon.OutputConfig `mapstructure:",squash"`
parallelscommon.PrlctlConfig `mapstructure:",squash"`
parallelscommon.PrlctlPostConfig `mapstructure:",squash"`
Expand Down
54 changes: 53 additions & 1 deletion builder/parallels/iso/builder_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package iso

import (
"github.com/mitchellh/packer/packer"
"fmt"
"reflect"
"testing"

"github.com/mitchellh/packer/packer"
)

func testConfig() map[string]interface{} {
Expand Down Expand Up @@ -46,6 +49,55 @@ func TestBuilderPrepare_Defaults(t *testing.T) {
}
}

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{"nonexistant.bat", "nonexistant.ps1"}
b = Builder{}
_, errs := b.Prepare(config)
if errs == nil {
t.Fatalf("Non existant 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()
Expand Down
2 changes: 1 addition & 1 deletion builder/parallels/pvm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
// Config is the configuration structure for the builder.
type Config struct {
common.PackerConfig `mapstructure:",squash"`
parallelscommon.FloppyConfig `mapstructure:",squash"`
common.FloppyConfig `mapstructure:",squash"`
parallelscommon.OutputConfig `mapstructure:",squash"`
parallelscommon.PrlctlConfig `mapstructure:",squash"`
parallelscommon.PrlctlPostConfig `mapstructure:",squash"`
Expand Down
27 changes: 27 additions & 0 deletions builder/parallels/pvm/config_test.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package pvm

import (
"fmt"
"io/ioutil"
"os"
"testing"

"github.com/mitchellh/packer/packer"
)

func testConfig(t *testing.T) map[string]interface{} {
return map[string]interface{}{
"ssh_username": "foo",
"shutdown_command": "foo",
"parallels_tools_flavor": "lin",
"source_path": "config_test.go",
}
}

Expand Down Expand Up @@ -68,6 +72,29 @@ func TestNewConfig_sourcePath(t *testing.T) {
testConfigOk(t, warns, errs)
}

func TestNewConfig_FloppyFiles(t *testing.T) {
c := testConfig(t)
floppies_path := "../../../common/test-fixtures/floppies"
c["floppy_files"] = []string{fmt.Sprintf("%s/bar.bat", floppies_path), fmt.Sprintf("%s/foo.ps1", floppies_path)}
_, _, err := NewConfig(c)
if err != nil {
t.Fatalf("should not have error: %s", err)
}
}

func TestNewConfig_InvalidFloppies(t *testing.T) {
c := testConfig(t)
c["floppy_files"] = []string{"nonexistant.bat", "nonexistant.ps1"}
_, _, errs := NewConfig(c)
if errs == nil {
t.Fatalf("Non existant floppies should trigger multierror")
}

if len(errs.(*packer.MultiError).Errors) != 2 {
t.Fatalf("Multierror should work and report 2 errors")
}
}

func TestNewConfig_shutdown_timeout(t *testing.T) {
c := testConfig(t)
tf := getTempFile(t)
Expand Down
11 changes: 5 additions & 6 deletions builder/qemu/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ type Config struct {
common.HTTPConfig `mapstructure:",squash"`
common.ISOConfig `mapstructure:",squash"`
Comm communicator.Config `mapstructure:",squash"`
common.FloppyConfig `mapstructure:",squash"`

ISOSkipCache bool `mapstructure:"iso_skip_cache"`
Accelerator string `mapstructure:"accelerator"`
Expand Down Expand Up @@ -139,6 +140,9 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
return nil, err
}

var errs *packer.MultiError
warnings := make([]string, 0)

if b.config.DiskSize == 0 {
b.config.DiskSize = 40000
}
Expand Down Expand Up @@ -215,9 +219,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
b.config.Format = "qcow2"
}

if b.config.FloppyFiles == nil {
b.config.FloppyFiles = make([]string, 0)
}
errs = packer.MultiErrorAppend(errs, b.config.FloppyConfig.Prepare(&b.config.ctx)...)

if b.config.NetDevice == "" {
b.config.NetDevice = "virtio-net"
Expand All @@ -232,9 +234,6 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
b.config.Comm.SSHTimeout = b.config.SSHWaitTimeout
}

var errs *packer.MultiError
warnings := make([]string, 0)

if b.config.ISOSkipCache {
b.config.ISOChecksumType = "none"
}
Expand Down
53 changes: 52 additions & 1 deletion builder/qemu/builder_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package qemu

import (
"github.com/mitchellh/packer/packer"
"fmt"
"io/ioutil"
"os"
"reflect"
"testing"

"github.com/mitchellh/packer/packer"
)

var testPem = `
Expand Down Expand Up @@ -262,6 +264,55 @@ func TestBuilderPrepare_Format(t *testing.T) {
}
}

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{"nonexistant.bat", "nonexistant.ps1"}
b = Builder{}
_, errs := b.Prepare(config)
if errs == nil {
t.Fatalf("Non existant floppies should trigger multierror")
}

if len(errs.(*packer.MultiError).Errors) != 2 {
t.Fatalf("Multierror should work and report 2 errors")
}
}

func TestBuilderPrepare_InvalidKey(t *testing.T) {
var b Builder
config := testConfig()
Expand Down
19 changes: 0 additions & 19 deletions builder/virtualbox/common/floppy_config.go

This file was deleted.

18 changes: 0 additions & 18 deletions builder/virtualbox/common/floppy_config_test.go

This file was deleted.

2 changes: 1 addition & 1 deletion builder/virtualbox/iso/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ type Config struct {
common.PackerConfig `mapstructure:",squash"`
common.HTTPConfig `mapstructure:",squash"`
common.ISOConfig `mapstructure:",squash"`
common.FloppyConfig `mapstructure:",squash"`
vboxcommon.ExportConfig `mapstructure:",squash"`
vboxcommon.ExportOpts `mapstructure:",squash"`
vboxcommon.FloppyConfig `mapstructure:",squash"`
vboxcommon.OutputConfig `mapstructure:",squash"`
vboxcommon.RunConfig `mapstructure:",squash"`
vboxcommon.ShutdownConfig `mapstructure:",squash"`
Expand Down
54 changes: 53 additions & 1 deletion builder/virtualbox/iso/builder_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package iso

import (
"fmt"
"reflect"
"testing"

"github.com/mitchellh/packer/builder/virtualbox/common"
"github.com/mitchellh/packer/packer"
"testing"
)

func testConfig() map[string]interface{} {
Expand Down Expand Up @@ -86,6 +89,55 @@ func TestBuilderPrepare_DiskSize(t *testing.T) {
}
}

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{"nonexistant.bat", "nonexistant.ps1"}
b = Builder{}
_, errs := b.Prepare(config)
if errs == nil {
t.Fatalf("Non existant floppies should trigger multierror")
}

if len(errs.(*packer.MultiError).Errors) != 2 {
t.Fatalf("Multierror should work and report 2 errors")
}
}

func TestBuilderPrepare_GuestAdditionsMode(t *testing.T) {
var b Builder
config := testConfig()
Expand Down
2 changes: 1 addition & 1 deletion builder/virtualbox/ovf/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import (
type Config struct {
common.PackerConfig `mapstructure:",squash"`
common.HTTPConfig `mapstructure:",squash"`
common.FloppyConfig `mapstructure:",squash"`
vboxcommon.ExportConfig `mapstructure:",squash"`
vboxcommon.ExportOpts `mapstructure:",squash"`
vboxcommon.FloppyConfig `mapstructure:",squash"`
vboxcommon.OutputConfig `mapstructure:",squash"`
vboxcommon.RunConfig `mapstructure:",squash"`
vboxcommon.SSHConfig `mapstructure:",squash"`
Expand Down
Loading

0 comments on commit acededf

Please sign in to comment.