github.com/ssgreg/logf@v1.4.1/time_test.go (about)

     1  package logf
     2  
     3  import (
     4  	"testing"
     5  	"time"
     6  
     7  	"github.com/stretchr/testify/assert"
     8  )
     9  
    10  func TestRFC3339TimeEncoder(t *testing.T) {
    11  	tm := time.Unix(1542266559, 305941000).UTC()
    12  	enc := testTypeEncoder{}
    13  	RFC3339TimeEncoder(tm, &enc)
    14  
    15  	assert.EqualValues(t, "2018-11-15T07:22:39Z", enc.result)
    16  }
    17  
    18  func TestRFC3339NanoTimeEncoder(t *testing.T) {
    19  	tm := time.Unix(1542266559, 305941000).UTC()
    20  	enc := testTypeEncoder{}
    21  	RFC3339NanoTimeEncoder(tm, &enc)
    22  
    23  	assert.EqualValues(t, "2018-11-15T07:22:39.305941Z", enc.result)
    24  }
    25  
    26  func TestLayoutTimeEncoder(t *testing.T) {
    27  	tm := time.Unix(1542266559, 305941000).UTC()
    28  	enc := testTypeEncoder{}
    29  	LayoutTimeEncoder(time.StampNano)(tm, &enc)
    30  
    31  	assert.EqualValues(t, "Nov 15 07:22:39.305941000", enc.result)
    32  }
    33  
    34  func TestUnixNanoTimeEncoder(t *testing.T) {
    35  	tm := time.Unix(1542266559, 305941000).UTC()
    36  	enc := testTypeEncoder{}
    37  	UnixNanoTimeEncoder(tm, &enc)
    38  
    39  	assert.EqualValues(t, 1542266559305941000, enc.result)
    40  }
    41  
    42  func TestNanoDurationEncoder(t *testing.T) {
    43  	d := time.Duration(66559305941000)
    44  	enc := testTypeEncoder{}
    45  	NanoDurationEncoder(d, &enc)
    46  
    47  	assert.EqualValues(t, 66559305941000, enc.result)
    48  }
    49  
    50  func TestFloatSecondsDurationEncoder(t *testing.T) {
    51  	d := time.Duration(66559305941000)
    52  	enc := testTypeEncoder{}
    53  	FloatSecondsDurationEncoder(d, &enc)
    54  
    55  	assert.InDelta(t, 66559.305941, enc.result, 0.0000005)
    56  }
    57  
    58  func TestStringDurationEncoder(t *testing.T) {
    59  	d := time.Duration(66559305941000)
    60  	enc := testTypeEncoder{}
    61  	StringDurationEncoder(d, &enc)
    62  
    63  	assert.EqualValues(t, "18h29m19.305941s", enc.result)
    64  }