2017-05-16 11:49:40 -04:00
|
|
|
package opts
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2018-03-05 18:53:52 -05:00
|
|
|
"github.com/gotestyourself/gotestyourself/assert"
|
|
|
|
is "github.com/gotestyourself/gotestyourself/assert/cmp"
|
2017-05-16 11:49:40 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestDurationOptString(t *testing.T) {
|
|
|
|
dur := time.Duration(300 * 10e8)
|
|
|
|
duration := DurationOpt{value: &dur}
|
2018-03-05 18:53:52 -05:00
|
|
|
assert.Check(t, is.Equal("5m0s", duration.String()))
|
2017-05-16 11:49:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestDurationOptSetAndValue(t *testing.T) {
|
|
|
|
var duration DurationOpt
|
2018-03-06 15:13:00 -05:00
|
|
|
assert.NilError(t, duration.Set("300s"))
|
2018-03-05 18:53:52 -05:00
|
|
|
assert.Check(t, is.Equal(time.Duration(300*10e8), *duration.Value()))
|
2018-03-06 15:13:00 -05:00
|
|
|
assert.NilError(t, duration.Set("-300s"))
|
2018-03-05 18:53:52 -05:00
|
|
|
assert.Check(t, is.Equal(time.Duration(-300*10e8), *duration.Value()))
|
2017-05-16 11:49:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestPositiveDurationOptSetAndValue(t *testing.T) {
|
|
|
|
var duration PositiveDurationOpt
|
2018-03-06 15:13:00 -05:00
|
|
|
assert.NilError(t, duration.Set("300s"))
|
2018-03-05 18:53:52 -05:00
|
|
|
assert.Check(t, is.Equal(time.Duration(300*10e8), *duration.Value()))
|
2018-03-06 15:54:24 -05:00
|
|
|
assert.Error(t, duration.Set("-300s"), "duration cannot be negative")
|
2017-05-16 11:49:40 -04:00
|
|
|
}
|