mirror of
https://github.com/luxfi/cli.git
synced 2026-10-30 17:01:20 +00:00
- Update github.com/luxfi/netrunner v1.15.3 → v1.15.4 - Update github.com/luxfi/node v1.22.77 → v1.22.80 - Remove local replace directive for netrunner - Use published package versions for reproducible builds
81 lines
1.5 KiB
Go
81 lines
1.5 KiB
Go
// Copyright (C) 2022-2025, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package ux
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestDurationFormat(t *testing.T) {
|
|
require := require.New(t)
|
|
|
|
type test struct {
|
|
d time.Duration
|
|
expected string
|
|
}
|
|
|
|
tests := []test{
|
|
{
|
|
d: 972 * 24 * time.Hour,
|
|
expected: "2 years 242 days ",
|
|
},
|
|
{
|
|
d: 364 * 24 * time.Hour,
|
|
expected: "364 days ",
|
|
},
|
|
{
|
|
d: 42 * 24 * time.Hour,
|
|
expected: "42 days ",
|
|
},
|
|
{
|
|
d: 1 * 24 * time.Hour,
|
|
expected: "1 days ",
|
|
},
|
|
{
|
|
d: 23 * time.Hour,
|
|
expected: "23 hours ",
|
|
},
|
|
{
|
|
d: 42*time.Hour + 42*time.Minute,
|
|
expected: "1 days 18 hours 42 minutes ",
|
|
},
|
|
{
|
|
d: 42 * time.Minute,
|
|
expected: "42 minutes ",
|
|
},
|
|
{
|
|
d: 42*time.Minute + 42*time.Second,
|
|
expected: "42 minutes 42 seconds ",
|
|
},
|
|
{
|
|
d: 42 * time.Second,
|
|
expected: "42 seconds ",
|
|
},
|
|
{
|
|
d: 342*24*time.Hour + 42*time.Second,
|
|
expected: "342 days 42 seconds ",
|
|
},
|
|
{
|
|
d: 342*24*time.Hour + 1*time.Hour + 42*time.Second,
|
|
expected: "342 days 1 hours 42 seconds ",
|
|
},
|
|
{
|
|
d: 342*24*time.Hour + 42*time.Minute + 42*time.Second,
|
|
expected: "342 days 42 minutes 42 seconds ",
|
|
},
|
|
{
|
|
d: 342*24*time.Hour + 42*time.Minute,
|
|
expected: "342 days 42 minutes ",
|
|
},
|
|
}
|
|
|
|
for _, t := range tests {
|
|
s := FormatDuration(t.d)
|
|
require.Equal(t.expected, s)
|
|
}
|
|
}
|