@@ -65,26 +65,26 @@ func TestCLIWorkflow(t *testing.T) {
6565 testConfigs := []struct {
6666 name string
6767 schemaName string
68- schemaArgs []string
6968 dbRole string
69+ args []string
7070 }{
7171 {
7272 name : "CustomSchema" ,
7373 schemaName : "test_schema" ,
74- schemaArgs : []string {"--schema" , "test_schema" },
7574 dbRole : "postgres" ,
75+ args : []string {"--schema" , "test_schema" },
7676 },
7777 {
7878 name : "DefaultSchema" ,
7979 schemaName : "dbos" ,
80- schemaArgs : []string {}, // No schema argument, use default
8180 dbRole : "postgres" ,
81+ args : []string {},
8282 },
8383 {
8484 name : "FunnySchema" ,
8585 schemaName : "F8nny_sCHem@-n@m3" ,
86- schemaArgs : []string {"--schema" , "F8nny_sCHem@-n@m3" },
8786 dbRole : "notpostgres" ,
87+ args : []string {"--schema" , "F8nny_sCHem@-n@m3" },
8888 },
8989 }
9090
@@ -103,7 +103,7 @@ func TestCLIWorkflow(t *testing.T) {
103103 })
104104
105105 t .Run ("ResetDatabase" , func (t * testing.T ) {
106- args := append ([]string {"reset" , "-y" }, config .schemaArgs ... )
106+ args := append ([]string {"reset" , "-y" }, config .args ... )
107107 cmd := exec .Command (cliPath , args ... )
108108 cmd .Env = append (os .Environ (), "DBOS_SYSTEM_DATABASE_URL=" + getDatabaseURL ("postgres" ))
109109
@@ -144,11 +144,14 @@ func TestCLIWorkflow(t *testing.T) {
144144 })
145145
146146 t .Run ("MigrateCommand" , func (t * testing.T ) {
147- testMigrateCommand (t , cliPath , config .schemaArgs , config .dbRole )
147+ testMigrateCommand (t , cliPath , config .args , config .dbRole )
148148 })
149149
150150 // Start a test application using dbos start
151- startArgs := append ([]string {"start" }, config .schemaArgs ... )
151+ startArgs := append ([]string {"start" }, config .args ... )
152+ if config .dbRole != "postgres" {
153+ startArgs = append (startArgs , "--app-role" , config .dbRole )
154+ }
152155 cmd := exec .CommandContext (context .Background (), cliPath , startArgs ... )
153156 envVars := append (os .Environ (), "DBOS_SYSTEM_DATABASE_URL=" + getDatabaseURL (config .dbRole ))
154157 // Pass the schema to the test app if using custom schema
@@ -176,11 +179,11 @@ func TestCLIWorkflow(t *testing.T) {
176179 })
177180
178181 t .Run ("WorkflowCommands" , func (t * testing.T ) {
179- testWorkflowCommands (t , cliPath , config .schemaArgs , config .dbRole )
182+ testWorkflowCommands (t , cliPath , config .args , config .dbRole )
180183 })
181184
182185 t .Run ("ErrorHandling" , func (t * testing.T ) {
183- testErrorHandling (t , cliPath , config .schemaArgs , config .dbRole )
186+ testErrorHandling (t , cliPath , config .args , config .dbRole )
184187 })
185188 })
186189 }
@@ -246,7 +249,7 @@ func testProjectInitialization(t *testing.T, cliPath string) {
246249 require .NoError (t , err , "go mod tidy failed: %s" , string (modOutput ))
247250}
248251
249- func testMigrateCommand (t * testing.T , cliPath string , schemaArgs []string , dbRole string ) {
252+ func testMigrateCommand (t * testing.T , cliPath string , baseArgs []string , dbRole string ) {
250253 // If the role is set, create it in Postgres first
251254 if dbRole != "postgres" {
252255 db , err := sql .Open ("pgx" , getDatabaseURL ("postgres" ))
@@ -261,7 +264,7 @@ func testMigrateCommand(t *testing.T, cliPath string, schemaArgs []string, dbRol
261264 require .NoError (t , err )
262265 }
263266
264- args := append ([]string {"--verbose" , "migrate" }, schemaArgs ... )
267+ args := append ([]string {"--verbose" , "migrate" }, baseArgs ... )
265268 if dbRole != "postgres" {
266269 args = append (args , "--app-role" , dbRole )
267270 }
@@ -273,31 +276,31 @@ func testMigrateCommand(t *testing.T, cliPath string, schemaArgs []string, dbRol
273276}
274277
275278// testWorkflowCommands comprehensively tests all workflow CLI commands
276- func testWorkflowCommands (t * testing.T , cliPath string , schemaArgs []string , dbRole string ) {
279+ func testWorkflowCommands (t * testing.T , cliPath string , baseArgs []string , dbRole string ) {
277280
278281 t .Run ("ListWorkflows" , func (t * testing.T ) {
279- testListWorkflows (t , cliPath , schemaArgs , dbRole )
282+ testListWorkflows (t , cliPath , baseArgs , dbRole )
280283 })
281284
282285 t .Run ("GetWorkflow" , func (t * testing.T ) {
283- testGetWorkflow (t , cliPath , schemaArgs , dbRole )
286+ testGetWorkflow (t , cliPath , baseArgs , dbRole )
284287 })
285288
286289 t .Run ("CancelResumeWorkflow" , func (t * testing.T ) {
287- testCancelResumeWorkflow (t , cliPath , schemaArgs , dbRole )
290+ testCancelResumeWorkflow (t , cliPath , baseArgs , dbRole )
288291 })
289292
290293 t .Run ("ForkWorkflow" , func (t * testing.T ) {
291- testForkWorkflow (t , cliPath , schemaArgs , dbRole )
294+ testForkWorkflow (t , cliPath , baseArgs , dbRole )
292295 })
293296
294297 t .Run ("GetWorkflowSteps" , func (t * testing.T ) {
295- testGetWorkflowSteps (t , cliPath , schemaArgs , dbRole )
298+ testGetWorkflowSteps (t , cliPath , baseArgs , dbRole )
296299 })
297300}
298301
299302// testListWorkflows tests various workflow listing scenarios
300- func testListWorkflows (t * testing.T , cliPath string , schemaArgs []string , dbRole string ) {
303+ func testListWorkflows (t * testing.T , cliPath string , baseArgs []string , dbRole string ) {
301304 // Create some test workflows first to ensure we have data to filter
302305 resp , err := http .Get ("http://localhost:" + testServerPort + "/workflow" )
303306 require .NoError (t , err , "Failed to trigger workflow" )
@@ -443,7 +446,10 @@ func testListWorkflows(t *testing.T, cliPath string, schemaArgs []string, dbRole
443446
444447 for _ , tc := range testCases {
445448 t .Run (tc .name , func (t * testing.T ) {
446- args := append (tc .args , schemaArgs ... )
449+ args := append (tc .args , baseArgs ... )
450+ if dbRole != "postgres" {
451+ args = append (args , "--app-role" , dbRole )
452+ }
447453 cmd := exec .Command (cliPath , args ... )
448454 cmd .Env = append (os .Environ (), "DBOS_SYSTEM_DATABASE_URL=" + getDatabaseURL (dbRole ))
449455
@@ -487,7 +493,7 @@ func testListWorkflows(t *testing.T, cliPath string, schemaArgs []string, dbRole
487493}
488494
489495// testGetWorkflow tests retrieving individual workflow details
490- func testGetWorkflow (t * testing.T , cliPath string , schemaArgs []string , dbRole string ) {
496+ func testGetWorkflow (t * testing.T , cliPath string , baseArgs []string , dbRole string ) {
491497 resp , err := http .Get ("http://localhost:" + testServerPort + "/queue" )
492498 require .NoError (t , err , "Failed to trigger queue workflow" )
493499 defer resp .Body .Close ()
@@ -507,7 +513,10 @@ func testGetWorkflow(t *testing.T, cliPath string, schemaArgs []string, dbRole s
507513 assert .NotEmpty (t , workflowID , "Workflow ID should not be empty" )
508514
509515 t .Run ("GetWorkflowJSON" , func (t * testing.T ) {
510- args := append ([]string {"workflow" , "get" , workflowID }, schemaArgs ... )
516+ args := append ([]string {"workflow" , "get" , workflowID }, baseArgs ... )
517+ if dbRole != "postgres" {
518+ args = append (args , "--app-role" , dbRole )
519+ }
511520 cmd := exec .Command (cliPath , args ... )
512521 cmd .Env = append (os .Environ (), "DBOS_SYSTEM_DATABASE_URL=" + getDatabaseURL (dbRole ))
513522
@@ -523,7 +532,10 @@ func testGetWorkflow(t *testing.T, cliPath string, schemaArgs []string, dbRole s
523532 assert .NotEmpty (t , status .Name , "Should have workflow name" )
524533
525534 // Redo the test with the db url in flags
526- args2 := append ([]string {"workflow" , "get" , workflowID , "--db-url" , getDatabaseURL (dbRole )}, schemaArgs ... )
535+ args2 := append ([]string {"workflow" , "get" , workflowID , "--db-url" , getDatabaseURL (dbRole )}, baseArgs ... )
536+ if dbRole != "postgres" {
537+ args2 = append (args2 , "--app-role" , dbRole )
538+ }
527539 cmd2 := exec .Command (cliPath , args2 ... )
528540
529541 output2 , err2 := cmd2 .CombinedOutput ()
@@ -557,7 +569,10 @@ func testGetWorkflow(t *testing.T, cliPath string, schemaArgs []string, dbRole s
557569 })
558570
559571 // Test with environment variable D
560- args3 := append ([]string {"workflow" , "get" , workflowID }, schemaArgs ... )
572+ args3 := append ([]string {"workflow" , "get" , workflowID }, baseArgs ... )
573+ if dbRole != "postgres" {
574+ args3 = append (args3 , "--app-role" , dbRole )
575+ }
561576 cmd3 := exec .Command (cliPath , args3 ... )
562577 cmd3 .Env = append (os .Environ (), "D=" + getDatabaseURL (dbRole ))
563578
@@ -575,7 +590,7 @@ func testGetWorkflow(t *testing.T, cliPath string, schemaArgs []string, dbRole s
575590}
576591
577592// testCancelResumeWorkflow tests workflow state management
578- func testCancelResumeWorkflow (t * testing.T , cliPath string , schemaArgs []string , dbRole string ) {
593+ func testCancelResumeWorkflow (t * testing.T , cliPath string , baseArgs []string , dbRole string ) {
579594 resp , err := http .Get ("http://localhost:" + testServerPort + "/queue" )
580595 require .NoError (t , err , "Failed to trigger queue workflow" )
581596 defer resp .Body .Close ()
@@ -595,7 +610,10 @@ func testCancelResumeWorkflow(t *testing.T, cliPath string, schemaArgs []string,
595610 assert .NotEmpty (t , workflowID , "Workflow ID should not be empty" )
596611
597612 t .Run ("CancelWorkflow" , func (t * testing.T ) {
598- args := append ([]string {"workflow" , "cancel" , workflowID }, schemaArgs ... )
613+ args := append ([]string {"workflow" , "cancel" , workflowID }, baseArgs ... )
614+ if dbRole != "postgres" {
615+ args = append (args , "--app-role" , dbRole )
616+ }
599617 cmd := exec .Command (cliPath , args ... )
600618 cmd .Env = append (os .Environ (), "DBOS_SYSTEM_DATABASE_URL=" + getDatabaseURL (dbRole ))
601619
@@ -605,7 +623,10 @@ func testCancelResumeWorkflow(t *testing.T, cliPath string, schemaArgs []string,
605623 assert .Contains (t , string (output ), "Successfully cancelled" , "Should confirm cancellation" )
606624
607625 // Verify workflow is actually cancelled
608- getArgs := append ([]string {"workflow" , "get" , workflowID }, schemaArgs ... )
626+ getArgs := append ([]string {"workflow" , "get" , workflowID }, baseArgs ... )
627+ if dbRole != "postgres" {
628+ getArgs = append (getArgs , "--app-role" , dbRole )
629+ }
609630 getCmd := exec .Command (cliPath , getArgs ... )
610631 getCmd .Env = append (os .Environ (), "DBOS_SYSTEM_DATABASE_URL=" + getDatabaseURL (dbRole ))
611632
@@ -619,7 +640,10 @@ func testCancelResumeWorkflow(t *testing.T, cliPath string, schemaArgs []string,
619640 })
620641
621642 t .Run ("ResumeWorkflow" , func (t * testing.T ) {
622- args := append ([]string {"workflow" , "resume" , workflowID }, schemaArgs ... )
643+ args := append ([]string {"workflow" , "resume" , workflowID }, baseArgs ... )
644+ if dbRole != "postgres" {
645+ args = append (args , "--app-role" , dbRole )
646+ }
623647 cmd := exec .Command (cliPath , args ... )
624648 cmd .Env = append (os .Environ (), "DBOS_SYSTEM_DATABASE_URL=" + getDatabaseURL (dbRole ))
625649
@@ -638,7 +662,7 @@ func testCancelResumeWorkflow(t *testing.T, cliPath string, schemaArgs []string,
638662}
639663
640664// testForkWorkflow tests workflow forking functionality
641- func testForkWorkflow (t * testing.T , cliPath string , schemaArgs []string , dbRole string ) {
665+ func testForkWorkflow (t * testing.T , cliPath string , baseArgs []string , dbRole string ) {
642666 resp , err := http .Get ("http://localhost:" + testServerPort + "/queue" )
643667 require .NoError (t , err , "Failed to trigger queue workflow" )
644668 defer resp .Body .Close ()
@@ -660,7 +684,10 @@ func testForkWorkflow(t *testing.T, cliPath string, schemaArgs []string, dbRole
660684 t .Run ("ForkWorkflow" , func (t * testing.T ) {
661685 newID := uuid .NewString ()
662686 targetVersion := "1.0.0"
663- args := append ([]string {"workflow" , "fork" , workflowID , "--forked-workflow-id" , newID , "--application-version" , targetVersion }, schemaArgs ... )
687+ args := append ([]string {"workflow" , "fork" , workflowID , "--forked-workflow-id" , newID , "--application-version" , targetVersion }, baseArgs ... )
688+ if dbRole != "postgres" {
689+ args = append (args , "--app-role" , dbRole )
690+ }
664691 cmd := exec .Command (cliPath , args ... )
665692 cmd .Env = append (os .Environ (), "DBOS_SYSTEM_DATABASE_URL=" + getDatabaseURL (dbRole ))
666693
@@ -680,7 +707,10 @@ func testForkWorkflow(t *testing.T, cliPath string, schemaArgs []string, dbRole
680707 })
681708
682709 t .Run ("ForkWorkflowFromStep" , func (t * testing.T ) {
683- args := append ([]string {"workflow" , "fork" , workflowID , "--step" , "2" }, schemaArgs ... )
710+ args := append ([]string {"workflow" , "fork" , workflowID , "--step" , "2" }, baseArgs ... )
711+ if dbRole != "postgres" {
712+ args = append (args , "--app-role" , dbRole )
713+ }
684714 cmd := exec .Command (cliPath , args ... )
685715 cmd .Env = append (os .Environ (), "DBOS_SYSTEM_DATABASE_URL=" + getDatabaseURL (dbRole ))
686716
@@ -699,7 +729,10 @@ func testForkWorkflow(t *testing.T, cliPath string, schemaArgs []string, dbRole
699729
700730 t .Run ("ForkWorkflowFromNegativeStep" , func (t * testing.T ) {
701731 // Test fork with invalid step number (0 should be converted to 1)
702- args := append ([]string {"workflow" , "fork" , workflowID , "--step" , "-1" }, schemaArgs ... )
732+ args := append ([]string {"workflow" , "fork" , workflowID , "--step" , "-1" }, baseArgs ... )
733+ if dbRole != "postgres" {
734+ args = append (args , "--app-role" , dbRole )
735+ }
703736 cmd := exec .Command (cliPath , args ... )
704737 cmd .Env = append (os .Environ (), "DBOS_SYSTEM_DATABASE_URL=" + getDatabaseURL (dbRole ))
705738
@@ -718,7 +751,7 @@ func testForkWorkflow(t *testing.T, cliPath string, schemaArgs []string, dbRole
718751}
719752
720753// testGetWorkflowSteps tests retrieving workflow steps
721- func testGetWorkflowSteps (t * testing.T , cliPath string , schemaArgs []string , dbRole string ) {
754+ func testGetWorkflowSteps (t * testing.T , cliPath string , baseArgs []string , dbRole string ) {
722755 resp , err := http .Get ("http://localhost:" + testServerPort + "/queue" )
723756 require .NoError (t , err , "Failed to trigger queue workflow" )
724757 defer resp .Body .Close ()
@@ -738,7 +771,10 @@ func testGetWorkflowSteps(t *testing.T, cliPath string, schemaArgs []string, dbR
738771 assert .NotEmpty (t , workflowID , "Workflow ID should not be empty" )
739772
740773 t .Run ("GetStepsJSON" , func (t * testing.T ) {
741- args := append ([]string {"workflow" , "steps" , workflowID }, schemaArgs ... )
774+ args := append ([]string {"workflow" , "steps" , workflowID }, baseArgs ... )
775+ if dbRole != "postgres" {
776+ args = append (args , "--app-role" , dbRole )
777+ }
742778 cmd := exec .Command (cliPath , args ... )
743779 cmd .Env = append (os .Environ (), "DBOS_SYSTEM_DATABASE_URL=" + getDatabaseURL (dbRole ))
744780
@@ -762,12 +798,15 @@ func testGetWorkflowSteps(t *testing.T, cliPath string, schemaArgs []string, dbR
762798}
763799
764800// testErrorHandling tests various error conditions and edge cases
765- func testErrorHandling (t * testing.T , cliPath string , schemaArgs []string , dbRole string ) {
801+ func testErrorHandling (t * testing.T , cliPath string , baseArgs []string , dbRole string ) {
766802 t .Run ("InvalidWorkflowID" , func (t * testing.T ) {
767803 invalidID := "invalid-workflow-id-12345"
768804
769805 // Test get with invalid ID
770- args := append ([]string {"workflow" , "get" , invalidID }, schemaArgs ... )
806+ args := append ([]string {"workflow" , "get" , invalidID }, baseArgs ... )
807+ if dbRole != "postgres" {
808+ args = append (args , "--app-role" , dbRole )
809+ }
771810 cmd := exec .Command (cliPath , args ... )
772811 cmd .Env = append (os .Environ (), "DBOS_SYSTEM_DATABASE_URL=" + getDatabaseURL (dbRole ))
773812
@@ -778,7 +817,10 @@ func testErrorHandling(t *testing.T, cliPath string, schemaArgs []string, dbRole
778817
779818 t .Run ("MissingWorkflowID" , func (t * testing.T ) {
780819 // Test get without workflow ID
781- args := append ([]string {"workflow" , "get" }, schemaArgs ... )
820+ args := append ([]string {"workflow" , "get" }, baseArgs ... )
821+ if dbRole != "postgres" {
822+ args = append (args , "--app-role" , dbRole )
823+ }
782824 cmd := exec .Command (cliPath , args ... )
783825 cmd .Env = append (os .Environ (), "DBOS_SYSTEM_DATABASE_URL=" + getDatabaseURL (dbRole ))
784826
@@ -788,7 +830,10 @@ func testErrorHandling(t *testing.T, cliPath string, schemaArgs []string, dbRole
788830 })
789831
790832 t .Run ("InvalidStatusFilter" , func (t * testing.T ) {
791- args := append ([]string {"workflow" , "list" , "--status" , "INVALID_STATUS" }, schemaArgs ... )
833+ args := append ([]string {"workflow" , "list" , "--status" , "INVALID_STATUS" }, baseArgs ... )
834+ if dbRole != "postgres" {
835+ args = append (args , "--app-role" , dbRole )
836+ }
792837 cmd := exec .Command (cliPath , args ... )
793838 cmd .Env = append (os .Environ (), "DBOS_SYSTEM_DATABASE_URL=" + getDatabaseURL (dbRole ))
794839
@@ -798,7 +843,10 @@ func testErrorHandling(t *testing.T, cliPath string, schemaArgs []string, dbRole
798843 })
799844
800845 t .Run ("InvalidTimeFormat" , func (t * testing.T ) {
801- args := append ([]string {"workflow" , "list" , "--start-time" , "invalid-time-format" }, schemaArgs ... )
846+ args := append ([]string {"workflow" , "list" , "--start-time" , "invalid-time-format" }, baseArgs ... )
847+ if dbRole != "postgres" {
848+ args = append (args , "--app-role" , dbRole )
849+ }
802850 cmd := exec .Command (cliPath , args ... )
803851 cmd .Env = append (os .Environ (), "DBOS_SYSTEM_DATABASE_URL=" + getDatabaseURL (dbRole ))
804852
@@ -809,7 +857,10 @@ func testErrorHandling(t *testing.T, cliPath string, schemaArgs []string, dbRole
809857
810858 t .Run ("MissingDatabaseURL" , func (t * testing.T ) {
811859 // Test without system DB url in the flags or env var
812- args := append ([]string {"workflow" , "list" }, schemaArgs ... )
860+ args := append ([]string {"workflow" , "list" }, baseArgs ... )
861+ if dbRole != "postgres" {
862+ args = append (args , "--app-role" , dbRole )
863+ }
813864 cmd := exec .Command (cliPath , args ... )
814865
815866 output , err := cmd .CombinedOutput ()
0 commit comments