Commit 90581899 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

helper/config: decode time durations

parent 60081c32
...@@ -66,6 +66,7 @@ func Decode(target interface{}, config *DecodeOpts, raws ...interface{}) error { ...@@ -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 {
......
...@@ -3,6 +3,7 @@ package config ...@@ -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) { ...@@ -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) { ...@@ -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,
}, },
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment