helper/config: decode time durations

This commit is contained in:
Mitchell Hashimoto 2015-06-13 17:53:45 -04:00
parent 60081c323a
commit 90581899a4
2 changed files with 5 additions and 0 deletions

View File

@ -66,6 +66,7 @@ func Decode(target interface{}, config *DecodeOpts, raws ...interface{}) error {
DecodeHook: mapstructure.ComposeDecodeHookFunc(
uint8ToStringHook,
mapstructure.StringToSliceHookFunc(","),
mapstructure.StringToTimeDurationHookFunc(),
),
})
if err != nil {

View File

@ -3,6 +3,7 @@ package config
import (
"reflect"
"testing"
"time"
"github.com/mitchellh/packer/template/interpolate"
)
@ -11,6 +12,7 @@ func TestDecode(t *testing.T) {
type Target struct {
Name string
Address string
Time time.Duration
}
cases := map[string]struct {
@ -22,10 +24,12 @@ func TestDecode(t *testing.T) {
[]interface{}{
map[string]interface{}{
"name": "bar",
"time": "5s",
},
},
&Target{
Name: "bar",
Time: 5 * time.Second,
},
nil,
},