Skip to content

Commit c12a344

Browse files
committed
more list tests
1 parent f5dbe12 commit c12a344

File tree

1 file changed

+130
-2
lines changed

1 file changed

+130
-2
lines changed

cmd/dbos/cli_integration_test.go

Lines changed: 130 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,12 +228,21 @@ func testWorkflowCommands(t *testing.T, cliPath string) {
228228

229229
// testListWorkflows tests various workflow listing scenarios
230230
func testListWorkflows(t *testing.T, cliPath string) {
231+
// Create some test workflows first to ensure we have data to filter
232+
// The previous test functions have already created workflows that we can query
233+
234+
// Get the current time for time-based filtering
235+
currentTime := time.Now()
236+
231237
testCases := []struct {
232238
name string
233239
args []string
234240
expectWorkflows bool
235241
expectQueuedCount int
236242
checkQueueNames bool
243+
maxCount int
244+
minCount int
245+
checkStatus dbos.WorkflowStatusType
237246
}{
238247
{
239248
name: "BasicList",
@@ -244,6 +253,18 @@ func testListWorkflows(t *testing.T, cliPath string) {
244253
name: "LimitedList",
245254
args: []string{"workflow", "list", "--json", "--limit", "5"},
246255
expectWorkflows: true,
256+
maxCount: 5,
257+
},
258+
{
259+
name: "OffsetPagination",
260+
args: []string{"workflow", "list", "--json", "--limit", "3", "--offset", "1"},
261+
maxCount: 3,
262+
},
263+
{
264+
name: "SortDescending",
265+
args: []string{"workflow", "list", "--json", "--sort-desc", "--limit", "10"},
266+
expectWorkflows: true,
267+
maxCount: 10,
247268
},
248269
{
249270
name: "QueueOnlyList",
@@ -252,6 +273,103 @@ func testListWorkflows(t *testing.T, cliPath string) {
252273
expectQueuedCount: 10, // From QueueWorkflow which enqueues 10 workflows
253274
checkQueueNames: true,
254275
},
276+
{
277+
name: "StatusFilterSuccess",
278+
args: []string{"workflow", "list", "--json", "--status", "SUCCESS"},
279+
expectWorkflows: true,
280+
checkStatus: dbos.WorkflowStatusSuccess,
281+
},
282+
{
283+
name: "StatusFilterError",
284+
args: []string{"workflow", "list", "--json", "--status", "ERROR"},
285+
checkStatus: dbos.WorkflowStatusError,
286+
},
287+
{
288+
name: "StatusFilterEnqueued",
289+
args: []string{"workflow", "list", "--json", "--status", "ENQUEUED"},
290+
checkStatus: dbos.WorkflowStatusEnqueued,
291+
minCount: 10, // We expect at least 10 enqueued workflows from QueueWorkflow
292+
},
293+
{
294+
name: "StatusFilterPending",
295+
args: []string{"workflow", "list", "--json", "--status", "PENDING"},
296+
checkStatus: dbos.WorkflowStatusPending,
297+
},
298+
{
299+
name: "StatusFilterCancelled",
300+
args: []string{"workflow", "list", "--json", "--status", "CANCELLED"},
301+
checkStatus: dbos.WorkflowStatusCancelled,
302+
},
303+
{
304+
name: "TimeRangeFilter",
305+
args: []string{"workflow", "list", "--json", "--start-time", currentTime.Add(-1 * time.Hour).Format(time.RFC3339), "--end-time", currentTime.Add(1 * time.Hour).Format(time.RFC3339)},
306+
expectWorkflows: true,
307+
},
308+
{
309+
name: "CurrentTimeStartFilter",
310+
args: []string{"workflow", "list", "--json", "--start-time", currentTime.Format(time.RFC3339)},
311+
maxCount: 0, // Should return no workflows as all were created before currentTime
312+
},
313+
{
314+
name: "FutureTimeFilter",
315+
args: []string{"workflow", "list", "--json", "--start-time", currentTime.Add(1 * time.Hour).Format(time.RFC3339)},
316+
maxCount: 0, // Should return no workflows
317+
},
318+
{
319+
name: "PastTimeFilter",
320+
args: []string{"workflow", "list", "--json", "--end-time", currentTime.Add(1 * time.Hour).Format(time.RFC3339)},
321+
expectWorkflows: true, // Should return all workflows created before now + 1 hour
322+
},
323+
{
324+
name: "MultipleFilters",
325+
args: []string{"workflow", "list", "--json", "--status", "ENQUEUED", "--queue", "example-queue", "--limit", "20"},
326+
expectWorkflows: true,
327+
checkStatus: dbos.WorkflowStatusEnqueued,
328+
checkQueueNames: true,
329+
maxCount: 20,
330+
},
331+
{
332+
name: "WorkflowNameFilter",
333+
args: []string{"workflow", "list", "--json", "--name", "main.QueueWorkflow"},
334+
expectWorkflows: true,
335+
minCount: 1, // Should find at least the QueueWorkflow
336+
},
337+
{
338+
name: "QueueNameFilter",
339+
args: []string{"workflow", "list", "--json", "--queue", "example-queue", "--status", "ENQUEUED"},
340+
expectWorkflows: true,
341+
checkQueueNames: true,
342+
checkStatus: dbos.WorkflowStatusEnqueued,
343+
minCount: 10, // Should find the 10 enqueued workflows
344+
},
345+
{
346+
name: "QueuesOnlyFilter",
347+
args: []string{"workflow", "list", "--json", "--queues-only"},
348+
expectWorkflows: true,
349+
minCount: 10, // Should find at least the enqueued workflows
350+
},
351+
{
352+
name: "UserFilter",
353+
args: []string{"workflow", "list", "--json", "--user", "test-user"},
354+
expectWorkflows: false, // No workflows with test-user in this test
355+
},
356+
{
357+
name: "LargeLimit",
358+
args: []string{"workflow", "list", "--json", "--limit", "100"},
359+
maxCount: 100,
360+
},
361+
{
362+
name: "CombinedTimeAndStatus",
363+
args: []string{"workflow", "list", "--json", "--status", "SUCCESS", "--start-time", currentTime.Add(-2 * time.Hour).Format(time.RFC3339)},
364+
expectWorkflows: true,
365+
checkStatus: dbos.WorkflowStatusSuccess,
366+
},
367+
{
368+
name: "QueueAndTimeFilter",
369+
args: []string{"workflow", "list", "--json", "--queue", "example-queue", "--end-time", currentTime.Add(1 * time.Hour).Format(time.RFC3339)},
370+
expectWorkflows: true,
371+
checkQueueNames: true,
372+
},
255373
}
256374

257375
for _, tc := range testCases {
@@ -275,14 +393,24 @@ func testListWorkflows(t *testing.T, cliPath string) {
275393
assert.Equal(t, tc.expectQueuedCount, len(workflows), "Should have expected number of queued workflows")
276394
}
277395

396+
if tc.maxCount > 0 {
397+
assert.LessOrEqual(t, len(workflows), tc.maxCount, "Should not exceed max count")
398+
}
399+
400+
if tc.minCount > 0 {
401+
assert.GreaterOrEqual(t, len(workflows), tc.minCount, "Should have at least min count")
402+
}
403+
278404
if tc.checkQueueNames {
279405
for _, wf := range workflows {
280406
assert.NotEmpty(t, wf.QueueName, "Queued workflows should have queue name")
281407
}
282408
}
283409

284-
if tc.name == "LimitedList" {
285-
assert.LessOrEqual(t, len(workflows), 5, "Limited list should respect limit")
410+
if tc.checkStatus != "" {
411+
for _, wf := range workflows {
412+
assert.Equal(t, tc.checkStatus, wf.Status, "All workflows should have status %s", tc.checkStatus)
413+
}
286414
}
287415
})
288416
}

0 commit comments

Comments
 (0)