mukan-ignite/ignite/pkg/xtime/unix_test.go
Mukan Erkin Törük 26b204bd04
Some checks are pending
Docs Deploy / build_and_deploy (push) Waiting to run
Generate Docs / cli (push) Waiting to run
Generate Config Doc / cli (push) Waiting to run
Go formatting / go-formatting (push) Waiting to run
Check links / markdown-link-check (push) Waiting to run
Integration / pre-test (push) Waiting to run
Integration / test on (push) Blocked by required conditions
Integration / status (push) Blocked by required conditions
Lint / Lint Go code (push) Waiting to run
Test / test (ubuntu-latest) (push) Waiting to run
feat: fork Ignite CLI v29 as Mukan Ignite — remove cosmos-sdk restrictions
2026-05-11 03:31:37 +03:00

68 lines
1.3 KiB
Go

package xtime_test
import (
"fmt"
"testing"
"time"
"github.com/stretchr/testify/require"
"github.com/ignite/cli/v29/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)
})
}
}