61a47f3e95
Change-Id: I6a5cbdf86eecdc5578f3dae7a8ab1b0d4485e1da
33 lines
863 B
Go
33 lines
863 B
Go
// Copyright (C) 2021 Storj Labs, Inc.
|
|
// See LICENSE for copying information.
|
|
|
|
package main
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestParseHumanDate(t *testing.T) {
|
|
t.Run("test parse relative date", func(t *testing.T) {
|
|
parsed, err := parseHumanDate("+24h")
|
|
require.NoError(t, err)
|
|
require.Less(t, parsed.Unix(), time.Now().Add(25*time.Hour).Unix())
|
|
require.Greater(t, parsed.Unix(), time.Now().Add(23*time.Hour).Unix())
|
|
})
|
|
|
|
t.Run("test parse absolute date", func(t *testing.T) {
|
|
parsed, err := parseHumanDate("2030-02-03T12:13:14+01:00")
|
|
require.NoError(t, err)
|
|
require.Equal(t, "2030-02-03T12:13:14+01:00", parsed.Format(time.RFC3339))
|
|
})
|
|
|
|
t.Run("test parse nonsense", func(t *testing.T) {
|
|
parsed, err := parseHumanDate("999999")
|
|
require.Equal(t, time.Time{}, parsed)
|
|
require.Error(t, err)
|
|
})
|
|
}
|