package tool import ( "fmt" "testing" "time" "github.com/stretchr/testify/assert" ) func TestTimeParseLocalUnix(t *testing.T) { t.Run("ok", func(t *testing.T) { testMap := map[string]int64{ "2023-02-22": 1676995200, "2023-02-23": 1677081600, } for localTime, timestamp := range testMap { assert.Equal(t, TimeParseLocalUnix(localTime), timestamp) } }) } func TestGetTargetByValueForTag(t *testing.T) { } func TestStringToTimeUnix(t *testing.T) { // 测试分钟维度 t.Run("minute", func(t *testing.T) { for i := 0; i < 10; i++ { execTime := fmt.Sprintf("0_0_%d", i) want := time.Now().Add(time.Duration(i) * time.Minute).Unix() got := StringToTimeUnix(execTime) assert.Equal(t, want, got) } }) // 测试小时维度 t.Run("hour", func(t *testing.T) { for i := 0; i < 10; i++ { execTime := fmt.Sprintf("0_%d_0", i) want := time.Now().Add(time.Duration(i) * time.Hour).Unix() got := StringToTimeUnix(execTime) assert.Equal(t, want, got) } }) // 测试天维度 t.Run("day", func(t *testing.T) { for i := 0; i < 10; i++ { execTime := fmt.Sprintf("%d_0_0", i) want := time.Now().Add(time.Duration(i) * time.Hour * 24).Unix() got := StringToTimeUnix(execTime) assert.Equal(t, want, got) } }) } func TestGetLocalTime(t *testing.T) { t.Run("ok", func(t *testing.T) { tests := []struct { PushTimeStr string Got int64 }{ { PushTimeStr: "2023-02-28 09:30:00", Got: 1677547800, }, } for _, tt := range tests { want := GetLocalTime(tt.PushTimeStr) assert.Equal(t, want.Unix(), tt.Got) } }) } func TestDemo(t *testing.T) { t.Run("ok", func(t *testing.T) { }) }