Skip to content

Commit

Permalink
test/e2e/namespaces: add proper suffix to the test object names
Browse files Browse the repository at this point in the history
Tests could be executed concurrently by ginkgo framwork.
Ind it requires to add proper suffix to it with id of the process.

Signed-off-by: f41gh7 <[email protected]>
  • Loading branch information
f41gh7 committed Dec 9, 2024
1 parent 32b8253 commit baa094c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
3 changes: 3 additions & 0 deletions test/e2e/watchnamespace/controllers_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package watchnamespace

import (
"fmt"
"reflect"

v1beta1vm "github.com/VictoriaMetrics/operator/api/operator/v1beta1"
Expand Down Expand Up @@ -97,7 +98,9 @@ var _ = Describe("Controllers", func() {
}

var objectTypes []formattableType
processIdxSuffix := fmt.Sprintf("-%d", GinkgoParallelProcess())
for _, object := range objects {
object.SetName(object.GetName() + processIdxSuffix)
objectTypes = append(objectTypes, formattableType{reflect.TypeOf(object).Elem()})
}

Expand Down
19 changes: 10 additions & 9 deletions test/e2e/watchnamespace/prometheus_converter_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package watchnamespace

import (
"fmt"

v1beta1vm "github.com/VictoriaMetrics/operator/api/operator/v1beta1"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand All @@ -12,11 +14,12 @@ import (
var _ = Describe("VM Operator", func() {
var namespace string

processIdxSuffix := fmt.Sprintf("-%d", GinkgoParallelProcess())
JustBeforeEach(func() {
CreateObjects(
&monitoringv1.ServiceMonitor{
ObjectMeta: metav1.ObjectMeta{
Name: "test-service-monitor",
Name: "test-service-monitor" + processIdxSuffix,
Namespace: namespace,
},
Spec: monitoringv1.ServiceMonitorSpec{
Expand All @@ -27,7 +30,7 @@ var _ = Describe("VM Operator", func() {
},
&monitoringv1.PodMonitor{
ObjectMeta: metav1.ObjectMeta{
Name: "test-pod-monitor",
Name: "test-pod-monitor" + processIdxSuffix,
Namespace: namespace,
},
Spec: monitoringv1.PodMonitorSpec{
Expand All @@ -38,13 +41,13 @@ var _ = Describe("VM Operator", func() {
},
&monitoringv1.Probe{
ObjectMeta: metav1.ObjectMeta{
Name: "test-probe",
Name: "test-probe" + processIdxSuffix,
Namespace: namespace,
},
},
&monitoringv1.PrometheusRule{
ObjectMeta: metav1.ObjectMeta{
Name: "test-prometheus-rule",
Name: "test-prometheus-rule" + processIdxSuffix,
Namespace: namespace,
},
},
Expand Down Expand Up @@ -77,11 +80,9 @@ var _ = Describe("VM Operator", func() {
})

It("should convert Prometheus operator objects to VictoriaMetrics operator objects", func() {
for _, listProto := range vmObjectListProtos {
Eventually(func() []client.Object {
return ListObjectsInNamespace(namespace, listProto)
}, 60, 1).ShouldNot(BeEmpty())
}
Eventually(func() []client.Object {
return ListObjectsInNamespace(namespace, vmObjectListProtos)
}, 60, 1).ShouldNot(BeEmpty())
})
})

Expand Down
2 changes: 1 addition & 1 deletion test/e2e/watchnamespace/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func DeleteAllObjectsOf(namespace string, listProtos ...client.ObjectList) {
}, 60, 1).Should(BeTrue())
}

func ListObjectsInNamespace(namespace string, listProtos ...client.ObjectList) []client.Object {
func ListObjectsInNamespace(namespace string, listProtos []client.ObjectList) []client.Object {
var result []client.Object
for _, listProto := range listProtos {
objects := listObjectsByListProto(namespace, listProto)
Expand Down

0 comments on commit baa094c

Please sign in to comment.