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( DecodeHook: mapstructure.ComposeDecodeHookFunc(
uint8ToStringHook, uint8ToStringHook,
mapstructure.StringToSliceHookFunc(","), mapstructure.StringToSliceHookFunc(","),
mapstructure.StringToTimeDurationHookFunc(),
), ),
}) })
if err != nil { if err != nil {

View File

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