45 lines
1.1 KiB
Go
45 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)
|
||
|
}
|