test: Add time test

This commit is contained in:
Anthony Laibe 2021-10-18 15:48:04 +02:00
parent b1284d367d
commit 9ad06b6eb8
2 changed files with 24 additions and 2 deletions

View File

@ -2,6 +2,10 @@ package utils
import "time"
func GetUnixEpoch() float64 {
return float64(time.Now().UnixNano()) / float64(time.Second)
func GetUnixEpochFrom(now func() time.Time) float64 {
return float64(now().UnixNano()) / float64(time.Second)
}
func GetUnixEpoch() float64 {
return GetUnixEpochFrom(time.Now)
}

View File

@ -0,0 +1,18 @@
package utils
import (
"testing"
"time"
"github.com/stretchr/testify/require"
)
func TestGetUnixEpochFrom(t *testing.T) {
loc := time.UTC
timeFn := func() time.Time {
return time.Date(2019, 1, 1, 0, 0, 0, 0, loc)
}
timestamp := GetUnixEpochFrom(timeFn)
require.Equal(t, float64(1546300800), timestamp)
}