1 Star 0 Fork 0

CNCF/devstatscode

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
annotations_test.go 2.16 KB
一键复制 编辑 原始数据 按行查看 历史
Lukasz Gryglicki 提交于 2019-03-21 17:05 +08:00 . Moved package [wip]
package devstatscode
import (
"reflect"
"testing"
"time"
lib "github.com/cncf/devstatscode"
testlib "github.com/cncf/devstatscode/test"
)
func TestGetFakeAnnotations(t *testing.T) {
// Example data
ft := testlib.YMDHMS
startDate := []time.Time{ft(2014), ft(2015), ft(2015), ft(2012)}
joinDate := []time.Time{ft(2015), ft(2015), ft(2014), ft(2013)}
// Test cases
var testCases = []struct {
startDate time.Time
joinDate time.Time
expectedAnnotations lib.Annotations
}{
{
startDate: startDate[0],
joinDate: joinDate[0],
expectedAnnotations: lib.Annotations{
Annotations: []lib.Annotation{
{
Name: "Project start",
Description: lib.ToYMDDate(startDate[0]) + " - project starts",
Date: startDate[0],
},
{
Name: "First CNCF project join date",
Description: lib.ToYMDDate(joinDate[0]),
Date: joinDate[0],
},
},
},
},
{
startDate: startDate[1],
joinDate: joinDate[1],
expectedAnnotations: lib.Annotations{
Annotations: []lib.Annotation{},
},
},
{
startDate: startDate[2],
joinDate: joinDate[2],
expectedAnnotations: lib.Annotations{
Annotations: []lib.Annotation{},
},
},
{
startDate: startDate[3],
joinDate: joinDate[3],
expectedAnnotations: lib.Annotations{
Annotations: []lib.Annotation{},
},
},
{
startDate: startDate[0],
joinDate: joinDate[3],
expectedAnnotations: lib.Annotations{
Annotations: []lib.Annotation{},
},
},
{
startDate: startDate[3],
joinDate: joinDate[0],
expectedAnnotations: lib.Annotations{
Annotations: []lib.Annotation{},
},
},
}
// Execute test cases
for index, test := range testCases {
expected := test.expectedAnnotations
got := lib.GetFakeAnnotations(test.startDate, test.joinDate)
if (len(expected.Annotations) > 0 || len(got.Annotations) > 0) && !reflect.DeepEqual(expected.Annotations, got.Annotations) {
t.Errorf(
"test number %d, expected:\n%+v\n%+v\n got, start date: %s, join date: %s",
index+1,
expected,
got,
lib.ToYMDDate(test.startDate),
lib.ToYMDDate(test.joinDate),
)
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/cncf/devstatscode.git
git@gitee.com:cncf/devstatscode.git
cncf
devstatscode
devstatscode
master

搜索帮助