Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: [Policy Assistant] fix unit test errors #244

Merged
merged 4 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cmd/policy-assistant/pkg/connectivity/probe/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ func NewTableWithDefaultConnectivity(r *Resources, ingress, egress Connectivity)
Egress: &egress,
}

if fr == to {
c := ConnectivityUndefined
jr.Ingress = &c
jr.Egress = &c
}

setCombined(jr)

k := fmt.Sprintf("%s/%d", proto, port)
Expand Down
20 changes: 10 additions & 10 deletions cmd/policy-assistant/pkg/matcher/builder_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func RunBuilderTests() {
ingress, egress := BuildTarget(netpol.AllowNoIngress)

Expect(ingress).ToNot(BeNil())
Expect(ingress.Peers).To(BeNil())
Expect(ingress.Peers).To(Equal([]PeerMatcher{&NoMatcher{}}))

Expect(egress).To(BeNil())
})
Expand All @@ -37,7 +37,7 @@ func RunBuilderTests() {
ingress, egress := BuildTarget(netpol.AllowNoEgress)

Expect(egress).ToNot(BeNil())
Expect(egress.Peers).To(BeNil())
Expect(egress.Peers).To(Equal([]PeerMatcher{&NoMatcher{}}))

Expect(ingress).To(BeNil())
})
Expand All @@ -46,10 +46,10 @@ func RunBuilderTests() {
ingress, egress := BuildTarget(netpol.AllowNoIngressAllowNoEgress)

Expect(egress).ToNot(BeNil())
Expect(egress.Peers).To(BeNil())
Expect(egress.Peers).To(Equal([]PeerMatcher{&NoMatcher{}}))

Expect(ingress).ToNot(BeNil())
Expect(ingress.Peers).To(BeNil())
Expect(ingress.Peers).To(Equal([]PeerMatcher{&NoMatcher{}}))
})
})

Expand All @@ -75,7 +75,7 @@ func RunBuilderTests() {
ingress, egress := BuildTarget(netpol.AllowNoIngress_EmptyIngress)

Expect(ingress).ToNot(BeNil())
Expect(ingress.Peers).To(BeNil())
Expect(ingress.Peers).To(Equal([]PeerMatcher{&NoMatcher{}}))

Expect(egress).To(BeNil())
})
Expand All @@ -84,7 +84,7 @@ func RunBuilderTests() {
ingress, egress := BuildTarget(netpol.AllowNoEgress_EmptyEgress)

Expect(egress).ToNot(BeNil())
Expect(egress.Peers).To(BeNil())
Expect(egress.Peers).To(Equal([]PeerMatcher{&NoMatcher{}}))

Expect(ingress).To(BeNil())
})
Expand All @@ -93,10 +93,10 @@ func RunBuilderTests() {
ingress, egress := BuildTarget(netpol.AllowNoIngressAllowNoEgress_EmptyEgressEmptyIngress)

Expect(egress).ToNot(BeNil())
Expect(egress.Peers).To(BeNil())
Expect(egress.Peers).To(Equal([]PeerMatcher{&NoMatcher{}}))

Expect(ingress).ToNot(BeNil())
Expect(ingress.Peers).To(BeNil())
Expect(ingress.Peers).To(Equal([]PeerMatcher{&NoMatcher{}}))
})
})

Expand Down Expand Up @@ -128,12 +128,12 @@ func RunBuilderTests() {
Describe("PeerMatcher from slice of ingress/egress rules", func() {
It("allows no ingress from an empty slice of ingress rules", func() {
peers := BuildIngressMatcher("abc", []networkingv1.NetworkPolicyIngressRule{})
Expect(peers).To(BeNil())
Expect(peers).To(Equal([]PeerMatcher{&NoMatcher{}}))
})

It("allows no egress from an empty slice of egress rules", func() {
peers := BuildEgressMatcher("abc", []networkingv1.NetworkPolicyEgressRule{})
Expect(peers).To(BeNil())
Expect(peers).To(Equal([]PeerMatcher{&NoMatcher{}}))
})

It("allows all ingress from an ingress containing a single empty rule", func() {
Expand Down
4 changes: 2 additions & 2 deletions cmd/policy-assistant/pkg/matcher/simplifier_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func RunSimplifierTests() {
Priority: 5,
Verdict: Deny,
},
Name: "anp",
RuleName: "anp",
}
banpAllowAll := &PeerMatcherAdmin{
PodPeerMatcher: &PodPeerMatcher{
Expand All @@ -147,7 +147,7 @@ func RunSimplifierTests() {
PolicyKind: BaselineAdminNetworkPolicy,
Verdict: Allow,
},
Name: "banp",
RuleName: "banp",
}
Expect(Simplify([]PeerMatcher{all, allOnTCP80, ip, allPodsAllPorts, banpAllowAll, allPodsTCP103, anpDenyAll})).To(Equal([]PeerMatcher{banpAllowAll, anpDenyAll, all}))

Expand Down
Loading
Loading