@@ -487,6 +487,169 @@ func TestControlPlane(t *testing.T) {
487487 })
488488}
489489
490+ func TestControlPlaneEndpoints (t * testing.T ) {
491+ tests := []struct {
492+ name string
493+ controlPlane * unstructured.Unstructured
494+ want []Path
495+ expectErr bool
496+ }{
497+ {
498+ name : "No ignore paths when controlPlaneEndpoint is not set" ,
499+ controlPlane : & unstructured.Unstructured {
500+ Object : map [string ]interface {}{
501+ "spec" : map [string ]interface {}{
502+ "server" : "1.2.3.4" ,
503+ },
504+ },
505+ },
506+ want : nil ,
507+ },
508+ {
509+ name : "No ignore paths when controlPlaneEndpoint is nil" ,
510+ controlPlane : & unstructured.Unstructured {
511+ Object : map [string ]interface {}{
512+ "spec" : map [string ]interface {}{
513+ "controlPlaneEndpoint" : nil ,
514+ },
515+ },
516+ },
517+
518+ want : nil ,
519+ },
520+ {
521+ name : "No ignore paths when controlPlaneEndpoint is an empty object" ,
522+ controlPlane : & unstructured.Unstructured {
523+ Object : map [string ]interface {}{
524+ "spec" : map [string ]interface {}{
525+ "controlPlaneEndpoint" : map [string ]interface {}{},
526+ },
527+ },
528+ },
529+
530+ want : nil ,
531+ },
532+ {
533+ name : "Don't ignore host when controlPlaneEndpoint.host is set" ,
534+ controlPlane : & unstructured.Unstructured {
535+ Object : map [string ]interface {}{
536+ "spec" : map [string ]interface {}{
537+ "controlPlaneEndpoint" : map [string ]interface {}{
538+ "host" : "example.com" ,
539+ },
540+ },
541+ },
542+ },
543+ want : nil ,
544+ },
545+ {
546+ name : "Ignore host when controlPlaneEndpoint.host is set to its zero value" ,
547+ controlPlane : & unstructured.Unstructured {
548+ Object : map [string ]interface {}{
549+ "spec" : map [string ]interface {}{
550+ "controlPlaneEndpoint" : map [string ]interface {}{
551+ "host" : "" ,
552+ },
553+ },
554+ },
555+ },
556+ want : []Path {
557+ {"spec" , "controlPlaneEndpoint" , "host" },
558+ },
559+ },
560+ {
561+ name : "Don't ignore port when controlPlaneEndpoint.port is set" ,
562+ controlPlane : & unstructured.Unstructured {
563+ Object : map [string ]interface {}{
564+ "spec" : map [string ]interface {}{
565+ "controlPlaneEndpoint" : map [string ]interface {}{
566+ "port" : int64 (6443 ),
567+ },
568+ },
569+ },
570+ },
571+
572+ want : nil ,
573+ },
574+ {
575+ name : "Ignore port when controlPlaneEndpoint.port is set to its zero value" ,
576+ controlPlane : & unstructured.Unstructured {
577+ Object : map [string ]interface {}{
578+ "spec" : map [string ]interface {}{
579+ "controlPlaneEndpoint" : map [string ]interface {}{
580+ "port" : int64 (0 ),
581+ },
582+ },
583+ },
584+ },
585+ want : []Path {
586+ {"spec" , "controlPlaneEndpoint" , "port" },
587+ },
588+ },
589+ {
590+ name : "Ignore host and port when controlPlaneEndpoint host and port are set to their zero values" ,
591+ controlPlane : & unstructured.Unstructured {
592+ Object : map [string ]interface {}{
593+ "spec" : map [string ]interface {}{
594+ "controlPlaneEndpoint" : map [string ]interface {}{
595+ "host" : "" ,
596+ "port" : int64 (0 ),
597+ },
598+ },
599+ },
600+ },
601+ want : []Path {
602+ {"spec" , "controlPlaneEndpoint" , "host" },
603+ {"spec" , "controlPlaneEndpoint" , "port" },
604+ },
605+ },
606+ {
607+ name : "Ignore host when controlPlaneEndpoint host is to its zero values, even if port is set" ,
608+ controlPlane : & unstructured.Unstructured {
609+ Object : map [string ]interface {}{
610+ "spec" : map [string ]interface {}{
611+ "controlPlaneEndpoint" : map [string ]interface {}{
612+ "host" : "" ,
613+ "port" : int64 (6443 ),
614+ },
615+ },
616+ },
617+ },
618+ want : []Path {
619+ {"spec" , "controlPlaneEndpoint" , "host" },
620+ },
621+ },
622+ {
623+ name : "Ignore port when controlPlaneEndpoint port is to its zero values, even if host is set" ,
624+ controlPlane : & unstructured.Unstructured {
625+ Object : map [string ]interface {}{
626+ "spec" : map [string ]interface {}{
627+ "controlPlaneEndpoint" : map [string ]interface {}{
628+ "host" : "example.com" ,
629+ "port" : int64 (0 ),
630+ },
631+ },
632+ },
633+ },
634+ want : []Path {
635+ {"spec" , "controlPlaneEndpoint" , "port" },
636+ },
637+ },
638+ }
639+ for _ , tt := range tests {
640+ t .Run (tt .name , func (t * testing.T ) {
641+ g := NewWithT (t )
642+ got , err := InfrastructureCluster ().IgnorePaths (tt .controlPlane )
643+ if tt .expectErr {
644+ g .Expect (err ).To (HaveOccurred ())
645+ return
646+ }
647+ g .Expect (err ).ToNot (HaveOccurred ())
648+ g .Expect (got ).To (Equal (tt .want ))
649+ })
650+ }
651+ }
652+
490653func TestControlPlaneIsUpgrading (t * testing.T ) {
491654 tests := []struct {
492655 name string
0 commit comments