Skip to content

Commit 60472d6

Browse files
added ginkgo test for Banner property of argocd (#962)
* added ginkgo test for Banner property of argocd Signed-off-by: Alka Kumari <alkumari@redhat.com> * merged It blocks into one and removed unwanted tests Signed-off-by: Alka Kumari <alkumari@redhat.com> --------- Signed-off-by: Alka Kumari <alkumari@redhat.com> Co-authored-by: Siddhesh Ghadi <61187612+svghadi@users.noreply.github.com>
1 parent 595fd5d commit 60472d6

1 file changed

Lines changed: 260 additions & 0 deletions

File tree

Lines changed: 260 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,260 @@
1+
/*
2+
Copyright 2025.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package parallel
18+
19+
import (
20+
"context"
21+
22+
argov1beta1api "github.com/argoproj-labs/argocd-operator/api/v1beta1"
23+
. "github.com/onsi/ginkgo/v2"
24+
. "github.com/onsi/gomega"
25+
"github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture"
26+
argocdFixture "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/argocd"
27+
fixtureUtils "github.com/redhat-developer/gitops-operator/test/openshift/e2e/ginkgo/fixture/utils"
28+
corev1 "k8s.io/api/core/v1"
29+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
30+
"k8s.io/apimachinery/pkg/types"
31+
32+
"sigs.k8s.io/controller-runtime/pkg/client"
33+
)
34+
35+
var _ = Describe("GitOps Operator Parallel E2E Tests", func() {
36+
37+
Context("1-120_validate_banner", func() {
38+
39+
var (
40+
k8sClient client.Client
41+
ctx context.Context
42+
ns *corev1.Namespace
43+
cleanupFunc func()
44+
)
45+
46+
BeforeEach(func() {
47+
fixture.EnsureParallelCleanSlate()
48+
k8sClient, _ = fixtureUtils.GetE2ETestKubeClient()
49+
ctx = context.Background()
50+
})
51+
52+
AfterEach(func() {
53+
fixture.OutputDebugOnFail(ns)
54+
55+
if cleanupFunc != nil {
56+
cleanupFunc()
57+
}
58+
})
59+
60+
It("verifies ArgoCD banner configuration is applied to ArgoCD CR and ConfigMap", func() {
61+
62+
By("creating simple namespace-scoped Argo CD instance")
63+
ns, cleanupFunc = fixture.CreateRandomE2ETestNamespaceWithCleanupFunc()
64+
65+
argoCD := &argov1beta1api.ArgoCD{
66+
ObjectMeta: metav1.ObjectMeta{Name: "argocd", Namespace: ns.Name},
67+
Spec: argov1beta1api.ArgoCDSpec{
68+
Server: argov1beta1api.ArgoCDServerSpec{
69+
Route: argov1beta1api.ArgoCDRouteSpec{
70+
Enabled: true,
71+
},
72+
},
73+
},
74+
}
75+
Expect(k8sClient.Create(ctx, argoCD)).To(Succeed())
76+
77+
By("waiting for ArgoCD CR to be reconciled and the instance to be ready")
78+
Eventually(argoCD, "5m", "5s").Should(argocdFixture.BeAvailable())
79+
80+
By("configuring banner settings on the ArgoCD server")
81+
argocdFixture.Update(argoCD, func(ac *argov1beta1api.ArgoCD) {
82+
ac.Spec.Banner = &argov1beta1api.Banner{
83+
Content: "This is a test banner for E2E validation",
84+
Position: "top",
85+
Permanent: true,
86+
URL: "https://argo-cd.readthedocs.io/",
87+
}
88+
})
89+
90+
By("verifying the banner configuration is stored in ArgoCD argocd-cm ConfigMap")
91+
Eventually(func() bool {
92+
configMap := &corev1.ConfigMap{}
93+
err := k8sClient.Get(ctx, types.NamespacedName{
94+
Name: "argocd-cm",
95+
Namespace: ns.Name,
96+
}, configMap)
97+
if err != nil {
98+
GinkgoWriter.Printf("Failed to get argocd-cm ConfigMap: %v\n", err)
99+
return false
100+
}
101+
102+
// Check if banner settings are present in the ConfigMap data
103+
if configMap.Data == nil {
104+
GinkgoWriter.Printf("ConfigMap data is nil\n")
105+
return false
106+
}
107+
108+
// Validate specific banner configuration keys
109+
expectedKeys := map[string]string{
110+
"ui.bannercontent": "This is a test banner for E2E validation",
111+
"ui.bannerposition": "top",
112+
"ui.bannerpermanent": "true",
113+
"ui.bannerurl": "https://argo-cd.readthedocs.io/",
114+
}
115+
116+
for key, expectedValue := range expectedKeys {
117+
actualValue, exists := configMap.Data[key]
118+
if !exists {
119+
GinkgoWriter.Printf("Missing key %s in ConfigMap\n", key)
120+
return false
121+
}
122+
if actualValue != expectedValue {
123+
GinkgoWriter.Printf("Key %s has value %s, expected %s\n", key, actualValue, expectedValue)
124+
return false
125+
}
126+
GinkgoWriter.Printf("✓ Found correct banner config: %s = %s\n", key, actualValue)
127+
}
128+
129+
return true
130+
}, "120s", "5s").Should(BeTrue())
131+
132+
By("updating banner settings")
133+
argocdFixture.Update(argoCD, func(ac *argov1beta1api.ArgoCD) {
134+
ac.Spec.Banner = &argov1beta1api.Banner{
135+
Content: "Updated banner message",
136+
Position: "top",
137+
Permanent: true,
138+
URL: "https://updated.example.com",
139+
}
140+
})
141+
142+
By("verifying the updated configuration is applied in ArgoCD CR")
143+
Eventually(func() bool {
144+
updatedArgoCD := &argov1beta1api.ArgoCD{}
145+
err := k8sClient.Get(ctx, types.NamespacedName{
146+
Name: "argocd",
147+
Namespace: ns.Name,
148+
}, updatedArgoCD)
149+
if err != nil {
150+
return false
151+
}
152+
153+
if updatedArgoCD.Spec.Banner == nil {
154+
return false
155+
}
156+
157+
return updatedArgoCD.Spec.Banner.Content == "Updated banner message" &&
158+
updatedArgoCD.Spec.Banner.Position == "top" &&
159+
updatedArgoCD.Spec.Banner.Permanent == true &&
160+
updatedArgoCD.Spec.Banner.URL == "https://updated.example.com"
161+
}, "120s", "5s").Should(BeTrue())
162+
163+
By("verifying the updated banner configuration is reflected in ConfigMap and the unchanged ones are preserved")
164+
Eventually(func() bool {
165+
configMap := &corev1.ConfigMap{}
166+
err := k8sClient.Get(ctx, types.NamespacedName{
167+
Name: "argocd-cm",
168+
Namespace: ns.Name,
169+
}, configMap)
170+
if err != nil {
171+
GinkgoWriter.Printf("Failed to get argocd-cm ConfigMap: %v\n", err)
172+
return false
173+
}
174+
175+
if configMap.Data == nil {
176+
return false
177+
}
178+
179+
// Validate updated banner configuration keys
180+
expectedUpdatedKeys := map[string]string{
181+
"ui.bannercontent": "Updated banner message",
182+
"ui.bannerposition": "top",
183+
"ui.bannerpermanent": "true",
184+
"ui.bannerurl": "https://updated.example.com",
185+
}
186+
187+
for key, expectedValue := range expectedUpdatedKeys {
188+
actualValue, exists := configMap.Data[key]
189+
if !exists {
190+
GinkgoWriter.Printf("Missing updated key %s in ConfigMap\n", key)
191+
return false
192+
}
193+
if actualValue != expectedValue {
194+
GinkgoWriter.Printf("Updated key %s has value %s, expected %s\n", key, actualValue, expectedValue)
195+
return false
196+
}
197+
GinkgoWriter.Printf("✓ Found correct updated banner config: %s = %s\n", key, actualValue)
198+
}
199+
200+
return true
201+
}, "120s", "5s").Should(BeTrue())
202+
203+
By("removing banner configuration")
204+
argocdFixture.Update(argoCD, func(ac *argov1beta1api.ArgoCD) {
205+
ac.Spec.Banner = nil
206+
})
207+
208+
By("verifying the banner configuration is removed from ArgoCD CR")
209+
Eventually(func() bool {
210+
updatedArgoCD := &argov1beta1api.ArgoCD{}
211+
err := k8sClient.Get(ctx, types.NamespacedName{
212+
Name: "argocd",
213+
Namespace: ns.Name,
214+
}, updatedArgoCD)
215+
if err != nil {
216+
return false
217+
}
218+
219+
return updatedArgoCD.Spec.Banner == nil
220+
}, "120s", "5s").Should(BeTrue())
221+
222+
By("verifying banner fields are removed from ConfigMap")
223+
Eventually(func() bool {
224+
configMap := &corev1.ConfigMap{}
225+
err := k8sClient.Get(ctx, types.NamespacedName{
226+
Name: "argocd-cm",
227+
Namespace: ns.Name,
228+
}, configMap)
229+
if err != nil {
230+
GinkgoWriter.Printf("Failed to get argocd-cm ConfigMap: %v\n", err)
231+
return false
232+
}
233+
234+
if configMap.Data == nil {
235+
GinkgoWriter.Printf("ConfigMap data is nil, banner fields should be absent\n")
236+
return true // No data means no banner fields
237+
}
238+
239+
// Check that banner configuration keys are removed
240+
bannerKeys := []string{
241+
"ui.bannercontent",
242+
"ui.bannerposition",
243+
"ui.bannerpermanent",
244+
"ui.bannerurl",
245+
}
246+
247+
for _, key := range bannerKeys {
248+
if _, exists := configMap.Data[key]; exists {
249+
GinkgoWriter.Printf("Banner key %s still exists in ConfigMap after removal\n", key)
250+
return false
251+
}
252+
}
253+
254+
GinkgoWriter.Printf("✓ All banner configuration keys have been removed from ConfigMap\n")
255+
return true
256+
}, "120s", "5s").Should(BeTrue())
257+
258+
})
259+
})
260+
})

0 commit comments

Comments
 (0)