fix to work with hcl2; update tests
This commit is contained in:
parent
dfb45e86cc
commit
82f03fca7c
|
@ -19,12 +19,12 @@ type Builder struct {
|
|||
func (b *Builder) ConfigSpec() hcldec.ObjectSpec { return b.config.FlatMapstructure().HCL2Spec() }
|
||||
|
||||
func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
|
||||
warnings, errs := b.config.Prepare()
|
||||
warnings, errs := b.config.Prepare(raws...)
|
||||
if errs != nil {
|
||||
return warnings, nil, errs
|
||||
return nil, warnings, errs
|
||||
}
|
||||
|
||||
return warnings, nil, nil
|
||||
return nil, warnings, nil
|
||||
}
|
||||
|
||||
func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
|
||||
|
|
|
@ -6,7 +6,8 @@ import (
|
|||
)
|
||||
|
||||
func TestCloneConfig_MinimalConfig(t *testing.T) {
|
||||
_, warns, errs := NewConfig(minimalConfig())
|
||||
c := new(Config)
|
||||
warns, errs := c.Prepare(minimalConfig())
|
||||
testConfigOk(t, warns, errs)
|
||||
}
|
||||
|
||||
|
@ -15,7 +16,8 @@ func TestCloneConfig_MandatoryParameters(t *testing.T) {
|
|||
for _, param := range params {
|
||||
raw := minimalConfig()
|
||||
raw[param] = ""
|
||||
_, warns, err := NewConfig(raw)
|
||||
c := new(Config)
|
||||
warns, err := c.Prepare(raw)
|
||||
testConfigErr(t, param, warns, err)
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +25,8 @@ func TestCloneConfig_MandatoryParameters(t *testing.T) {
|
|||
func TestCloneConfig_Timeout(t *testing.T) {
|
||||
raw := minimalConfig()
|
||||
raw["shutdown_timeout"] = "3m"
|
||||
conf, warns, err := NewConfig(raw)
|
||||
conf := new(Config)
|
||||
warns, err := conf.Prepare(raw)
|
||||
testConfigOk(t, warns, err)
|
||||
if conf.ShutdownConfig.Timeout != 3*time.Minute {
|
||||
t.Fatalf("shutdown_timeout sould be equal 3 minutes, got %v", conf.ShutdownConfig.Timeout)
|
||||
|
@ -34,7 +37,8 @@ func TestCloneConfig_RAMReservation(t *testing.T) {
|
|||
raw := minimalConfig()
|
||||
raw["RAM_reservation"] = 1000
|
||||
raw["RAM_reserve_all"] = true
|
||||
_, warns, err := NewConfig(raw)
|
||||
c := new(Config)
|
||||
warns, err := c.Prepare(raw)
|
||||
testConfigErr(t, "RAM_reservation", warns, err)
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package iso
|
|||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/hcl/v2/hcldec"
|
||||
"github.com/hashicorp/packer/builder/vsphere/common"
|
||||
"github.com/hashicorp/packer/builder/vsphere/driver"
|
||||
|
@ -19,12 +20,12 @@ type Builder struct {
|
|||
func (b *Builder) ConfigSpec() hcldec.ObjectSpec { return b.config.FlatMapstructure().HCL2Spec() }
|
||||
|
||||
func (b *Builder) Prepare(raws ...interface{}) ([]string, []string, error) {
|
||||
warnings, errs := b.config.Prepare()
|
||||
warnings, errs := b.config.Prepare(raws...)
|
||||
if errs != nil {
|
||||
return warnings, nil, errs
|
||||
return nil, warnings, errs
|
||||
}
|
||||
|
||||
return warnings, nil, nil
|
||||
return nil, warnings, nil
|
||||
}
|
||||
|
||||
func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (packer.Artifact, error) {
|
||||
|
|
|
@ -74,8 +74,8 @@ func (c *Config) Prepare(raws ...interface{}) ([]string, error) {
|
|||
errs = packer.MultiErrorAppend(errs, c.ShutdownConfig.Prepare()...)
|
||||
|
||||
if len(errs.Errors) > 0 {
|
||||
return nil, errs
|
||||
return warnings, errs
|
||||
}
|
||||
|
||||
return nil, nil
|
||||
return warnings, nil
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package config
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strings"
|
||||
|
@ -158,6 +159,9 @@ func DetectContextData(raws ...interface{}) (map[interface{}]interface{}, []inte
|
|||
// In provisioners, the last value pulled from raws is the placeholder data
|
||||
// for build-specific variables. Pull these out to add to interpolation
|
||||
// context.
|
||||
if len(raws) == 0 {
|
||||
return nil, raws
|
||||
}
|
||||
|
||||
// Internally, our tests may cause this to be read as a map[string]string
|
||||
placeholderData := raws[len(raws)-1]
|
||||
|
@ -201,6 +205,7 @@ func DetectContext(raws ...interface{}) (*interpolate.Context, error) {
|
|||
|
||||
for _, r := range raws {
|
||||
if err := mapstructure.Decode(r, &s); err != nil {
|
||||
log.Printf("Error detecting context: %s", err)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue