Modify clean_image_name not defined error

pull/5463/head
Atsushi Ishibashi 9 years ago
parent 3600924e59
commit 5310d5629b

@ -23,12 +23,11 @@ type Builder struct {
// Prepare processes the build configuration parameters.
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
c, warnings, errs := NewConfig(raws...)
c, warnings, errs := NewConfig(TemplateFuncs, raws...)
if errs != nil {
return warnings, errs
}
b.config = c
return warnings, nil
}

@ -63,8 +63,9 @@ type Config struct {
ctx interpolate.Context
}
func NewConfig(raws ...interface{}) (*Config, []string, error) {
func NewConfig(funcMap map[string]interface{}, raws ...interface{}) (*Config, []string, error) {
c := new(Config)
c.ctx.Funcs = funcMap
err := config.Decode(c, &config.DecodeOpts{
Interpolate: true,
InterpolateContext: &c.ctx,

@ -181,7 +181,7 @@ func TestConfigPrepare(t *testing.T) {
raw[tc.Key] = tc.Value
}
_, warns, errs := NewConfig(raw)
_, warns, errs := NewConfig(TemplateFuncs, raw)
if tc.Err {
testConfigErr(t, warns, errs, tc.Key)
@ -240,7 +240,7 @@ func TestConfigPrepareAccelerator(t *testing.T) {
}
}
_, warns, errs := NewConfig(raw)
_, warns, errs := NewConfig(TemplateFuncs, raw)
if tc.Err {
testConfigErr(t, warns, errs, strings.TrimRight(errStr, ", "))
@ -269,7 +269,7 @@ func TestConfigDefaults(t *testing.T) {
for _, tc := range cases {
raw := testConfig(t)
c, warns, errs := NewConfig(raw)
c, warns, errs := NewConfig(TemplateFuncs, raw)
testConfigOk(t, warns, errs)
actual := tc.Read(c)
@ -280,7 +280,7 @@ func TestConfigDefaults(t *testing.T) {
}
func TestImageName(t *testing.T) {
c, _, _ := NewConfig(testConfig(t))
c, _, _ := NewConfig(TemplateFuncs, testConfig(t))
if !strings.HasPrefix(c.ImageName, "packer-") {
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) {
c, _, _ := NewConfig(testConfig(t))
c, _, _ := NewConfig(TemplateFuncs, testConfig(t))
if c.Region != "us-east1" {
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 {
c, warns, errs := NewConfig(testConfig(t))
c, warns, errs := NewConfig(TemplateFuncs, testConfig(t))
if len(warns) > 0 {
t.Fatalf("bad: %#v", len(warns))
}

@ -1,7 +1,6 @@
package googlecompute
import (
"regexp"
"strings"
"text/template"
)
@ -19,8 +18,7 @@ func isalphanumeric(b byte) bool {
// Clean up image name by replacing invalid characters with "-"
// truncate up to 63 length, convert to a lower case
func templateCleanImageName(s string) string {
re := regexp.MustCompile(`^[a-z][-a-z0-9]{0,61}[a-z0-9]$`)
if re.MatchString(s) {
if reImageFamily.MatchString(s) {
return s
}
b := []byte(strings.ToLower(s))

Loading…
Cancel
Save