@@ -668,7 +668,7 @@ func TestEndpointsResolver_ResolveNetworkPeers(t *testing.T) {
668668 PodIP : "1.0.0.1" ,
669669 },
670670 }
671- dstPod := corev1.Pod {
671+ dstPodOne := corev1.Pod {
672672 ObjectMeta : metav1.ObjectMeta {
673673 Name : "pod2" ,
674674 Namespace : "dst" ,
@@ -691,6 +691,29 @@ func TestEndpointsResolver_ResolveNetworkPeers(t *testing.T) {
691691 PodIP : "1.0.0.2" ,
692692 },
693693 }
694+ dstPodTwo := corev1.Pod {
695+ ObjectMeta : metav1.ObjectMeta {
696+ Name : "pod3" ,
697+ Namespace : "dst" ,
698+ },
699+ Spec : corev1.PodSpec {
700+ Containers : []corev1.Container {
701+ {
702+ Name : "pod3" ,
703+ Ports : []corev1.ContainerPort {
704+ {
705+ ContainerPort : port8080 ,
706+ Protocol : corev1 .ProtocolTCP ,
707+ Name : "test-port" ,
708+ },
709+ },
710+ },
711+ },
712+ },
713+ Status : corev1.PodStatus {
714+ PodIP : "1.0.0.3" ,
715+ },
716+ }
694717
695718 policy := & networking.NetworkPolicy {
696719 ObjectMeta : metav1.ObjectMeta {
@@ -775,7 +798,7 @@ func TestEndpointsResolver_ResolveNetworkPeers(t *testing.T) {
775798 // getting ingress endpoint calls listing pods with dst NS first
776799 mockClient .EXPECT ().List (gomock .Any (), podList , gomock .Any ()).DoAndReturn (
777800 func (ctx context.Context , podList * corev1.PodList , opts ... client.ListOption ) error {
778- podList .Items = []corev1.Pod {dstPod }
801+ podList .Items = []corev1.Pod {dstPodOne , dstPodTwo }
779802 return nil
780803 },
781804 ),
@@ -811,7 +834,7 @@ func TestEndpointsResolver_ResolveNetworkPeers(t *testing.T) {
811834 ),
812835 mockClient .EXPECT ().List (gomock .Any (), podList , gomock .Any ()).DoAndReturn (
813836 func (ctx context.Context , podList * corev1.PodList , opts ... client.ListOption ) error {
814- podList .Items = []corev1.Pod {dstPod }
837+ podList .Items = []corev1.Pod {dstPodOne , dstPodTwo }
815838 return nil
816839 },
817840 ),
@@ -845,12 +868,13 @@ func TestEndpointsResolver_ResolveNetworkPeers(t *testing.T) {
845868
846869 for _ , ingPE := range ingressEndpoints {
847870 assert .Equal (t , srcPod .Status .PodIP , string (ingPE .CIDR ))
848- assert .Equal (t , dstPod .Spec .Containers [0 ].Ports [0 ].ContainerPort , * ingPE .Ports [0 ].Port )
871+ assert .Equal (t , dstPodOne .Spec .Containers [0 ].Ports [0 ].ContainerPort , * ingPE .Ports [0 ].Port )
872+ assert .Equal (t , 1 , len (ingPE .Ports ))
849873 }
850874
851875 for _ , egPE := range egressEndpoints {
852- assert .Equal (t , dstPod . Status .PodIP , string (egPE .CIDR ))
853- assert .Equal (t , dstPod .Spec .Containers [0 ].Ports [0 ].ContainerPort , * egPE .Ports [0 ].Port )
876+ assert .True (t , string ( egPE . CIDR ) == dstPodOne . Status .PodIP || string (egPE .CIDR ) == dstPodTwo . Status . PodIP )
877+ assert .Equal (t , dstPodOne .Spec .Containers [0 ].Ports [0 ].ContainerPort , * egPE .Ports [0 ].Port )
854878 assert .Equal (t , policy .Spec .Egress [0 ].Ports [0 ].Port .IntVal , * egPE .Ports [0 ].Port )
855879 assert .Equal (t , * policy .Spec .Egress [0 ].Ports [0 ].EndPort , * egPE .Ports [0 ].EndPort )
856880 }
0 commit comments