-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathlogs_test.go
73 lines (67 loc) · 1.79 KB
/
logs_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package ecsta_test
import (
"testing"
"time"
"github.com/Songmu/flextime"
"github.com/fujiwara/ecsta"
)
func init() {
flextime.Set(time.Date(2023, 2, 10, 11, 22, 33, 0, time.Local))
}
type logsOptionTest struct {
title string
opt *ecsta.LogsOption
startTime time.Time
endTime time.Time
}
var logsOptionTests = []logsOptionTest{
{
title: "5 minutes ago from now",
opt: &ecsta.LogsOption{
Duration: 5 * time.Minute,
},
startTime: time.Date(2023, 2, 10, 11, 17, 33, 0, time.Local),
endTime: time.Date(2023, 2, 10, 11, 22, 33, 0, time.Local),
},
{
title: "12 minutes ago from start time",
opt: &ecsta.LogsOption{
StartTime: "2023-01-12T22:33:44+09:00",
Duration: 12 * time.Minute,
},
startTime: time.Date(2023, 1, 12, 22, 33, 44, 0, time.FixedZone("JST", 9*60*60)),
endTime: time.Date(2023, 1, 12, 22, 45, 44, 0, time.FixedZone("JST", 9*60*60)),
},
{
opt: &ecsta.LogsOption{
StartTime: "2023-01-02 11:22",
Duration: 1 * time.Minute,
},
startTime: time.Date(2023, 1, 2, 11, 22, 0, 0, time.Local),
endTime: time.Date(2023, 1, 2, 11, 23, 0, 0, time.Local),
},
{
title: "5 minutes ago from now with --follow",
opt: &ecsta.LogsOption{
Duration: 5 * time.Minute,
Follow: true,
},
startTime: time.Date(2023, 2, 10, 11, 17, 33, 0, time.Local),
},
}
func TestLogOptStartTime(t *testing.T) {
for _, tt := range logsOptionTests {
t.Run(tt.title, func(t *testing.T) {
startTime, endTime, err := tt.opt.ResolveTimestamps()
if err != nil {
t.Errorf("failed to resolve start time: %s", err)
}
if startTime.Unix() != tt.startTime.Unix() {
t.Errorf("startTime got %s, want %s", startTime, tt.startTime)
}
if endTime.Unix() != tt.endTime.Unix() {
t.Errorf("endTime got %s, want %s", endTime, tt.endTime)
}
})
}
}