helper/config: decode time durations
This commit is contained in:
parent
60081c323a
commit
90581899a4
|
@ -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,
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue