@@ -416,3 +416,162 @@ func TestViperIntegration(t *testing.T) {
416416 t .Error ("AllSettings should not be empty after setting values" )
417417 }
418418}
419+
420+ func TestPostInstallActions (t * testing.T ) {
421+ testCases := []struct {
422+ name string
423+ actions []PostInstallAction
424+ expectError bool
425+ }{
426+ {
427+ name : "empty actions" ,
428+ actions : []PostInstallAction {},
429+ expectError : false ,
430+ },
431+ {
432+ name : "missing action field" ,
433+ actions : []PostInstallAction {
434+ {
435+ Kind : "Deployment" ,
436+ Name : "test" ,
437+ },
438+ },
439+ expectError : false , // Should warn and skip
440+ },
441+ {
442+ name : "missing kind field" ,
443+ actions : []PostInstallAction {
444+ {
445+ Action : "restart" ,
446+ Name : "test" ,
447+ },
448+ },
449+ expectError : false , // Should warn and skip
450+ },
451+ {
452+ name : "missing both name and labelSelector" ,
453+ actions : []PostInstallAction {
454+ {
455+ Action : "restart" ,
456+ Kind : "Deployment" ,
457+ },
458+ },
459+ expectError : false , // Should warn and skip
460+ },
461+ {
462+ name : "unsupported action" ,
463+ actions : []PostInstallAction {
464+ {
465+ Action : "delete" ,
466+ Kind : "Deployment" ,
467+ Name : "test" ,
468+ },
469+ },
470+ expectError : false , // Should warn and skip
471+ },
472+ {
473+ name : "unsupported kind" ,
474+ actions : []PostInstallAction {
475+ {
476+ Action : "restart" ,
477+ Kind : "Pod" ,
478+ Name : "test" ,
479+ },
480+ },
481+ expectError : false , // Should warn and skip
482+ },
483+ }
484+
485+ for _ , tc := range testCases {
486+ t .Run (tc .name , func (t * testing.T ) {
487+ // PostInstallActions with nil config will skip invalid actions
488+ // We're testing the validation logic, not the actual execution
489+ err := PostInstallActions (tc .actions , context .TODO (), nil )
490+
491+ if tc .expectError && err == nil {
492+ t .Error ("Expected error but got none" )
493+ }
494+ // Note: err may be nil for cases where actions are skipped due to validation failures
495+ })
496+ }
497+ }
498+
499+ func TestPostInstallAction_Validation (t * testing.T ) {
500+ testCases := []struct {
501+ name string
502+ action PostInstallAction
503+ shouldValidate bool
504+ }{
505+ {
506+ name : "valid with name" ,
507+ action : PostInstallAction {
508+ Action : "restart" ,
509+ Kind : "Deployment" ,
510+ Name : "test" ,
511+ },
512+ shouldValidate : true ,
513+ },
514+ {
515+ name : "valid with labelSelector" ,
516+ action : PostInstallAction {
517+ Action : "restart" ,
518+ Kind : "StatefulSet" ,
519+ LabelSelector : map [string ]string {
520+ "app" : "test" ,
521+ },
522+ },
523+ shouldValidate : true ,
524+ },
525+ {
526+ name : "valid with both name and labelSelector" ,
527+ action : PostInstallAction {
528+ Action : "restart" ,
529+ Kind : "DaemonSet" ,
530+ Name : "test" ,
531+ LabelSelector : map [string ]string {
532+ "app" : "test" ,
533+ },
534+ },
535+ shouldValidate : true , // labelSelector takes precedence
536+ },
537+ {
538+ name : "invalid - no action" ,
539+ action : PostInstallAction {
540+ Kind : "Deployment" ,
541+ Name : "test" ,
542+ },
543+ shouldValidate : false ,
544+ },
545+ {
546+ name : "invalid - no kind" ,
547+ action : PostInstallAction {
548+ Action : "restart" ,
549+ Name : "test" ,
550+ },
551+ shouldValidate : false ,
552+ },
553+ {
554+ name : "invalid - no name or labelSelector" ,
555+ action : PostInstallAction {
556+ Action : "restart" ,
557+ Kind : "Deployment" ,
558+ },
559+ shouldValidate : false ,
560+ },
561+ }
562+
563+ for _ , tc := range testCases {
564+ t .Run (tc .name , func (t * testing.T ) {
565+ // Basic validation checks
566+ hasAction := tc .action .Action != ""
567+ hasKind := tc .action .Kind != ""
568+ hasNameOrSelector := tc .action .Name != "" || len (tc .action .LabelSelector ) > 0
569+
570+ validates := hasAction && hasKind && hasNameOrSelector
571+
572+ if validates != tc .shouldValidate {
573+ t .Errorf ("Expected validation to be %v, got %v" , tc .shouldValidate , validates )
574+ }
575+ })
576+ }
577+ }
0 commit comments