Skip to content

Commit

Permalink
fixup! Implement NetworkPolicy handling in controller
Browse files Browse the repository at this point in the history
Add test for multiple port ranges
  • Loading branch information
Lykos153 committed Oct 19, 2022
1 parent 1a18d93 commit 5d732b1
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions internal/controller/model_pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,20 @@ func TestNetworkPolicies(t *testing.T) {
np4.Spec.Ingress = []networkingv1.NetworkPolicyIngressRule{}
f.addNetworkPolicy(np4)

np5 := newNetworkPolicy("multiple-ports-with-ranges")
np5.Spec.PolicyTypes = []networkingv1.PolicyType{
"Ingress",
}
np5.Spec.Ingress = []networkingv1.NetworkPolicyIngressRule{
{
Ports: []networkingv1.NetworkPolicyPort{
newNetworkPolicyPort(corev1.ProtocolTCP, 2000, 3000),
newNetworkPolicyPort(corev1.ProtocolUDP, 2000, 3000),
},
},
}
f.addNetworkPolicy(np5)

f.runWith(func(g *PodLoadBalancerModelGenerator) {
m, err := g.GenerateModel(nil)

Expand Down Expand Up @@ -745,6 +759,18 @@ func TestNetworkPolicies(t *testing.T) {
anyNetworkPolicy(t, m.NetworkPolicies, "block-everything", func(t *testing.T, p model.NetworkPolicy) {
assert.Equal(t, 0, len(p.AllowedIngresses))
})

anyNetworkPolicy(t, m.NetworkPolicies, "multiple-ports-with-ranges", func(t *testing.T, p model.NetworkPolicy) {
assert.Equal(t, 1, len(p.AllowedIngresses))
assert.Equal(t, 0, len(p.AllowedIngresses[0].IPBlockFilters))
assert.Equal(t, 2, len(p.AllowedIngresses[0].PortFilters))
assert.Equal(t, corev1.ProtocolTCP, p.AllowedIngresses[0].PortFilters[0].Protocol)
assert.Equal(t, int32(2000), *p.AllowedIngresses[0].PortFilters[0].Port)
assert.Equal(t, int32(3000), *p.AllowedIngresses[0].PortFilters[0].EndPort)
assert.Equal(t, corev1.ProtocolUDP, p.AllowedIngresses[0].PortFilters[1].Protocol)
assert.Equal(t, int32(2000), *p.AllowedIngresses[0].PortFilters[1].Port)
assert.Equal(t, int32(3000), *p.AllowedIngresses[0].PortFilters[1].EndPort)
})
})
}

Expand Down

0 comments on commit 5d732b1

Please sign in to comment.