github.com/pwn-term/docker@v0.0.0-20210616085119-6e977cce2565/cli/opts/duration_test.go (about)

     1  package opts
     2  
     3  import (
     4  	"testing"
     5  	"time"
     6  
     7  	"gotest.tools/v3/assert"
     8  	is "gotest.tools/v3/assert/cmp"
     9  )
    10  
    11  func TestDurationOptString(t *testing.T) {
    12  	dur := time.Duration(300 * 10e8)
    13  	duration := DurationOpt{value: &dur}
    14  	assert.Check(t, is.Equal("5m0s", duration.String()))
    15  }
    16  
    17  func TestDurationOptSetAndValue(t *testing.T) {
    18  	var duration DurationOpt
    19  	assert.NilError(t, duration.Set("300s"))
    20  	assert.Check(t, is.Equal(time.Duration(300*10e8), *duration.Value()))
    21  	assert.NilError(t, duration.Set("-300s"))
    22  	assert.Check(t, is.Equal(time.Duration(-300*10e8), *duration.Value()))
    23  }
    24  
    25  func TestPositiveDurationOptSetAndValue(t *testing.T) {
    26  	var duration PositiveDurationOpt
    27  	assert.NilError(t, duration.Set("300s"))
    28  	assert.Check(t, is.Equal(time.Duration(300*10e8), *duration.Value()))
    29  	assert.Error(t, duration.Set("-300s"), "duration cannot be negative")
    30  }