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