Change args of NewConfig
This commit is contained in:
parent
5310d5629b
commit
210dd08326
|
@ -23,7 +23,7 @@ type Builder struct {
|
||||||
|
|
||||||
// Prepare processes the build configuration parameters.
|
// Prepare processes the build configuration parameters.
|
||||||
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
|
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
|
||||||
c, warnings, errs := NewConfig(TemplateFuncs, raws...)
|
c, warnings, errs := NewConfig(raws...)
|
||||||
if errs != nil {
|
if errs != nil {
|
||||||
return warnings, errs
|
return warnings, errs
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,9 +63,9 @@ type Config struct {
|
||||||
ctx interpolate.Context
|
ctx interpolate.Context
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewConfig(funcMap map[string]interface{}, raws ...interface{}) (*Config, []string, error) {
|
func NewConfig(raws ...interface{}) (*Config, []string, error) {
|
||||||
c := new(Config)
|
c := new(Config)
|
||||||
c.ctx.Funcs = funcMap
|
c.ctx.Funcs = TemplateFuncs
|
||||||
err := config.Decode(c, &config.DecodeOpts{
|
err := config.Decode(c, &config.DecodeOpts{
|
||||||
Interpolate: true,
|
Interpolate: true,
|
||||||
InterpolateContext: &c.ctx,
|
InterpolateContext: &c.ctx,
|
||||||
|
|
|
@ -181,7 +181,7 @@ func TestConfigPrepare(t *testing.T) {
|
||||||
raw[tc.Key] = tc.Value
|
raw[tc.Key] = tc.Value
|
||||||
}
|
}
|
||||||
|
|
||||||
_, warns, errs := NewConfig(TemplateFuncs, raw)
|
_, warns, errs := NewConfig(raw)
|
||||||
|
|
||||||
if tc.Err {
|
if tc.Err {
|
||||||
testConfigErr(t, warns, errs, tc.Key)
|
testConfigErr(t, warns, errs, tc.Key)
|
||||||
|
@ -240,7 +240,7 @@ func TestConfigPrepareAccelerator(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_, warns, errs := NewConfig(TemplateFuncs, raw)
|
_, warns, errs := NewConfig(raw)
|
||||||
|
|
||||||
if tc.Err {
|
if tc.Err {
|
||||||
testConfigErr(t, warns, errs, strings.TrimRight(errStr, ", "))
|
testConfigErr(t, warns, errs, strings.TrimRight(errStr, ", "))
|
||||||
|
@ -269,7 +269,7 @@ func TestConfigDefaults(t *testing.T) {
|
||||||
for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
raw := testConfig(t)
|
raw := testConfig(t)
|
||||||
|
|
||||||
c, warns, errs := NewConfig(TemplateFuncs, raw)
|
c, warns, errs := NewConfig(raw)
|
||||||
testConfigOk(t, warns, errs)
|
testConfigOk(t, warns, errs)
|
||||||
|
|
||||||
actual := tc.Read(c)
|
actual := tc.Read(c)
|
||||||
|
@ -280,7 +280,7 @@ func TestConfigDefaults(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestImageName(t *testing.T) {
|
func TestImageName(t *testing.T) {
|
||||||
c, _, _ := NewConfig(TemplateFuncs, testConfig(t))
|
c, _, _ := NewConfig(testConfig(t))
|
||||||
if !strings.HasPrefix(c.ImageName, "packer-") {
|
if !strings.HasPrefix(c.ImageName, "packer-") {
|
||||||
t.Fatalf("ImageName should have 'packer-' prefix, found %s", c.ImageName)
|
t.Fatalf("ImageName should have 'packer-' prefix, found %s", c.ImageName)
|
||||||
}
|
}
|
||||||
|
@ -290,7 +290,7 @@ func TestImageName(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRegion(t *testing.T) {
|
func TestRegion(t *testing.T) {
|
||||||
c, _, _ := NewConfig(TemplateFuncs, testConfig(t))
|
c, _, _ := NewConfig(testConfig(t))
|
||||||
if c.Region != "us-east1" {
|
if c.Region != "us-east1" {
|
||||||
t.Fatalf("Region should be 'us-east1' given Zone of 'us-east1-a', but is %s", c.Region)
|
t.Fatalf("Region should be 'us-east1' given Zone of 'us-east1-a', but is %s", c.Region)
|
||||||
}
|
}
|
||||||
|
@ -314,7 +314,7 @@ func testConfig(t *testing.T) map[string]interface{} {
|
||||||
}
|
}
|
||||||
|
|
||||||
func testConfigStruct(t *testing.T) *Config {
|
func testConfigStruct(t *testing.T) *Config {
|
||||||
c, warns, errs := NewConfig(TemplateFuncs, testConfig(t))
|
c, warns, errs := NewConfig(testConfig(t))
|
||||||
if len(warns) > 0 {
|
if len(warns) > 0 {
|
||||||
t.Fatalf("bad: %#v", len(warns))
|
t.Fatalf("bad: %#v", len(warns))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue