diff --git a/pkg/monitoring/rules/BUILD.bazel b/pkg/monitoring/rules/BUILD.bazel index db052a75ce71..c36ed9e57140 100644 --- a/pkg/monitoring/rules/BUILD.bazel +++ b/pkg/monitoring/rules/BUILD.bazel @@ -1,4 +1,4 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_library") +load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") go_library( name = "go_default_library", @@ -12,3 +12,18 @@ go_library( "//vendor/github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1:go_default_library", ], ) + +go_test( + name = "go_default_test", + srcs = [ + "rules_suite_test.go", + "rules_test.go", + ], + embed = [":go_default_library"], + deps = [ + "//staging/src/kubevirt.io/client-go/testutils:go_default_library", + "//vendor/github.com/machadovilaca/operator-observability/pkg/testutil:go_default_library", + "//vendor/github.com/onsi/ginkgo/v2:go_default_library", + "//vendor/github.com/onsi/gomega:go_default_library", + ], +) diff --git a/pkg/monitoring/rules/rules_suite_test.go b/pkg/monitoring/rules/rules_suite_test.go new file mode 100644 index 000000000000..8e4970a0eb12 --- /dev/null +++ b/pkg/monitoring/rules/rules_suite_test.go @@ -0,0 +1,27 @@ +/* +Copyright 2024 The KubeVirt Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package rules + +import ( + "testing" + + "kubevirt.io/client-go/testutils" +) + +func TestRules(t *testing.T) { + testutils.KubeVirtTestSuiteSetup(t) +} diff --git a/pkg/monitoring/rules/rules_test.go b/pkg/monitoring/rules/rules_test.go new file mode 100644 index 000000000000..9331eb3f82b4 --- /dev/null +++ b/pkg/monitoring/rules/rules_test.go @@ -0,0 +1,51 @@ +/* +Copyright 2024 The KubeVirt Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package rules + +import ( + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + + "github.com/machadovilaca/operator-observability/pkg/testutil" +) + +var _ = Describe("Rules Validation", func() { + var linter *testutil.Linter + + BeforeEach(func() { + Expect(SetupRules("")).To(Succeed()) + linter = testutil.New() + }) + + It("Should validate alerts", func() { + linter.AddCustomAlertValidations( + testutil.ValidateAlertNameLength, + testutil.ValidateAlertRunbookURLAnnotation, + testutil.ValidateAlertHealthImpactLabel, + testutil.ValidateAlertPartOfAndComponentLabels) + + alerts := ListAlerts() + problems := linter.LintAlerts(alerts) + Expect(problems).To(BeEmpty()) + }) + + It("Should validate recording rules", func() { + recordingRules := ListRecordingRules() + problems := linter.LintRecordingRules(recordingRules) + Expect(problems).To(BeEmpty()) + }) +})