Skip to content

Commit

Permalink
[feat] - secret tests
Browse files Browse the repository at this point in the history
Signed-off-by: Hélia Barroso <helia_barroso@hotmail.com>
  • Loading branch information
heliapb committed Dec 6, 2024
1 parent f34ef84 commit fb3dda5
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions internal/analyzers/alertmanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,78 @@ func TestAlertmanagerAnalyzer(t *testing.T) {
}
},
},
{
name: "AlertmanagerSecretEmptyData",
namespace: "test",
shouldFail: true,
getMockedClientSets: func(tc testCase) k8sutil.ClientSets {
mClient := monitoringclient.NewSimpleClientset(&monitoringv1.AlertmanagerList{})
mClient.PrependReactor("get", "alertmanagers", func(_ clienttesting.Action) (bool, runtime.Object, error) {
return true, &monitoringv1.Alertmanager{
ObjectMeta: metav1.ObjectMeta{
Name: tc.name,
Namespace: tc.namespace,
},
Spec: monitoringv1.AlertmanagerSpec{
ConfigSecret: "test-secret",
},
}, nil
})

kClient := fake.NewSimpleClientset(&corev1.Secret{})
kClient.PrependReactor("get", "secrets", func(_ clienttesting.Action) (bool, runtime.Object, error) {
return true, &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: "test-secret",
Namespace: tc.namespace,
},
Data: map[string][]byte{},
}, nil
})

return k8sutil.ClientSets{
MClient: mClient,
KClient: kClient,
}
},
},
{
name: "AlertmanagerSecretKeyNotFound",
namespace: "test",
shouldFail: true,
getMockedClientSets: func(tc testCase) k8sutil.ClientSets {
mClient := monitoringclient.NewSimpleClientset(&monitoringv1.AlertmanagerList{})
mClient.PrependReactor("get", "alertmanagers", func(_ clienttesting.Action) (bool, runtime.Object, error) {
return true, &monitoringv1.Alertmanager{
ObjectMeta: metav1.ObjectMeta{
Name: tc.name,
Namespace: tc.namespace,
},
Spec: monitoringv1.AlertmanagerSpec{
ConfigSecret: "test-secret",
},
}, nil
})

kClient := fake.NewSimpleClientset(&corev1.Secret{})
kClient.PrependReactor("get", "secrets", func(_ clienttesting.Action) (bool, runtime.Object, error) {
return true, &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: "test-secret",
Namespace: tc.namespace,
},
Data: map[string][]byte{
"some-other-key": []byte("value"),
},
}, nil
})

return k8sutil.ClientSets{
MClient: mClient,
KClient: kClient,
}
},
},
{
name: "AlertmanagerNamespaceSelectorWithoutMatchLabels",
namespace: "test",
Expand Down

0 comments on commit fb3dda5

Please sign in to comment.