Skip to content

Commit 6c230e2

Browse files
committed
Added initial version of e2e test which needs improvment and additional tests
Signed-off-by: Anand Francis Joseph <[email protected]>
1 parent 90000c5 commit 6c230e2

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

test/openshift/e2e/ginkgo/fixture/deployment/fixture.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,14 @@ func HaveServiceAccountName(expectedServiceAccountName string) matcher.GomegaMat
364364
})
365365
}
366366

367+
// HaveResourceRequirements validates if the deployment object contains the given resource requirements.
368+
func HaveResourceRequirements(requirements *corev1.ResourceRequirements) matcher.GomegaMatcher {
369+
return fetchDeployment(func(depl *appsv1.Deployment) bool {
370+
GinkgoWriter.Println("Deployment HaveResourceRequirements:", "expected: ", requirements.String(), "actual: ", depl.Spec.Template.Spec.Resources.String())
371+
return reflect.DeepEqual(requirements, depl.Spec.Template.Spec.Resources)
372+
})
373+
}
374+
367375
// This is intentionally NOT exported, for now. Create another function in this file/package that calls this function, and export that.
368376
func fetchDeployment(f func(*appsv1.Deployment) bool) matcher.GomegaMatcher {
369377

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package parallel
2+
3+
import (
4+
. "github.com/onsi/ginkgo/v2"
5+
. "github.com/onsi/gomega"
6+
gitopsoperatorv1alpha1 "github.com/redhat-developer/gitops-operator/api/v1alpha1"
7+
"github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture"
8+
deploymentFixture "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/deployment"
9+
gitopsserviceFixture "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/gitopsservice"
10+
k8sFixture "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/k8s"
11+
appsv1 "k8s.io/api/apps/v1"
12+
corev1 "k8s.io/api/core/v1"
13+
"k8s.io/apimachinery/pkg/api/resource"
14+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
15+
)
16+
17+
var _ = Describe("GitOps Operator Parallel E2E Tests", func() {
18+
19+
Context("1-120-validate_resource_constraints_gitopsservice_test", func() {
20+
BeforeEach(func() {
21+
fixture.EnsureSequentialCleanSlate()
22+
23+
})
24+
25+
It("validates that GitOpsService can take in custom resource constraints", func() {
26+
27+
By("enabling resource constraints on GitOpsService CR")
28+
gitopsService := &gitopsoperatorv1alpha1.GitopsService{
29+
ObjectMeta: metav1.ObjectMeta{Name: "cluster"},
30+
}
31+
Expect(gitopsService).To(k8sFixture.ExistByName())
32+
gitopsserviceFixture.Update(gitopsService, func(gs *gitopsoperatorv1alpha1.GitopsService) {
33+
gs.Spec.Resources = &corev1.ResourceRequirements{
34+
Requests: corev1.ResourceList{
35+
"cpu": resource.MustParse("200m"),
36+
"memory": resource.MustParse("256Mi"),
37+
},
38+
Limits: corev1.ResourceList{
39+
"cpu": resource.MustParse("500m"),
40+
"memory": resource.MustParse("512Mi"),
41+
},
42+
}
43+
})
44+
45+
// Ensure the change is reverted when the test exits
46+
defer func() {
47+
gitopsserviceFixture.Update(gitopsService, func(gs *gitopsoperatorv1alpha1.GitopsService) {
48+
gs.Spec.Resources = nil
49+
})
50+
}()
51+
52+
By("verifying the openshift-gitops resources have honoured the resource constraints")
53+
clusterDepl := &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: "cluster", Namespace: "openshift-gitops"}}
54+
Eventually(clusterDepl).Should(
55+
And(
56+
deploymentFixture.HaveResourceRequirements(&corev1.ResourceRequirements{
57+
Requests: corev1.ResourceList{
58+
"cpu": resource.MustParse("200m"),
59+
"memory": resource.MustParse("256Mi"),
60+
},
61+
Limits: corev1.ResourceList{
62+
"cpu": resource.MustParse("500m"),
63+
"memory": resource.MustParse("512Mi"),
64+
},
65+
}),
66+
),
67+
)
68+
})
69+
})
70+
})

0 commit comments

Comments
 (0)