@@ -448,39 +448,37 @@ func TestDiscoverUpdates(t *testing.T) {
448448
449449func TestPreRunStrategyValidation (t * testing.T ) {
450450 ns := "ns"
451- dummyApiServer := "http://localhost:999999" // expect no valid Kubernetes server will be running on this port
451+ dummyApiServer := "http://localhost:9999"
452452 fakeClient := fake .NewClientBuilder ().Build ()
453453 cfg := & genericclioptions.ConfigFlags {
454- // set the API server in case a development cluster is already running
455- // deliberately ensure ECONNREFUSED errors if we get as far as the List() call
456454 APIServer : & dummyApiServer ,
457455 Namespace : & ns ,
458456 }
459457 ctx := context .Background ()
460458
461459 testCases := []struct {
462- name string
463- strategy string
464- expectErr bool
465- expectedError string
460+ name string
461+ strategy string
462+ validationShouldPass bool
463+ expectedErrorMsg string
466464 }{
467465 {
468- name : "Valid strategy: copy-merge" ,
469- strategy : string (porchapi .CopyMerge ),
470- expectErr : false ,
471- expectedError : "cmdrpkgupgrade" , // this means the strategy is valid and it fails elsewhere
466+ name : "Valid strategy: copy-merge" ,
467+ strategy : string (porchapi .CopyMerge ),
468+ validationShouldPass : true ,
469+ // Will fail with connection error later, after validation passes
472470 },
473471 {
474- name : "Empty strategy is valid (uses default resource-merge)" ,
475- strategy : "" ,
476- expectErr : false ,
477- expectedError : "cmdrpkgupgrade" ,
472+ name : "Empty strategy is valid (uses default resource-merge)" ,
473+ strategy : "" ,
474+ validationShouldPass : true ,
475+ // Will fail with connection error later, after validation passes
478476 },
479477 {
480- name : "Invalid strategy" ,
481- strategy : "non-existent-strategy" ,
482- expectErr : true ,
483- expectedError : "invalid strategy \" non-existent-strategy\" ; must be one of:" ,
478+ name : "Invalid strategy" ,
479+ strategy : "non-existent-strategy" ,
480+ validationShouldPass : false ,
481+ expectedErrorMsg : "invalid strategy \" non-existent-strategy\" ; must be one of:" ,
484482 },
485483 }
486484
@@ -498,17 +496,20 @@ func TestPreRunStrategyValidation(t *testing.T) {
498496
499497 err := r .preRunE (r .Command , []string {"some-package-revision" })
500498
501- if tc .expectErr {
499+ if ! tc .validationShouldPass {
500+ // For invalid strategies, check specific validation error
502501 assert .Error (t , err )
503- if tc .expectedError != "" {
504- assert .Contains (t , err .Error (), tc .expectedError )
505- }
502+ assert .Contains (t , err .Error (), tc .expectedErrorMsg )
506503 } else {
507- assert .NoError (t , err )
504+ // For valid strategies, we expect a different error (connection error)
505+ // since we provided an invalid API server
506+ assert .Error (t , err )
507+ assert .NotContains (t , err .Error (), "invalid strategy" )
508508 }
509509 })
510510 }
511511}
512+
512513func TestFindUpstreamByLock (t * testing.T ) {
513514 const ns = "ns"
514515
0 commit comments