@@ -12,6 +12,7 @@ import (
12
12
"code.gitea.io/gitea/models/unittest"
13
13
"code.gitea.io/gitea/services/context"
14
14
"code.gitea.io/gitea/services/contexttest"
15
+
15
16
"github.com/stretchr/testify/assert"
16
17
)
17
18
@@ -79,15 +80,15 @@ func TestListRunsExcludePullRequestsParam(t *testing.T) {
79
80
ctx , _ := contexttest .MockAPIContext (t , "user2/repo1" )
80
81
contexttest .LoadRepo (t , ctx , 1 )
81
82
contexttest .LoadUser (t , ctx , 2 )
82
-
83
+
83
84
// Set up form value
84
85
setFormValue (ctx , "exclude_pull_requests" , "true" )
85
86
86
87
// Call the actual parsing logic from ListRuns
87
88
opts := actions_model.FindRunOptions {
88
89
RepoID : ctx .Repo .Repository .ID ,
89
90
}
90
-
91
+
91
92
if exclude := ctx .FormString ("exclude_pull_requests" ); exclude != "" {
92
93
if exclude == "true" || exclude == "1" {
93
94
opts .ExcludePullRequests = true
@@ -101,13 +102,13 @@ func TestListRunsExcludePullRequestsParam(t *testing.T) {
101
102
ctx2 , _ := contexttest .MockAPIContext (t , "user2/repo1" )
102
103
contexttest .LoadRepo (t , ctx2 , 1 )
103
104
contexttest .LoadUser (t , ctx2 , 2 )
104
-
105
+
105
106
setFormValue (ctx2 , "exclude_pull_requests" , "1" )
106
107
107
108
opts2 := actions_model.FindRunOptions {
108
109
RepoID : ctx2 .Repo .Repository .ID ,
109
110
}
110
-
111
+
111
112
if exclude := ctx2 .FormString ("exclude_pull_requests" ); exclude != "" {
112
113
if exclude == "true" || exclude == "1" {
113
114
opts2 .ExcludePullRequests = true
@@ -121,13 +122,13 @@ func TestListRunsExcludePullRequestsParam(t *testing.T) {
121
122
ctx3 , _ := contexttest .MockAPIContext (t , "user2/repo1" )
122
123
contexttest .LoadRepo (t , ctx3 , 1 )
123
124
contexttest .LoadUser (t , ctx3 , 2 )
124
-
125
+
125
126
setFormValue (ctx3 , "exclude_pull_requests" , "false" )
126
127
127
128
opts3 := actions_model.FindRunOptions {
128
129
RepoID : ctx3 .Repo .Repository .ID ,
129
130
}
130
-
131
+
131
132
if exclude := ctx3 .FormString ("exclude_pull_requests" ); exclude != "" {
132
133
if exclude == "true" || exclude == "1" {
133
134
opts3 .ExcludePullRequests = true
@@ -144,19 +145,19 @@ func TestListRunsCheckSuiteIDParam(t *testing.T) {
144
145
unittest .PrepareTestEnv (t )
145
146
146
147
const testSuiteID int64 = 12345
147
-
148
+
148
149
// Test case: With check_suite_id parameter
149
150
ctx , _ := contexttest .MockAPIContext (t , "user2/repo1" )
150
151
contexttest .LoadRepo (t , ctx , 1 )
151
152
contexttest .LoadUser (t , ctx , 2 )
152
-
153
+
153
154
setFormValue (ctx , "check_suite_id" , "12345" )
154
155
155
156
// Call the actual parsing logic from ListRuns
156
157
opts := actions_model.FindRunOptions {
157
158
RepoID : ctx .Repo .Repository .ID ,
158
159
}
159
-
160
+
160
161
// This simulates the logic in ListRuns
161
162
if checkSuiteID := ctx .FormInt64 ("check_suite_id" ); checkSuiteID > 0 {
162
163
opts .CheckSuiteID = checkSuiteID
@@ -175,20 +176,20 @@ func TestListRunsCreatedParam(t *testing.T) {
175
176
ctx , _ := contexttest .MockAPIContext (t , "user2/repo1" )
176
177
contexttest .LoadRepo (t , ctx , 1 )
177
178
contexttest .LoadUser (t , ctx , 2 )
178
-
179
+
179
180
setFormValue (ctx , "created" , "2023-01-01..2023-12-31" )
180
181
181
182
opts := actions_model.FindRunOptions {
182
183
RepoID : ctx .Repo .Repository .ID ,
183
184
}
184
-
185
+
185
186
// Simulate the date parsing logic from ListRuns
186
187
if created := ctx .FormString ("created" ); created != "" {
187
188
if created == "2023-01-01..2023-12-31" {
188
189
startDate , _ := time .Parse ("2006-01-02" , "2023-01-01" )
189
190
endDate , _ := time .Parse ("2006-01-02" , "2023-12-31" )
190
191
endDate = endDate .Add (24 * time .Hour - time .Second )
191
-
192
+
192
193
opts .CreatedAfter = startDate
193
194
opts .CreatedBefore = endDate
194
195
}
@@ -198,21 +199,21 @@ func TestListRunsCreatedParam(t *testing.T) {
198
199
expectedStart , _ := time .Parse ("2006-01-02" , "2023-01-01" )
199
200
expectedEnd , _ := time .Parse ("2006-01-02" , "2023-12-31" )
200
201
expectedEnd = expectedEnd .Add (24 * time .Hour - time .Second )
201
-
202
+
202
203
assert .Equal (t , expectedStart , opts .CreatedAfter )
203
204
assert .Equal (t , expectedEnd , opts .CreatedBefore )
204
205
205
206
// Test case 2: With created in ">=" format
206
207
ctx2 , _ := contexttest .MockAPIContext (t , "user2/repo1" )
207
208
contexttest .LoadRepo (t , ctx2 , 1 )
208
209
contexttest .LoadUser (t , ctx2 , 2 )
209
-
210
+
210
211
setFormValue (ctx2 , "created" , ">=2023-01-01" )
211
212
212
213
opts2 := actions_model.FindRunOptions {
213
214
RepoID : ctx2 .Repo .Repository .ID ,
214
215
}
215
-
216
+
216
217
// Simulate the date parsing logic for >= format
217
218
if created := ctx2 .FormString ("created" ); created != "" {
218
219
if created == ">=2023-01-01" {
@@ -231,13 +232,13 @@ func TestListRunsCreatedParam(t *testing.T) {
231
232
ctx3 , _ := contexttest .MockAPIContext (t , "user2/repo1" )
232
233
contexttest .LoadRepo (t , ctx3 , 1 )
233
234
contexttest .LoadUser (t , ctx3 , 2 )
234
-
235
+
235
236
setFormValue (ctx3 , "created" , "2023-06-15" )
236
237
237
238
opts3 := actions_model.FindRunOptions {
238
239
RepoID : ctx3 .Repo .Repository .ID ,
239
240
}
240
-
241
+
241
242
// Simulate the date parsing logic for exact date
242
243
if created := ctx3 .FormString ("created" ); created != "" {
243
244
if created == "2023-06-15" {
0 commit comments