frostfs-s3-gw/internal/frostfs/util/util_test.go
Marina Biryukova f120715a37 [#516] Convert expiration date to epoch
Signed-off-by: Marina Biryukova <m.biryukova@yadro.com>
2024-10-22 14:21:49 +00:00

44 lines
1.1 KiB
Go

package util
import (
"testing"
"time"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/netmap"
"github.com/stretchr/testify/require"
)
func TestTimeToEpoch(t *testing.T) {
ni := netmap.NetworkInfo{}
ni.SetCurrentEpoch(10)
_, err := TimeToEpoch(&ni, time.Now(), time.Now())
require.Error(t, err)
ni.SetEpochDuration(60)
ni.SetMsPerBlock(1000)
epoch, err := TimeToEpoch(&ni, time.Now(), time.Now())
require.NoError(t, err)
require.Equal(t, uint64(10), epoch)
epoch, err = TimeToEpoch(&ni, time.Now(), time.Now().Add(30*time.Second))
require.NoError(t, err)
require.Equal(t, uint64(11), epoch)
epoch, err = TimeToEpoch(&ni, time.Now(), time.Now().Add(90*time.Second))
require.NoError(t, err)
require.Equal(t, uint64(12), epoch)
epoch, err = TimeToEpoch(&ni, time.Now(), time.Now().Add(-30*time.Second))
require.NoError(t, err)
require.Equal(t, uint64(9), epoch)
epoch, err = TimeToEpoch(&ni, time.Now(), time.Now().Add(-90*time.Second))
require.NoError(t, err)
require.Equal(t, uint64(8), epoch)
epoch, err = TimeToEpoch(&ni, time.Now(), time.Now().Add(-10*time.Minute))
require.NoError(t, err)
require.Equal(t, uint64(0), epoch)
}