do validation in vmx config stage
This commit is contained in:
parent
0efcb1bba2
commit
0d18de2942
|
@ -2,6 +2,7 @@ package ovf
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
vboxcommon "github.com/hashicorp/packer/builder/virtualbox/common"
|
||||
|
@ -101,6 +102,13 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
|
|||
if err != nil {
|
||||
errs = packer.MultiErrorAppend(errs, fmt.Errorf("source_path is invalid: %s", err))
|
||||
}
|
||||
// file must exist now.
|
||||
if (len(c.SourcePath) > 7) && (c.SourcePath[:7] == "file://") {
|
||||
if _, err := os.Stat(c.SourcePath[7:]); err != nil {
|
||||
errs = packer.MultiErrorAppend(errs,
|
||||
fmt.Errorf("source file needs to exist at time of config validation: %s", err))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
validMode := false
|
||||
|
|
|
@ -65,14 +65,14 @@ func TestNewConfig_sourcePath(t *testing.T) {
|
|||
t.Fatalf("should error with empty `source_path`")
|
||||
}
|
||||
|
||||
// Okay, because it gets caught during download
|
||||
// Want this to fail on validation
|
||||
c = testConfig(t)
|
||||
c["source_path"] = "/i/dont/exist"
|
||||
_, warns, err = NewConfig(c)
|
||||
if len(warns) > 0 {
|
||||
t.Fatalf("bad: %#v", warns)
|
||||
}
|
||||
if err != nil {
|
||||
if err == nil {
|
||||
t.Fatalf("bad: %s", err)
|
||||
}
|
||||
|
||||
|
@ -84,7 +84,7 @@ func TestNewConfig_sourcePath(t *testing.T) {
|
|||
t.Fatalf("bad: %#v", warns)
|
||||
}
|
||||
if err == nil {
|
||||
t.Fatal("should error")
|
||||
t.Fatal("Nonexistent source file should be caught in validation")
|
||||
}
|
||||
|
||||
// Good
|
||||
|
|
Loading…
Reference in New Issue