common: config strings to slices [GH-950]

pull/919/head
Mitchell Hashimoto 12 years ago
parent edcb8fea30
commit d5981c69f2

@ -14,6 +14,9 @@ FEATURES:
IMPROVEMENTS:
* core: RPC transport between plugins switched to MessagePack
* core: Templates array values can now be comma separated strings.
Most importantly, this allows for user variables to fill
array configurations. [GH-950]
* builder/amazon: Added `ssh_private_key_file` option [GH-971]
* builder/amazon: Added `ami_virtualization_type` option [GH-1021]
* builder/googlecompute: Configurable instance name. [GH-1065]

@ -68,7 +68,10 @@ func DecodeConfig(target interface{}, raws ...interface{}) (*mapstructure.Metada
var md mapstructure.Metadata
decoderConfig := &mapstructure.DecoderConfig{
DecodeHook: decodeHook,
DecodeHook: mapstructure.ComposeDecodeHookFunc(
decodeHook,
mapstructure.StringToSliceHookFunc(","),
),
Metadata: &md,
Result: target,
WeaklyTypedInput: true,

@ -95,6 +95,33 @@ func TestDecodeConfig(t *testing.T) {
}
}
// This test tests the case that a user var is used for an integer
// configuration.
func TestDecodeConfig_stringToSlice(t *testing.T) {
type Local struct {
Val []string
}
raw := map[string]interface{}{
"packer_user_variables": map[string]string{
"foo": "bar",
},
"val": "foo,{{user `foo`}}",
}
var result Local
_, err := DecodeConfig(&result, raw)
if err != nil {
t.Fatalf("err: %s", err)
}
expected := []string{"foo", "bar"}
if !reflect.DeepEqual(result.Val, expected) {
t.Fatalf("invalid: %#v", result.Val)
}
}
// This test tests the case that a user var is used for an integer
// configuration.
func TestDecodeConfig_userVarConversion(t *testing.T) {

Loading…
Cancel
Save