@@ -68,7 +68,7 @@ func TestSubmitCmd_PathwaysDryRun(t *testing.T) {
6868 }
6969
7070 // Reset flags before each test
71- resetSubmitCmdFlags ( )
71+ setupSubmitTestEnv ( t )
7272
7373 output , err := executeCommand (JobCmd ,
7474 "submit" ,
@@ -143,7 +143,7 @@ func TestSubmitCmd_RegularDryRun(t *testing.T) {
143143 }
144144
145145 // Reset flags before each test
146- resetSubmitCmdFlags ( )
146+ setupSubmitTestEnv ( t )
147147
148148 output , err := executeCommand (JobCmd ,
149149 "submit" ,
@@ -181,7 +181,7 @@ func TestSubmitCmd_RegularDryRun(t *testing.T) {
181181}
182182
183183func TestSubmitCmd_TPUWithNumNodes_Fails (t * testing.T ) {
184- resetSubmitCmdFlags ( )
184+ setupSubmitTestEnv ( t )
185185
186186 oldStore := store
187187 defer func () { store = oldStore }()
@@ -221,7 +221,7 @@ func TestSubmitCmd_TPUWithNumNodes_Fails(t *testing.T) {
221221}
222222
223223func TestSubmitCmd_LongWorkloadName_Fails (t * testing.T ) {
224- resetSubmitCmdFlags ( )
224+ setupSubmitTestEnv ( t )
225225
226226 oldStore := store
227227 defer func () { store = oldStore }()
@@ -252,7 +252,7 @@ func TestSubmitCmd_LongWorkloadName_Fails(t *testing.T) {
252252 }
253253}
254254
255- func resetSubmitCmdFlags ( ) {
255+ func setupSubmitTestEnv ( t * testing. T ) {
256256 imageName = ""
257257 baseImage = ""
258258 buildContext = ""
@@ -288,10 +288,26 @@ func resetSubmitCmdFlags() {
288288 pathwaysProxyEnv = nil
289289 pathwaysServerEnv = nil
290290 pathwaysWorkerEnv = nil
291+
292+ oldFactory := gkeOrchestratorFactory
293+ defer t .Cleanup (func () {
294+ gkeOrchestratorFactory = oldFactory
295+ })
296+ gkeOrchestratorFactory = func () orchestrator.JobOrchestrator {
297+ return & mockOrchestrator {}
298+ }
291299}
292300
293301type mockOrchestrator struct {
294302 orchestrator.JobOrchestrator
303+ initializeFunc func (string , string , string ) (string , error )
304+ }
305+
306+ func (m * mockOrchestrator ) Initialize (clusterName , location , projectID string ) (string , error ) {
307+ if m .initializeFunc != nil {
308+ return m .initializeFunc (clusterName , location , projectID )
309+ }
310+ return location , nil
295311}
296312
297313func (m * mockOrchestrator ) SubmitJob (job orchestrator.JobDefinition ) error {
@@ -348,7 +364,7 @@ func TestParseDurationToSeconds(t *testing.T) {
348364}
349365
350366func TestSubmitCmd_MissingRepoEnvVar (t * testing.T ) {
351- resetSubmitCmdFlags ( )
367+ setupSubmitTestEnv ( t )
352368
353369 origRepo := os .Getenv ("GCLUSTER_IMAGE_REPO" )
354370 os .Setenv ("GCLUSTER_IMAGE_REPO" , "" )
@@ -386,7 +402,7 @@ func TestSubmitCmd_MissingRepoEnvVar(t *testing.T) {
386402}
387403
388404func TestSubmitCmd_MissingUserEnvVar (t * testing.T ) {
389- resetSubmitCmdFlags ( )
405+ setupSubmitTestEnv ( t )
390406
391407 origUser := os .Getenv ("USER" )
392408 origUsername := os .Getenv ("USERNAME" )
@@ -431,7 +447,7 @@ func TestSubmitCmd_MissingUserEnvVar(t *testing.T) {
431447}
432448
433449func TestSubmitCmd_InvalidGKENAPProvisioning (t * testing.T ) {
434- resetSubmitCmdFlags ( )
450+ setupSubmitTestEnv ( t )
435451
436452 oldStore := store
437453 defer func () { store = oldStore }()
@@ -471,7 +487,7 @@ func TestSubmitCmd_InvalidGKENAPProvisioning(t *testing.T) {
471487}
472488
473489func TestSubmitCmd_ReservationModelWithoutName_Fails (t * testing.T ) {
474- resetSubmitCmdFlags ( )
490+ setupSubmitTestEnv ( t )
475491
476492 oldStore := store
477493 defer func () { store = oldStore }()
@@ -511,7 +527,7 @@ func TestSubmitCmd_ReservationModelWithoutName_Fails(t *testing.T) {
511527}
512528
513529func TestSubmitCmd_NonReservationModelWithName_Fails (t * testing.T ) {
514- resetSubmitCmdFlags ( )
530+ setupSubmitTestEnv ( t )
515531
516532 oldStore := store
517533 defer func () { store = oldStore }()
@@ -574,7 +590,7 @@ func TestSubmitCmd_DryRunMissingDir_Approved(t *testing.T) {
574590 defer func () { shell .PromptYesNo = oldPrompt }()
575591 shell .PromptYesNo = func (prompt string ) bool { return true }
576592
577- resetSubmitCmdFlags ( )
593+ setupSubmitTestEnv ( t )
578594
579595 _ , err = executeCommand (JobCmd ,
580596 "submit" ,
@@ -624,7 +640,7 @@ func TestSubmitCmd_DryRunMissingDir_Rejected(t *testing.T) {
624640 defer func () { shell .PromptYesNo = oldPrompt }()
625641 shell .PromptYesNo = func (prompt string ) bool { return false }
626642
627- resetSubmitCmdFlags ( )
643+ setupSubmitTestEnv ( t )
628644
629645 output , err := executeCommand (JobCmd ,
630646 "submit" ,
@@ -663,7 +679,7 @@ func TestSubmitCmd_DryRunIsDir_Existing(t *testing.T) {
663679 defer func () { store = oldStore }()
664680 store = & MockPrereqStore {State : PrereqState {LastCheckedTimestamp : time .Now ()}}
665681
666- resetSubmitCmdFlags ( )
682+ setupSubmitTestEnv ( t )
667683
668684 _ , err = executeCommand (JobCmd ,
669685 "submit" ,
@@ -692,7 +708,7 @@ func TestSubmitCmd_DryRunIsDir_TrailingSlash(t *testing.T) {
692708 defer func () { store = oldStore }()
693709 store = & MockPrereqStore {State : PrereqState {LastCheckedTimestamp : time .Now ()}}
694710
695- resetSubmitCmdFlags ( )
711+ setupSubmitTestEnv ( t )
696712
697713 _ , err := executeCommand (JobCmd ,
698714 "submit" ,
@@ -736,7 +752,7 @@ func TestSubmitCmd_ValidEnvVars(t *testing.T) {
736752 return & mockOrchestrator {}
737753 }
738754
739- resetSubmitCmdFlags ( )
755+ setupSubmitTestEnv ( t )
740756
741757 _ , err := executeCommand (JobCmd ,
742758 "submit" ,
@@ -770,7 +786,7 @@ func TestSubmitCmd_InvalidEnvFormat_Fails(t *testing.T) {
770786 },
771787 }
772788
773- resetSubmitCmdFlags ( )
789+ setupSubmitTestEnv ( t )
774790
775791 _ , err := executeCommand (JobCmd ,
776792 "submit" ,
@@ -815,7 +831,7 @@ func TestSubmitCmd_PathwaysEnv_Success(t *testing.T) {
815831 return & mockOrchestrator {}
816832 }
817833
818- resetSubmitCmdFlags ( )
834+ setupSubmitTestEnv ( t )
819835
820836 _ , err := executeCommand (JobCmd ,
821837 "submit" ,
@@ -859,7 +875,7 @@ func TestSubmitCmd_PathwaysEnv_InvalidFormat_Fails(t *testing.T) {
859875 return & mockOrchestrator {}
860876 }
861877
862- resetSubmitCmdFlags ( )
878+ setupSubmitTestEnv ( t )
863879
864880 _ , err := executeCommand (JobCmd ,
865881 "submit" ,
@@ -923,7 +939,7 @@ func TestSubmitCmd_InvalidEnvKey_Fails(t *testing.T) {
923939 },
924940 }
925941
926- resetSubmitCmdFlags ( )
942+ setupSubmitTestEnv ( t )
927943
928944 _ , err := executeCommand (JobCmd ,
929945 "submit" ,
@@ -971,7 +987,7 @@ func TestSubmitCmd_PathwaysMTCFlags(t *testing.T) {
971987 return & mockOrchestrator {}
972988 }
973989
974- resetSubmitCmdFlags ( )
990+ setupSubmitTestEnv ( t )
975991
976992 _ , err := executeCommand (JobCmd ,
977993 "submit" ,
@@ -1025,7 +1041,7 @@ func TestSubmitCmd_PathwaysHeadless(t *testing.T) {
10251041 return & mockOrchestrator {}
10261042 }
10271043
1028- resetSubmitCmdFlags ( )
1044+ setupSubmitTestEnv ( t )
10291045
10301046 _ , err := executeCommand (JobCmd ,
10311047 "submit" ,
0 commit comments