成本查询限窗过滤;桶级 PAR 放开列举
CI / test (push) Successful in 35s

This commit is contained in:
2026-07-21 19:26:33 +08:00
parent f40f2a20e8
commit 33e92a65e2
9 changed files with 93 additions and 19 deletions
+34
View File
@@ -101,6 +101,40 @@ func TestApplyCostDefaults(t *testing.T) {
}
}
func TestFilterCostWindow(t *testing.T) {
hour := func(h int) *time.Time {
ts := time.Date(2026, 7, 20, h, 0, 0, 0, time.UTC)
return &ts
}
start := time.Date(2026, 7, 20, 16, 0, 0, 0, time.UTC)
end := time.Date(2026, 7, 21, 0, 0, 0, 0, time.UTC)
tests := []struct {
name string
items []oci.CostItem
want int
}{
{name: "空输入", items: []oci.CostItem{}, want: 0},
{name: "窗口前的整日下扩数据被丢弃", items: []oci.CostItem{{TimeStart: hour(0)}, {TimeStart: hour(15)}}, want: 0},
{name: "起点边界含", items: []oci.CostItem{{TimeStart: hour(16)}}, want: 1},
{name: "终点边界不含", items: []oci.CostItem{{TimeStart: &end}}, want: 0},
{name: "TimeStart 缺失丢弃", items: []oci.CostItem{{TimeStart: nil}}, want: 0},
{name: "窗口内外混合只留窗口内", items: []oci.CostItem{{TimeStart: hour(2)}, {TimeStart: hour(16)}, {TimeStart: hour(23)}, {TimeStart: &end}}, want: 2},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := filterCostWindow(tt.items, start, end)
if len(got) != tt.want {
t.Errorf("filterCostWindow() kept %d rows, want %d", len(got), tt.want)
}
for _, it := range got {
if it.TimeStart.Before(start) || !it.TimeStart.Before(end) {
t.Errorf("row %v outside window [%v, %v)", it.TimeStart, start, end)
}
}
})
}
}
func TestValidateEmails(t *testing.T) {
tests := []struct {
name string