Skip to content

Commit

Permalink
test: added missing tests for the Netpool analyzer (#1016)
Browse files Browse the repository at this point in the history
- Added a network policy allowing traffic to all pods. Resulting in
  additional failures in the results.

Partially addresses: #889

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
Co-authored-by: Alex Jones <alexsimonjones@gmail.com>
  • Loading branch information
VaibhavMalik4187 and AlexsJones authored Mar 15, 2024
1 parent 20892b4 commit f60467c
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion pkg/analyzer/netpol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,19 @@ func TestNetpolWithPod(t *testing.T) {

func TestNetpolNoPodsNamespaceFiltering(t *testing.T) {
clientset := fake.NewSimpleClientset(
&networkingv1.NetworkPolicy{
ObjectMeta: metav1.ObjectMeta{
Name: "policy-without-podselector-match-labels",
Namespace: "default",
},
Spec: networkingv1.NetworkPolicySpec{
PodSelector: metav1.LabelSelector{
// len(MatchLabels) == 0 should trigger a failure.
// Allowing traffic to all pods.
MatchLabels: map[string]string{},
},
},
},
&networkingv1.NetworkPolicy{
ObjectMeta: metav1.ObjectMeta{
Name: "example",
Expand Down Expand Up @@ -203,7 +216,7 @@ func TestNetpolNoPodsNamespaceFiltering(t *testing.T) {
t.Error(err)
}

assert.Equal(t, len(results), 1)
assert.Equal(t, len(results), 2)
assert.Equal(t, results[0].Kind, "NetworkPolicy")

}

0 comments on commit f60467c

Please sign in to comment.