Skip to content

Commit

Permalink
Add operator-observability rules unit test
Browse files Browse the repository at this point in the history
Add rules unit test, which ensures that alerts and recording rules
definitions are following conventions.

Signed-off-by: assafad <aadmi@redhat.com>
  • Loading branch information
assafad committed Mar 28, 2024
1 parent 7cd59b7 commit 3851bc9
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pkg/monitoring/rules/rules_suite_test.go
@@ -0,0 +1,13 @@
package rules_test

import (
"testing"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

func TestRules(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Rules Suite")
}
37 changes: 37 additions & 0 deletions pkg/monitoring/rules/rules_test.go
@@ -0,0 +1,37 @@
package rules_test

import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"github.com/machadovilaca/operator-observability/pkg/testutil"

"github.com/kubevirt/cluster-network-addons-operator/pkg/monitoring/rules"
)

var _ = Describe("Rules Validation", func() {
var linter *testutil.Linter

BeforeEach(func() {
Expect(rules.SetupRules("")).To(Succeed())
linter = testutil.New()
})

It("Should validate alerts", func() {
linter.AddCustomAlertValidations(
testutil.ValidateAlertNameLength,
testutil.ValidateAlertRunbookURLAnnotation,
testutil.ValidateAlertHealthImpactLabel,
testutil.ValidateAlertPartOfAndComponentLabels)

alerts := rules.ListAlerts()
problems := linter.LintAlerts(alerts)
Expect(problems).To(BeEmpty())
})

It("Should validate recording rules", func() {
recordingRules := rules.ListRecordingRules()
problems := linter.LintRecordingRules(recordingRules)
Expect(problems).To(BeEmpty())
})
})

0 comments on commit 3851bc9

Please sign in to comment.