3 Star 0 Fork 1

Gitee 极速下载/GoAlert

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/target/goalert
克隆/下载
usercalculator_test.go 2.51 KB
一键复制 编辑 原始数据 按行查看 历史
Mitch Cimenski 提交于 2021-03-31 15:16 . removing unused func cloneSlice
package oncall_test
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/target/goalert/oncall"
)
func TestUserCalculator(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, setup func(*oncall.UserCalculator)) {
t.Run(desc, func(t *testing.T) {
iter := oncall.NewTimeIterator(
start,
end,
time.Minute,
).NewUserCalculator()
if setup != nil {
setup(iter)
}
iter.Init()
var count int
for iter.Next() {
i := count
count++
if count > len(expected) {
t.Errorf("unexpected result: Value=%v, Time=%d", iter.ActiveUsers(), iter.Unix())
continue
}
if len(expected[i].Value) > 0 || len(iter.ActiveUsers()) > 0 {
assert.EqualValuesf(t, expected[i].Value, iter.ActiveUsers(), "result[%d].Value", i)
}
assert.Equalf(t, expected[i].Time.String(), time.Unix(iter.Unix(), 0).UTC().String(), "result[%d].Time", i)
}
if count != len(expected) {
t.Errorf("got %d results; want %d", count, len(expected))
}
})
}
check("empty",
[]result{
{Time: start},
{Time: end},
},
nil,
)
check("simple",
[]result{
{Time: start},
{Time: time.Date(2000, 1, 2, 3, 5, 0, 0, time.UTC), Value: []string{"foo"}},
{Time: time.Date(2000, 1, 2, 3, 7, 0, 0, time.UTC)},
{Time: end},
},
func(iter *oncall.UserCalculator) {
iter.SetSpan(time.Date(2000, 1, 2, 3, 5, 0, 0, time.UTC), time.Date(2000, 1, 2, 3, 7, 0, 0, time.UTC), "foo")
},
)
check("at-start",
[]result{
{Time: time.Date(2000, 1, 2, 3, 3, 0, 0, time.UTC), Value: []string{"foo"}},
{Time: time.Date(2000, 1, 2, 3, 7, 0, 0, time.UTC)},
{Time: end},
},
func(iter *oncall.UserCalculator) {
iter.SetSpan(time.Date(2000, 1, 2, 3, 3, 0, 0, time.UTC), time.Date(2000, 1, 2, 3, 7, 0, 0, time.UTC), "foo")
},
)
check("multiple",
[]result{
{Time: start},
{Time: time.Date(2000, 1, 2, 3, 5, 0, 0, time.UTC), Value: []string{"foo"}},
{Time: time.Date(2000, 1, 2, 3, 6, 0, 0, time.UTC), Value: []string{"foo", "bar"}},
{Time: time.Date(2000, 1, 2, 3, 7, 0, 0, time.UTC)},
{Time: end},
},
func(iter *oncall.UserCalculator) {
iter.SetSpan(time.Date(2000, 1, 2, 3, 5, 0, 0, time.UTC), time.Date(2000, 1, 2, 3, 7, 0, 0, time.UTC), "foo")
iter.SetSpan(time.Date(2000, 1, 2, 3, 6, 0, 0, time.UTC), time.Date(2000, 1, 2, 3, 7, 0, 0, time.UTC), "bar")
},
)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/mirrors/GoAlert.git
git@gitee.com:mirrors/GoAlert.git
mirrors
GoAlert
GoAlert
master

搜索帮助