test: added missing tests for the Netpool analyzer (#1016)

- Added a network policy allowing traffic to all pods. Resulting in
  additional failures in the results.

Partially addresses: https://github.com/k8sgpt-ai/k8sgpt/issues/889

Signed-off-by: VaibhavMalik4187 <vaibhavmalik2018@gmail.com>
Co-authored-by: Alex Jones <alexsimonjones@gmail.com>
This commit is contained in:
Vaibhav Malik
2024-03-16 00:15:36 +05:30
committed by GitHub
parent 20892b48d0
commit f60467cd4d

View File

@@ -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",
@@ -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")
}