Some checks failed
Docs Deploy / build_and_deploy (push) Has been cancelled
Generate Docs / cli (push) Has been cancelled
Generate Config Doc / cli (push) Has been cancelled
Go formatting / go-formatting (push) Has been cancelled
Check links / markdown-link-check (push) Has been cancelled
Integration / pre-test (push) Has been cancelled
Integration / test on (push) Has been cancelled
Integration / status (push) Has been cancelled
Lint / Lint Go code (push) Has been cancelled
Test / test (ubuntu-latest) (push) Has been cancelled
68 lines
1.3 KiB
Go
68 lines
1.3 KiB
Go
package xtime_test
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"git.cw.tr/mukan-network/mukan-ignite/ignite/pkg/xtime"
|
|
)
|
|
|
|
func TestSeconds(t *testing.T) {
|
|
tests := []int64{
|
|
9999999999,
|
|
10000,
|
|
100,
|
|
0,
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(fmt.Sprintf("test %d value", tt), func(t *testing.T) {
|
|
got := xtime.Seconds(tt)
|
|
require.Equal(t, time.Duration(tt)*time.Second, got)
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestNowAfter(t *testing.T) {
|
|
tests := []int64{
|
|
9999999999,
|
|
10000,
|
|
100,
|
|
0,
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(fmt.Sprintf("test %d value", tt), func(t *testing.T) {
|
|
got := xtime.NowAfter(xtime.Seconds(tt))
|
|
date := time.Now().Add(time.Duration(tt) * time.Second)
|
|
require.Equal(t, date.Format(time.UnixDate), got)
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestFormatUnix(t *testing.T) {
|
|
tests := []struct {
|
|
date time.Time
|
|
want string
|
|
}{
|
|
{
|
|
date: time.Time{},
|
|
want: "Mon Jan 1 00:00:00 UTC 0001",
|
|
},
|
|
{
|
|
date: time.Unix(10000000000, 100).In(time.UTC),
|
|
want: "Sat Nov 20 17:46:40 UTC 2286",
|
|
},
|
|
{
|
|
date: time.Date(2020, 10, 11, 12, 30, 50, 0, time.FixedZone("Europe/Berlin", 3*60*60)),
|
|
want: "Sun Oct 11 12:30:50 Europe/Berlin 2020",
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run("test date "+tt.date.String(), func(t *testing.T) {
|
|
got := xtime.FormatUnix(tt.date)
|
|
require.Equal(t, tt.want, got)
|
|
})
|
|
}
|
|
}
|