mirror of https://github.com/status-im/go-waku.git
test: Add time test
This commit is contained in:
parent
b1284d367d
commit
9ad06b6eb8
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
Loading…
Reference in New Issue