-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathannotations_test.go
93 lines (89 loc) · 2.16 KB
/
annotations_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
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),
)
}
}
}