@@ -16,24 +16,84 @@ func TestPipelineRunSortByCompletionTime(t *testing.T) {
16
16
ns := "namespace"
17
17
labels := map [string ]string {}
18
18
success := tektonv1 .PipelineRunReasonSuccessful .String ()
19
+
20
+ pruns := []tektonv1.PipelineRun {
21
+ * (tektontest .MakePRCompletion (clock , "troisieme" , ns , success , nil , labels , 30 )),
22
+ * (tektontest .MakePRCompletion (clock , "premier" , ns , success , nil , labels , 10 )),
23
+ * (tektontest .MakePRCompletion (clock , "second" , ns , success , nil , labels , 20 )),
24
+ }
25
+
26
+ prunsMissing := []tektonv1.PipelineRun {
27
+ * (tektontest .MakePRCompletion (clock , "troisieme" , ns , success , nil , labels , 30 )),
28
+ * (tektontest .MakePRCompletion (clock , "premier" , ns , success , nil , labels , 10 )),
29
+ * (tektontest .MakePRCompletion (clock , "no-completion-time" , ns , success , nil , labels , 20 )),
30
+ }
31
+ for i := range prunsMissing {
32
+ if prunsMissing [i ].Name == "no-completion-time" {
33
+ prunsMissing [i ].Status .CompletionTime = nil
34
+ }
35
+ }
36
+
37
+ prunsWithOneMissing := []tektonv1.PipelineRun {
38
+ * (tektontest .MakePRCompletion (clock , "premier" , ns , success , nil , labels , 10 )),
39
+ * (tektontest .MakePRCompletion (clock , "no-completion-time" , ns , success , nil , labels , 20 )),
40
+ }
41
+ for i := range prunsWithOneMissing {
42
+ if prunsWithOneMissing [i ].Name == "no-completion-time" {
43
+ prunsWithOneMissing [i ].Status .CompletionTime = nil
44
+ }
45
+ }
46
+
47
+ prunsWithJMissing := []tektonv1.PipelineRun {
48
+ * (tektontest .MakePRCompletion (clock , "no-completion-time" , ns , success , nil , labels , 20 )),
49
+ * (tektontest .MakePRCompletion (clock , "premier" , ns , success , nil , labels , 10 )),
50
+ }
51
+ for i := range prunsWithJMissing {
52
+ if prunsWithJMissing [i ].Name == "no-completion-time" {
53
+ prunsWithJMissing [i ].Status .CompletionTime = nil
54
+ }
55
+ }
56
+
19
57
tests := []struct {
20
58
name string
21
59
pruns []tektonv1.PipelineRun
22
60
wantName []string
23
61
}{
24
62
{
25
- pruns : []tektonv1.PipelineRun {
26
- * (tektontest .MakePRCompletion (clock , "troisieme" , ns , success , nil , labels , 30 )),
27
- * (tektontest .MakePRCompletion (clock , "premier" , ns , success , nil , labels , 10 )),
28
- * (tektontest .MakePRCompletion (clock , "second" , ns , success , nil , labels , 20 )),
29
- },
63
+ name : "sort by completion time" ,
64
+ pruns : pruns ,
30
65
wantName : []string {"premier" , "second" , "troisieme" },
31
66
},
32
- // TODO: Add test cases.
67
+ {
68
+ name : "sort by completion time with missing" ,
69
+ pruns : prunsMissing ,
70
+ wantName : []string {"no-completion-time" , "premier" , "troisieme" },
71
+ },
72
+ {
73
+ name : "sort by completion time with one missing" ,
74
+ pruns : prunsWithOneMissing ,
75
+ wantName : []string {"no-completion-time" , "premier" },
76
+ },
77
+ {
78
+ name : "sort by completion time with j missing" ,
79
+ pruns : prunsWithJMissing ,
80
+ wantName : []string {"no-completion-time" , "premier" },
81
+ },
82
+ {
83
+ name : "empty list" ,
84
+ pruns : []tektonv1.PipelineRun {},
85
+ wantName : []string {},
86
+ },
87
+ {
88
+ name : "single item" ,
89
+ pruns : []tektonv1.PipelineRun {* (tektontest .MakePRCompletion (clock , "premier" , ns , success , nil , labels , 10 ))},
90
+ wantName : []string {"premier" },
91
+ },
33
92
}
34
93
for _ , tt := range tests {
35
94
t .Run (tt .name , func (t * testing.T ) {
36
- for key , value := range PipelineRunSortByCompletionTime (tt .pruns ) {
95
+ got := PipelineRunSortByCompletionTime (tt .pruns )
96
+ for key , value := range got {
37
97
assert .Equal (t , tt .wantName [key ], value .GetName ())
38
98
}
39
99
})
@@ -53,8 +113,18 @@ func TestPipelineRunSortByStartTime(t *testing.T) {
53
113
noCompletionPR .Status .CompletionTime = nil
54
114
55
115
notStartedYet := tektontest .MakePRCompletion (clock , "notStarted" , ns , success , nil , labels , 5 )
56
- noCompletionPR .Status .StartTime = nil
57
- noCompletionPR .Status .CompletionTime = nil
116
+ notStartedYet .Status .StartTime = nil
117
+ notStartedYet .Status .CompletionTime = nil
118
+
119
+ prunsWithOneNotStarted := []tektonv1.PipelineRun {
120
+ * (tektontest .MakePRCompletion (clock , "otherFirst" , ns , success , nil , labels , 30 )),
121
+ * notStartedYet ,
122
+ }
123
+
124
+ prunsWithJNotStarted := []tektonv1.PipelineRun {
125
+ * notStartedYet ,
126
+ * (tektontest .MakePRCompletion (clock , "otherFirst" , ns , success , nil , labels , 30 )),
127
+ }
58
128
59
129
tests := []struct {
60
130
name string
@@ -83,11 +153,31 @@ func TestPipelineRunSortByStartTime(t *testing.T) {
83
153
{
84
154
name : "not started yet" ,
85
155
pruns : []tektonv1.PipelineRun {
86
- * notStartedYet ,
87
156
* (tektontest .MakePRCompletion (clock , "otherFirst" , ns , success , nil , labels , 30 )),
88
157
* (tektontest .MakePRCompletion (clock , "otherSecond" , ns , success , nil , labels , 10 )),
158
+ * notStartedYet ,
89
159
},
90
- wantName : []string {"otherFirst" , "otherSecond" , "notStarted" },
160
+ wantName : []string {"notStarted" , "otherFirst" , "otherSecond" },
161
+ },
162
+ {
163
+ name : "not started yet single" ,
164
+ pruns : prunsWithOneNotStarted ,
165
+ wantName : []string {"notStarted" , "otherFirst" },
166
+ },
167
+ {
168
+ name : "not started yet single j" ,
169
+ pruns : prunsWithJNotStarted ,
170
+ wantName : []string {"notStarted" , "otherFirst" },
171
+ },
172
+ {
173
+ name : "empty list" ,
174
+ pruns : []tektonv1.PipelineRun {},
175
+ wantName : []string {},
176
+ },
177
+ {
178
+ name : "single item" ,
179
+ pruns : []tektonv1.PipelineRun {* startedEarlierPR },
180
+ wantName : []string {"earlier" },
91
181
},
92
182
}
93
183
for _ , tt := range tests {
0 commit comments