-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtable_test.go
74 lines (62 loc) · 2.07 KB
/
table_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
74
package bqwt
import (
"github.com/stretchr/testify/assert"
"github.com/viant/toolbox"
"testing"
"time"
)
func TestNewWindowedTable(t *testing.T) {
{ //from to withing a week case
now := time.Now()
nineDaysAgo, _ := toolbox.TimeDiff(now, "5DaysAgo")
windowedTable := NewWindowedTable(&TableInfo{
ProjectID: "p",
DatasetID: "d",
TableID: "t",
Created: *nineDaysAgo,
LastModified: now,
}, now)
assert.Equal(t, nineDaysAgo.Unix(), windowedTable.Window.From.Unix())
assert.Equal(t, now, windowedTable.Window.To)
}
{ //from to exceeded a week case
now := time.Now()
nineDaysAgo, _ := toolbox.TimeDiff(now, "9DaysAgo")
weekAgo, _ := toolbox.TimeDiff(now, "7DaysAgo")
windowedTable := NewWindowedTable(&TableInfo{
ProjectID: "p",
DatasetID: "d",
TableID: "t",
Created: *nineDaysAgo,
LastModified: now,
}, now)
assert.Equal(t, weekAgo.Unix(), windowedTable.Window.From.Unix())
assert.Equal(t, now, windowedTable.Window.To)
}
{ //from to exceeded a week case
now := time.Now()
nineDaysAgo, _ := toolbox.TimeDiff(now, "8DaysAgo")
eightDaysAgo, _ := toolbox.TimeDiff(now, "8DaysAgo")
weekAgo, _ := toolbox.TimeDiff(now, "7DaysAgo")
windowedTable := NewWindowedTable(&TableInfo{
ProjectID: "p",
DatasetID: "d",
TableID: "t",
Created: *nineDaysAgo,
LastModified: *eightDaysAgo,
}, now)
assert.Equal(t, -1+time.Duration(weekAgo.UnixNano())/time.Millisecond, time.Duration(windowedTable.Window.From.UnixNano())/time.Millisecond)
assert.Equal(t, weekAgo.UnixNano(), windowedTable.Window.To.UnixNano())
}
}
func TestWindowTableNoChangeExpressions(t *testing.T) {
windowedTable := NewWindowedTable(&TableInfo{
ProjectID: "p",
DatasetID: "d",
TableID: "t",
Created: time.Unix(1565121000, 0),
LastModified: time.Unix(1565121999, 0),
}, time.Unix(1565121999, 0))
assert.Equal(t, "[p:d.t@1565121999001-1565121999001]", windowedTable.FormatUnchangedAbsoluteExpr())
assert.Equal(t, "[d.t@1565121999001-1565121999001]", windowedTable.FormatUnchangedExpr())
}