mirror of https://github.com/hashicorp/packer
Merge pull request #3756 from ricardclau/floppy_check
Test floppy disks actually existpull/3869/merge
commit
5cbc36103e
@ -1,18 +0,0 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestFloppyConfigPrepare(t *testing.T) {
|
||||
c := new(FloppyConfig)
|
||||
|
||||
errs := c.Prepare(testConfigTemplate(t))
|
||||
if len(errs) > 0 {
|
||||
t.Fatalf("err: %#v", errs)
|
||||
}
|
||||
|
||||
if len(c.FloppyFiles) > 0 {
|
||||
t.Fatal("should not have floppy files")
|
||||
}
|
||||
}
|
||||
@ -1,19 +0,0 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"github.com/mitchellh/packer/template/interpolate"
|
||||
)
|
||||
|
||||
// FloppyConfig is configuration related to created floppy disks and attaching
|
||||
// them to a VirtualBox machine.
|
||||
type FloppyConfig struct {
|
||||
FloppyFiles []string `mapstructure:"floppy_files"`
|
||||
}
|
||||
|
||||
func (c *FloppyConfig) Prepare(ctx *interpolate.Context) []error {
|
||||
if c.FloppyFiles == nil {
|
||||
c.FloppyFiles = make([]string, 0)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@ -1,18 +0,0 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestFloppyConfigPrepare(t *testing.T) {
|
||||
c := new(FloppyConfig)
|
||||
|
||||
errs := c.Prepare(testConfigTemplate(t))
|
||||
if len(errs) > 0 {
|
||||
t.Fatalf("err: %#v", errs)
|
||||
}
|
||||
|
||||
if len(c.FloppyFiles) > 0 {
|
||||
t.Fatal("should not have floppy files")
|
||||
}
|
||||
}
|
||||
@ -1,19 +1,28 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/mitchellh/packer/template/interpolate"
|
||||
)
|
||||
|
||||
// FloppyConfig is configuration related to created floppy disks and attaching
|
||||
// them to a Parallels virtual machine.
|
||||
type FloppyConfig struct {
|
||||
FloppyFiles []string `mapstructure:"floppy_files"`
|
||||
}
|
||||
|
||||
func (c *FloppyConfig) Prepare(ctx *interpolate.Context) []error {
|
||||
var errs []error
|
||||
|
||||
if c.FloppyFiles == nil {
|
||||
c.FloppyFiles = make([]string, 0)
|
||||
}
|
||||
|
||||
return nil
|
||||
for _, path := range c.FloppyFiles {
|
||||
if _, err := os.Stat(path); err != nil {
|
||||
errs = append(errs, fmt.Errorf("Bad Floppy disk file '%s': %s", path, err))
|
||||
}
|
||||
}
|
||||
|
||||
return errs
|
||||
}
|
||||
@ -0,0 +1,70 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNilFloppies(t *testing.T) {
|
||||
c := FloppyConfig{}
|
||||
errs := c.Prepare(nil)
|
||||
if len(errs) != 0 {
|
||||
t.Fatal("nil floppies array should not fail")
|
||||
}
|
||||
|
||||
if len(c.FloppyFiles) > 0 {
|
||||
t.Fatal("struct should not have floppy files")
|
||||
}
|
||||
}
|
||||
|
||||
func TestEmptyArrayFloppies(t *testing.T) {
|
||||
c := FloppyConfig{
|
||||
FloppyFiles: make([]string, 0),
|
||||
}
|
||||
|
||||
errs := c.Prepare(nil)
|
||||
if len(errs) != 0 {
|
||||
t.Fatal("empty floppies array should never fail")
|
||||
}
|
||||
|
||||
if len(c.FloppyFiles) > 0 {
|
||||
t.Fatal("struct should not have floppy files")
|
||||
}
|
||||
}
|
||||
|
||||
func TestExistingFloppyFile(t *testing.T) {
|
||||
c := FloppyConfig{
|
||||
FloppyFiles: []string{"floppy_config.go"},
|
||||
}
|
||||
|
||||
errs := c.Prepare(nil)
|
||||
if len(errs) != 0 {
|
||||
t.Fatal("array with existing floppies should not fail")
|
||||
}
|
||||
}
|
||||
|
||||
func TestNonExistingFloppyFile(t *testing.T) {
|
||||
c := FloppyConfig{
|
||||
FloppyFiles: []string{"floppy_config.foo"},
|
||||
}
|
||||
|
||||
errs := c.Prepare(nil)
|
||||
if len(errs) == 0 {
|
||||
t.Fatal("array with non existing floppies should return errors")
|
||||
}
|
||||
}
|
||||
|
||||
func TestMultiErrorFloppyFiles(t *testing.T) {
|
||||
c := FloppyConfig{
|
||||
FloppyFiles: []string{"floppy_config.foo", "floppy_config.go", "floppy_config.bar", "floppy_config_test.go", "floppy_config.baz"},
|
||||
}
|
||||
|
||||
errs := c.Prepare(nil)
|
||||
if len(errs) == 0 {
|
||||
t.Fatal("array with non existing floppies should return errors")
|
||||
}
|
||||
|
||||
expectedErrors := 3
|
||||
if count := len(errs); count != expectedErrors {
|
||||
t.Fatalf("array with %v non existing floppy should return %v errors but it is returning %v", expectedErrors, expectedErrors, count)
|
||||
}
|
||||
}
|
||||
@ -0,0 +1 @@
|
||||
Echo I am a floppy with a batch file
|
||||
@ -0,0 +1 @@
|
||||
Write-Host "I am a floppy with some Powershell"
|
||||
Loading…
Reference in new issue