storj/cmd/uplink/stdlib_flags_test.go
Egon Elbre 05e165283f storagenode/console/consoleapi: use fixed time.Now()
It seems the tests relied on time.Now(), which might cause some
discrepancies in calculations. Use a fixed time.Now() rather than
recalculating.

As a sidefix, remove "Test" prefix from t.Run. These are unnecessary.

Change-Id: I1de903fcf0fcf46fc8e3acf2463e17239b8e3cc6
2022-07-01 12:36:01 +03:00

33 lines
848 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("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("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("parse nonsense", func(t *testing.T) {
parsed, err := parseHumanDate("999999")
require.Equal(t, time.Time{}, parsed)
require.Error(t, err)
})
}