You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
739 B

4 years ago
package value_test
import (
"errors"
"testing"
"time"
"gitoa.ru/go-4devs/config"
9 months ago
"gitoa.ru/go-4devs/config/test/require"
4 years ago
"gitoa.ru/go-4devs/config/value"
)
func TestStringDuration(t *testing.T) {
t.Parallel()
tests := map[string]struct {
raw value.JString
exp time.Duration
err error
}{
"1m": {
raw: value.JString("1m"),
exp: time.Minute,
},
"number error": {
raw: value.JString("100000000"),
err: config.ErrInvalidValue,
},
}
for name, data := range tests {
require.Equal(t, data.exp, data.raw.Duration(), name)
d, err := data.raw.ParseDuration()
require.Truef(t, errors.Is(err, data.err), "%[1]s: expect:%#[2]v, got:%#[3]v", name, data.err, err)
require.Equal(t, data.exp, d, name)
}
}