3 Star 0 Fork 1

Gitee 极速下载/GoAlert

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/target/goalert
克隆/下载
singlerulecalculator_test.go 1.40 KB
一键复制 编辑 原始数据 按行查看 历史
Nathaniel Caza 提交于 2021-05-21 12:54 . move WeekdayFilter to timeutils
package oncall_test
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/target/goalert/assignment"
"github.com/target/goalert/oncall"
"github.com/target/goalert/schedule/rule"
"github.com/target/goalert/util/timeutil"
)
func TestSingleRuleCalculator(t *testing.T) {
type result struct {
Time time.Time
Value string
}
var (
start = time.Date(2000, 1, 2, 3, 4, 0, 0, time.UTC)
end = time.Date(2000, 1, 2, 3, 8, 0, 0, time.UTC)
)
check := func(desc string, expected []result, rule oncall.ResolvedRule) {
t.Run(desc, func(t *testing.T) {
iter := oncall.NewTimeIterator(
start,
end,
time.Minute,
).NewSingleRuleCalculator(time.UTC, rule)
var results []result
for iter.Next() {
results = append(results, result{Time: time.Unix(iter.Unix(), 0).UTC(), Value: iter.ActiveUser()})
}
assert.EqualValues(t, expected, results)
})
}
check("empty",
[]result{
{Time: start},
{Time: end},
},
oncall.ResolvedRule{},
)
check("simple",
[]result{
{Time: start},
{Time: time.Date(2000, 1, 2, 3, 5, 0, 0, time.UTC), Value: "foo"},
{Time: time.Date(2000, 1, 2, 3, 7, 0, 0, time.UTC)},
{Time: end},
},
oncall.ResolvedRule{
Rule: rule.Rule{
Start: timeutil.NewClock(3, 5),
End: timeutil.NewClock(3, 7),
WeekdayFilter: timeutil.EveryDay(),
Target: assignment.UserTarget("foo"),
},
},
)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/mirrors/GoAlert.git
git@gitee.com:mirrors/GoAlert.git
mirrors
GoAlert
GoAlert
master

搜索帮助