github.com/blend/go-sdk@v1.20220411.3/timeutil/format_duration_test.go (about)

     1  /*
     2  
     3  Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file.
     5  
     6  */
     7  
     8  package timeutil
     9  
    10  import (
    11  	"fmt"
    12  	"testing"
    13  	"time"
    14  
    15  	"github.com/blend/go-sdk/assert"
    16  )
    17  
    18  func TestFormatDuration(t *testing.T) {
    19  	assert := assert.New(t)
    20  
    21  	testCases := [...]struct {
    22  		Input    time.Duration
    23  		Expected string
    24  	}{
    25  		{Input: ((10 * time.Hour) + (9 * time.Minute) + (8 * time.Second) + (7 * time.Millisecond) + (6 * time.Microsecond) + (5 * time.Nanosecond)), Expected: "10h"},
    26  		{Input: ((9 * time.Minute) + (8 * time.Second) + (7 * time.Millisecond) + (6 * time.Microsecond) + (5 * time.Nanosecond)), Expected: "9m"},
    27  		{Input: ((8 * time.Second) + (7 * time.Millisecond) + (6 * time.Microsecond) + (5 * time.Nanosecond)), Expected: "8s"},
    28  		{Input: ((7 * time.Millisecond) + (6 * time.Microsecond) + (5 * time.Nanosecond)), Expected: "7ms"},
    29  		{Input: ((6 * time.Microsecond) + (5 * time.Nanosecond)), Expected: "6µs"},
    30  	}
    31  
    32  	for _, tc := range testCases {
    33  		assert.Equal(tc.Expected, FormatDuration(tc.Input), fmt.Sprintf("%#v", tc))
    34  	}
    35  }