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-05 18:53:52 -05:00
|
|
|
assert.Check(t, duration.Set("300s"))
|
|
|
|
assert.Check(t, is.Equal(time.Duration(300*10e8), *duration.Value()))
|
|
|
|
assert.Check(t, duration.Set("-300s"))
|
|
|
|
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-05 18:53:52 -05:00
|
|
|
assert.Check(t, duration.Set("300s"))
|
|
|
|
assert.Check(t, is.Equal(time.Duration(300*10e8), *duration.Value()))
|
|
|
|
assert.Check(t, is.Error(duration.Set("-300s"), "duration cannot be negative"))
|
2017-05-16 11:49:40 -04:00
|
|
|
}
|