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