代码拉取完成,页面将自动刷新
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"),
},
},
)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。