@@ -616,32 +616,58 @@ func TestBuildGatewayStatuses(t *testing.T) {
616616}
617617
618618func TestBuildBackendTLSPolicyStatuses (t * testing.T ) {
619- getBackendTLSPolicy := func (
620- name string ,
621- valid bool ,
622- ignored bool ,
623- isReferenced bool ,
624- conditions []conditions.Condition ,
625- ) * graph.BackendTLSPolicy {
619+ type policyCfg struct {
620+ Name string
621+ Conditions []conditions.Condition
622+ Valid bool
623+ Ignored bool
624+ IsReferenced bool
625+ }
626+
627+ getBackendTLSPolicy := func (policyCfg policyCfg ) * graph.BackendTLSPolicy {
626628 return & graph.BackendTLSPolicy {
627629 Source : & v1alpha2.BackendTLSPolicy {
628630 ObjectMeta : metav1.ObjectMeta {
629631 Namespace : "test" ,
630- Name : name ,
632+ Name : policyCfg . Name ,
631633 Generation : 1 ,
632634 },
633635 },
634- Valid : valid ,
635- Ignored : ignored ,
636- IsReferenced : isReferenced ,
637- Conditions : conditions ,
636+ Valid : policyCfg . Valid ,
637+ Ignored : policyCfg . Ignored ,
638+ IsReferenced : policyCfg . IsReferenced ,
639+ Conditions : policyCfg . Conditions ,
638640 Gateway : types.NamespacedName {Name : "gateway" , Namespace : "test" },
639641 }
640642 }
641643
642644 attachedConds := []conditions.Condition {staticConds .NewBackendTLSPolicyAccepted ()}
643645 invalidConds := []conditions.Condition {staticConds .NewBackendTLSPolicyInvalid ("invalid backendTLSPolicy" )}
644646
647+ validPolicyCfg := policyCfg {
648+ Name : "valid-bt" ,
649+ Valid : true ,
650+ IsReferenced : true ,
651+ Conditions : attachedConds ,
652+ }
653+
654+ invalidPolicyCfg := policyCfg {
655+ Name : "invalid-bt" ,
656+ IsReferenced : true ,
657+ Conditions : invalidConds ,
658+ }
659+
660+ ignoredPolicyCfg := policyCfg {
661+ Name : "ignored-bt" ,
662+ Ignored : true ,
663+ IsReferenced : true ,
664+ }
665+
666+ notReferencedPolicyCfg := policyCfg {
667+ Name : "not-referenced" ,
668+ Valid : true ,
669+ }
670+
645671 tests := []struct {
646672 backendTLSPolicies map [types.NamespacedName ]* graph.BackendTLSPolicy
647673 expected status.BackendTLSPolicyStatuses
@@ -654,7 +680,7 @@ func TestBuildBackendTLSPolicyStatuses(t *testing.T) {
654680 {
655681 name : "valid backendTLSPolicy" ,
656682 backendTLSPolicies : map [types.NamespacedName ]* graph.BackendTLSPolicy {
657- {Namespace : "test" , Name : "valid-bt" }: getBackendTLSPolicy ("valid-bt" , true , false , true , attachedConds ),
683+ {Namespace : "test" , Name : "valid-bt" }: getBackendTLSPolicy (validPolicyCfg ),
658684 },
659685 expected : status.BackendTLSPolicyStatuses {
660686 {Namespace : "test" , Name : "valid-bt" }: {
@@ -670,7 +696,7 @@ func TestBuildBackendTLSPolicyStatuses(t *testing.T) {
670696 {
671697 name : "invalid backendTLSPolicy" ,
672698 backendTLSPolicies : map [types.NamespacedName ]* graph.BackendTLSPolicy {
673- {Namespace : "test" , Name : "invalid-bt" }: getBackendTLSPolicy ("invalid-bt" , false , false , true , invalidConds ),
699+ {Namespace : "test" , Name : "invalid-bt" }: getBackendTLSPolicy (invalidPolicyCfg ),
674700 },
675701 expected : status.BackendTLSPolicyStatuses {
676702 {Namespace : "test" , Name : "invalid-bt" }: {
@@ -686,16 +712,16 @@ func TestBuildBackendTLSPolicyStatuses(t *testing.T) {
686712 {
687713 name : "ignored or not referenced backendTLSPolicies" ,
688714 backendTLSPolicies : map [types.NamespacedName ]* graph.BackendTLSPolicy {
689- {Namespace : "test" , Name : "ignored-bt" }: getBackendTLSPolicy ("ignored-bt" , false , true , true , nil ),
690- {Namespace : "test" , Name : "not-referenced" }: getBackendTLSPolicy ("not-referenced" , true , false , false , nil ),
715+ {Namespace : "test" , Name : "ignored-bt" }: getBackendTLSPolicy (ignoredPolicyCfg ),
716+ {Namespace : "test" , Name : "not-referenced" }: getBackendTLSPolicy (notReferencedPolicyCfg ),
691717 },
692718 expected : status.BackendTLSPolicyStatuses {},
693719 },
694720 {
695721 name : "mix valid and ignored backendTLSPolicies" ,
696722 backendTLSPolicies : map [types.NamespacedName ]* graph.BackendTLSPolicy {
697- {Namespace : "test" , Name : "ignored-bt" }: getBackendTLSPolicy ("ignored-bt" , false , true , true , nil ),
698- {Namespace : "test" , Name : "valid-bt" }: getBackendTLSPolicy ("valid-bt" , true , false , true , attachedConds ),
723+ {Namespace : "test" , Name : "ignored-bt" }: getBackendTLSPolicy (ignoredPolicyCfg ),
724+ {Namespace : "test" , Name : "valid-bt" }: getBackendTLSPolicy (validPolicyCfg ),
699725 },
700726 expected : status.BackendTLSPolicyStatuses {
701727 {Namespace : "test" , Name : "valid-bt" }: {
0 commit comments