Skip to content

Commit

Permalink
Merge pull request #244 from huntergregory/unit-test-errors
Browse files Browse the repository at this point in the history
test: [Policy Assistant] fix unit test errors
  • Loading branch information
k8s-ci-robot authored Aug 8, 2024
2 parents 88a9549 + ff17442 commit 541245f
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 170 deletions.
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

0 comments on commit 541245f

Please sign in to comment.