@@ -24,6 +24,13 @@ import (
2424 "k8s.io/client-go/tools/cache"
2525)
2626
27+ var (
28+ eightyFive int32 = 85
29+ eightyFivePointer = & eightyFive
30+ eightySix int32 = 86
31+ eightySixPointer = & eightySix
32+ )
33+
2734type netPolFixture struct {
2835 t * testing.T
2936
@@ -633,12 +640,12 @@ func TestCountsAddAndDeleteNetPol(t *testing.T) {
633640 tests := []struct {
634641 name string
635642 // network policy to add
636- netPolSpec * networkingv1.NetworkPolicySpec
637- cidrCount int
638- namedPortCount int
643+ netPolSpec * networkingv1.NetworkPolicySpec
644+ cidrCount int
645+ endPortCount int
639646 }{
640647 {
641- name : "no-cidr-namedPort " ,
648+ name : "no-cidr-endPort " ,
642649 netPolSpec : & networkingv1.NetworkPolicySpec {
643650 PolicyTypes : []networkingv1.PolicyType {
644651 networkingv1 .PolicyTypeIngress ,
@@ -719,7 +726,7 @@ func TestCountsAddAndDeleteNetPol(t *testing.T) {
719726 cidrCount : 1 ,
720727 },
721728 {
722- name : "namedPort -ingress" ,
729+ name : "endPort -ingress" ,
723730 netPolSpec : & networkingv1.NetworkPolicySpec {
724731 PolicyTypes : []networkingv1.PolicyType {
725732 networkingv1 .PolicyTypeIngress ,
@@ -728,16 +735,17 @@ func TestCountsAddAndDeleteNetPol(t *testing.T) {
728735 {
729736 Ports : []networkingv1.NetworkPolicyPort {
730737 {
731- Port : & intstr.IntOrString {StrVal : "abc" },
738+ Port : & intstr.IntOrString {IntVal : 80 },
739+ EndPort : eightyFivePointer ,
732740 },
733741 },
734742 },
735743 },
736744 },
737- namedPortCount : 1 ,
745+ endPortCount : 1 ,
738746 },
739747 {
740- name : "namedPort -egress" ,
748+ name : "endPort -egress" ,
741749 netPolSpec : & networkingv1.NetworkPolicySpec {
742750 PolicyTypes : []networkingv1.PolicyType {
743751 networkingv1 .PolicyTypeEgress ,
@@ -746,16 +754,17 @@ func TestCountsAddAndDeleteNetPol(t *testing.T) {
746754 {
747755 Ports : []networkingv1.NetworkPolicyPort {
748756 {
749- Port : & intstr.IntOrString {StrVal : "abc" },
757+ Port : & intstr.IntOrString {IntVal : 80 },
758+ EndPort : eightyFivePointer ,
750759 },
751760 },
752761 },
753762 },
754763 },
755- namedPortCount : 1 ,
764+ endPortCount : 1 ,
756765 },
757766 {
758- name : "cidr-and-namedPort " ,
767+ name : "cidr-and-endPort " ,
759768 netPolSpec : & networkingv1.NetworkPolicySpec {
760769 PolicyTypes : []networkingv1.PolicyType {
761770 networkingv1 .PolicyTypeIngress ,
@@ -771,14 +780,15 @@ func TestCountsAddAndDeleteNetPol(t *testing.T) {
771780 },
772781 Ports : []networkingv1.NetworkPolicyPort {
773782 {
774- Port : & intstr.IntOrString {StrVal : "abc" },
783+ Port : & intstr.IntOrString {IntVal : 80 },
784+ EndPort : eightyFivePointer ,
775785 },
776786 },
777787 },
778788 },
779789 },
780- cidrCount : 1 ,
781- namedPortCount : 1 ,
790+ cidrCount : 1 ,
791+ endPortCount : 1 ,
782792 },
783793 }
784794
@@ -807,28 +817,28 @@ func TestCountsAddAndDeleteNetPol(t *testing.T) {
807817 }
808818 checkNetPolTestResult ("TestCountsCreateNetPol" , f , testCases )
809819 require .Equal (t , tt .cidrCount , metrics .GetCidrNetPols ())
810- require .Equal (t , tt .namedPortCount , metrics .GetNamedPortNetPols ())
820+ require .Equal (t , tt .endPortCount , metrics .GetEndPortNetPols ())
811821
812822 deleteNetPol (t , f , netPolObj , DeletedFinalStateknownObject )
813823 testCases = []expectedNetPolValues {
814824 {0 , 0 , netPolPromVals {0 , 1 , 0 , 1 }},
815825 }
816826 checkNetPolTestResult ("TestCountsDelNetPol" , f , testCases )
817827 require .Equal (t , 0 , metrics .GetCidrNetPols ())
818- require .Equal (t , 0 , metrics .GetNamedPortNetPols ())
828+ require .Equal (t , 0 , metrics .GetEndPortNetPols ())
819829 })
820830 }
821831}
822832
823833func TestCountsUpdateNetPol (t * testing.T ) {
824834 tests := []struct {
825- name string
826- netPolSpec * networkingv1.NetworkPolicySpec
827- updatedNetPolSpec * networkingv1.NetworkPolicySpec
828- cidrCount int
829- namedPortCount int
830- updatedCidrCount int
831- updatedNamedPortCount int
835+ name string
836+ netPolSpec * networkingv1.NetworkPolicySpec
837+ updatedNetPolSpec * networkingv1.NetworkPolicySpec
838+ cidrCount int
839+ endPortCount int
840+ updatedCidrCount int
841+ updatedEndPortCount int
832842 }{
833843 {
834844 name : "cidr-to-no-cidr" ,
@@ -942,7 +952,7 @@ func TestCountsUpdateNetPol(t *testing.T) {
942952 updatedCidrCount : 1 ,
943953 },
944954 {
945- name : "namedPort -to-no-namedPort " ,
955+ name : "endPort -to-no-endPort " ,
946956 netPolSpec : & networkingv1.NetworkPolicySpec {
947957 PolicyTypes : []networkingv1.PolicyType {
948958 networkingv1 .PolicyTypeIngress ,
@@ -951,7 +961,8 @@ func TestCountsUpdateNetPol(t *testing.T) {
951961 {
952962 Ports : []networkingv1.NetworkPolicyPort {
953963 {
954- Port : & intstr.IntOrString {StrVal : "abc" },
964+ Port : & intstr.IntOrString {IntVal : 80 },
965+ EndPort : eightyFivePointer ,
955966 },
956967 },
957968 },
@@ -971,11 +982,11 @@ func TestCountsUpdateNetPol(t *testing.T) {
971982 },
972983 },
973984 },
974- namedPortCount : 1 ,
975- updatedNamedPortCount : 0 ,
985+ endPortCount : 1 ,
986+ updatedEndPortCount : 0 ,
976987 },
977988 {
978- name : "no-namedPort -to-namedPort " ,
989+ name : "no-endPort -to-endPort " ,
979990 netPolSpec : & networkingv1.NetworkPolicySpec {
980991 PolicyTypes : []networkingv1.PolicyType {
981992 networkingv1 .PolicyTypeIngress ,
@@ -998,17 +1009,18 @@ func TestCountsUpdateNetPol(t *testing.T) {
9981009 {
9991010 Ports : []networkingv1.NetworkPolicyPort {
10001011 {
1001- Port : & intstr.IntOrString {StrVal : "abc" },
1012+ Port : & intstr.IntOrString {IntVal : 80 },
1013+ EndPort : eightyFivePointer ,
10021014 },
10031015 },
10041016 },
10051017 },
10061018 },
1007- namedPortCount : 0 ,
1008- updatedNamedPortCount : 1 ,
1019+ endPortCount : 0 ,
1020+ updatedEndPortCount : 1 ,
10091021 },
10101022 {
1011- name : "namedPort -to-namedPort " ,
1023+ name : "endPort -to-endPort " ,
10121024 netPolSpec : & networkingv1.NetworkPolicySpec {
10131025 PolicyTypes : []networkingv1.PolicyType {
10141026 networkingv1 .PolicyTypeIngress ,
@@ -1017,7 +1029,8 @@ func TestCountsUpdateNetPol(t *testing.T) {
10171029 {
10181030 Ports : []networkingv1.NetworkPolicyPort {
10191031 {
1020- Port : & intstr.IntOrString {StrVal : "abc" },
1032+ Port : & intstr.IntOrString {IntVal : 80 },
1033+ EndPort : eightyFivePointer ,
10211034 },
10221035 },
10231036 },
@@ -1031,14 +1044,15 @@ func TestCountsUpdateNetPol(t *testing.T) {
10311044 {
10321045 Ports : []networkingv1.NetworkPolicyPort {
10331046 {
1034- Port : & intstr.IntOrString {StrVal : "xyz" },
1047+ Port : & intstr.IntOrString {IntVal : 80 },
1048+ EndPort : eightySixPointer ,
10351049 },
10361050 },
10371051 },
10381052 },
10391053 },
1040- namedPortCount : 1 ,
1041- updatedNamedPortCount : 1 ,
1054+ endPortCount : 1 ,
1055+ updatedEndPortCount : 1 ,
10421056 },
10431057 }
10441058
@@ -1066,7 +1080,7 @@ func TestCountsUpdateNetPol(t *testing.T) {
10661080 }
10671081 checkNetPolTestResult ("TestCountsAddNetPol" , f , testCases )
10681082 require .Equal (t , tt .cidrCount , metrics .GetCidrNetPols ())
1069- require .Equal (t , tt .namedPortCount , metrics .GetNamedPortNetPols ())
1083+ require .Equal (t , tt .endPortCount , metrics .GetEndPortNetPols ())
10701084
10711085 newNetPolObj := createNetPol ()
10721086 newNetPolObj .Spec = * tt .updatedNetPolSpec
@@ -1078,7 +1092,7 @@ func TestCountsUpdateNetPol(t *testing.T) {
10781092 }
10791093 checkNetPolTestResult ("TestCountsUpdateNetPol" , f , testCases )
10801094 require .Equal (t , tt .updatedCidrCount , metrics .GetCidrNetPols ())
1081- require .Equal (t , tt .updatedNamedPortCount , metrics .GetNamedPortNetPols ())
1095+ require .Equal (t , tt .updatedEndPortCount , metrics .GetEndPortNetPols ())
10821096 })
10831097 }
10841098}
0 commit comments