Exemple #1
0
func TestMarshalJSON(t *testing.T) {
	d := jsonutil.Duration{time.Second * 10}
	data, err := d.MarshalJSON()

	require.Nil(t, err)
	require.Equal(t, `"10s"`, string(data))
}
Exemple #2
0
func TestUnmarshalJSON(t *testing.T) {
	s := `"1m"`
	var d jsonutil.Duration
	err := d.UnmarshalJSON([]byte(s))

	require.Nil(t, err)
	require.Equal(t, time.Minute*1, d.Duration)
}