Skip to content

Commit 67ce7b7

Browse files
committed
Add unit tests
1 parent f21c6b8 commit 67ce7b7

4 files changed

Lines changed: 429 additions & 0 deletions
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
suite: Test vpArgoNamespace in application-policies
2+
templates:
3+
- templates/policies/application-policies.yaml
4+
release:
5+
name: release-test
6+
tests:
7+
- it: should use custom vpArgoNamespace in ClusterRoleBinding name
8+
values:
9+
- ./clusterselector_values.yaml
10+
set:
11+
global:
12+
vpArgoNamespace: custom-argocd
13+
multiSourceSupport: true
14+
multiSourceRepoUrl: "https://charts.example.com"
15+
multiSourceTargetRevision: "0.1.0"
16+
asserts:
17+
- documentSelector:
18+
path: metadata.name
19+
value: group-one-clustergroup-policy
20+
equal:
21+
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.metadata.name
22+
value: custom-argocd-cluster-admin-rolebinding
23+
24+
- it: should use custom vpArgoNamespace in ServiceAccount subjects
25+
values:
26+
- ./clusterselector_values.yaml
27+
set:
28+
global:
29+
vpArgoNamespace: custom-argocd
30+
multiSourceSupport: true
31+
multiSourceRepoUrl: "https://charts.example.com"
32+
multiSourceTargetRevision: "0.1.0"
33+
asserts:
34+
- documentSelector:
35+
path: metadata.name
36+
value: group-one-clustergroup-policy
37+
contains:
38+
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.subjects
39+
content:
40+
kind: ServiceAccount
41+
name: custom-argocd-argocd-application-controller
42+
namespace: custom-argocd
43+
- documentSelector:
44+
path: metadata.name
45+
value: group-one-clustergroup-policy
46+
contains:
47+
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.subjects
48+
content:
49+
kind: ServiceAccount
50+
name: custom-argocd-argocd-server
51+
namespace: custom-argocd
52+
53+
- it: should use custom vpArgoNamespace for Application namespace
54+
values:
55+
- ./clusterselector_values.yaml
56+
set:
57+
global:
58+
vpArgoNamespace: custom-argocd
59+
multiSourceSupport: true
60+
multiSourceRepoUrl: "https://charts.example.com"
61+
multiSourceTargetRevision: "0.1.0"
62+
asserts:
63+
- documentSelector:
64+
path: metadata.name
65+
value: group-one-clustergroup-policy
66+
equal:
67+
path: spec.policy-templates[0].objectDefinition.spec.object-templates[1].objectDefinition.metadata.namespace
68+
value: custom-argocd
69+
70+
- it: should pass vpArgoNamespace as a helm parameter
71+
values:
72+
- ./clusterselector_values.yaml
73+
set:
74+
global:
75+
vpArgoNamespace: custom-argocd
76+
multiSourceSupport: true
77+
multiSourceRepoUrl: "https://charts.example.com"
78+
multiSourceTargetRevision: "0.1.0"
79+
asserts:
80+
- documentSelector:
81+
path: metadata.name
82+
value: group-one-clustergroup-policy
83+
contains:
84+
path: spec.policy-templates[0].objectDefinition.spec.object-templates[1].objectDefinition.spec.sources[1].helm.parameters
85+
content:
86+
name: global.vpArgoNamespace
87+
value: custom-argocd
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
suite: Test vpArgoNamespace in ocp-gitops-policy
2+
templates:
3+
- templates/policies/ocp-gitops-policy.yaml
4+
release:
5+
name: release-test
6+
tests:
7+
- it: should set DISABLE_DEFAULT_ARGOCD_INSTANCE when vpArgoNamespace is not openshift-gitops
8+
values:
9+
- ./clusterselector_values.yaml
10+
set:
11+
global:
12+
vpArgoNamespace: custom-argocd
13+
asserts:
14+
- documentSelector:
15+
path: metadata.name
16+
value: group-one-gitops-policy
17+
contains:
18+
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.config.env
19+
content:
20+
name: DISABLE_DEFAULT_ARGOCD_INSTANCE
21+
value: "true"
22+
23+
- it: should NOT set DISABLE_DEFAULT_ARGOCD_INSTANCE when vpArgoNamespace is openshift-gitops
24+
values:
25+
- ./clusterselector_values.yaml
26+
asserts:
27+
- documentSelector:
28+
path: metadata.name
29+
value: group-one-gitops-policy
30+
lengthEqual:
31+
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.spec.config.env
32+
count: 1
33+
34+
- it: should create a Namespace object-template with custom vpArgoNamespace
35+
values:
36+
- ./clusterselector_values.yaml
37+
set:
38+
global:
39+
vpArgoNamespace: custom-argocd
40+
asserts:
41+
- documentSelector:
42+
path: metadata.name
43+
value: group-one-gitops-policy
44+
equal:
45+
path: spec.policy-templates[0].objectDefinition.spec.object-templates[1].objectDefinition.kind
46+
value: Namespace
47+
- documentSelector:
48+
path: metadata.name
49+
value: group-one-gitops-policy
50+
equal:
51+
path: spec.policy-templates[0].objectDefinition.spec.object-templates[1].objectDefinition.metadata.name
52+
value: custom-argocd
53+
54+
- it: should create a Namespace object-template with default vpArgoNamespace
55+
values:
56+
- ./clusterselector_values.yaml
57+
asserts:
58+
- documentSelector:
59+
path: metadata.name
60+
value: group-one-gitops-policy
61+
equal:
62+
path: spec.policy-templates[0].objectDefinition.spec.object-templates[1].objectDefinition.kind
63+
value: Namespace
64+
- documentSelector:
65+
path: metadata.name
66+
value: group-one-gitops-policy
67+
equal:
68+
path: spec.policy-templates[0].objectDefinition.spec.object-templates[1].objectDefinition.metadata.name
69+
value: openshift-gitops
70+
71+
- it: should use custom vpArgoNamespace for trusted-ca-bundle ConfigMap namespace
72+
values:
73+
- ./clusterselector_values.yaml
74+
set:
75+
global:
76+
vpArgoNamespace: custom-argocd
77+
asserts:
78+
- documentSelector:
79+
path: metadata.name
80+
value: group-one-gitops-policy
81+
equal:
82+
path: spec.policy-templates[0].objectDefinition.spec.object-templates[2].objectDefinition.metadata.namespace
83+
value: custom-argocd
84+
- documentSelector:
85+
path: metadata.name
86+
value: group-one-gitops-policy
87+
equal:
88+
path: spec.policy-templates[0].objectDefinition.spec.object-templates[2].objectDefinition.kind
89+
value: ConfigMap
90+
91+
- it: should use custom vpArgoNamespace for ArgoCD resource name and namespace
92+
values:
93+
- ./clusterselector_values.yaml
94+
set:
95+
global:
96+
vpArgoNamespace: custom-argocd
97+
asserts:
98+
- documentSelector:
99+
path: metadata.name
100+
value: group-one-gitops-policy-argocd
101+
equal:
102+
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.metadata.name
103+
value: custom-argocd
104+
- documentSelector:
105+
path: metadata.name
106+
value: group-one-gitops-policy-argocd
107+
equal:
108+
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.metadata.namespace
109+
value: custom-argocd
110+
111+
- it: should use default vpArgoNamespace for ArgoCD resource name and namespace
112+
values:
113+
- ./clusterselector_values.yaml
114+
asserts:
115+
- documentSelector:
116+
path: metadata.name
117+
value: group-one-gitops-policy-argocd
118+
equal:
119+
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.metadata.name
120+
value: openshift-gitops
121+
- documentSelector:
122+
path: metadata.name
123+
value: group-one-gitops-policy-argocd
124+
equal:
125+
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.metadata.namespace
126+
value: openshift-gitops
127+
128+
- it: should create ConsoleLink when vpArgoNamespace is not openshift-gitops
129+
values:
130+
- ./clusterselector_values.yaml
131+
set:
132+
global:
133+
vpArgoNamespace: custom-argocd
134+
asserts:
135+
- documentSelector:
136+
path: metadata.name
137+
value: group-one-gitops-policy-argocd
138+
lengthEqual:
139+
path: spec.policy-templates[0].objectDefinition.spec.object-templates
140+
count: 2
141+
- documentSelector:
142+
path: metadata.name
143+
value: group-one-gitops-policy-argocd
144+
equal:
145+
path: spec.policy-templates[0].objectDefinition.spec.object-templates[1].objectDefinition.kind
146+
value: ConsoleLink
147+
- documentSelector:
148+
path: metadata.name
149+
value: group-one-gitops-policy-argocd
150+
equal:
151+
path: spec.policy-templates[0].objectDefinition.spec.object-templates[1].objectDefinition.metadata.name
152+
value: custom-argocd-gitops-link
153+
- documentSelector:
154+
path: metadata.name
155+
value: group-one-gitops-policy-argocd
156+
equal:
157+
path: spec.policy-templates[0].objectDefinition.spec.object-templates[1].objectDefinition.spec.location
158+
value: ApplicationMenu
159+
- documentSelector:
160+
path: metadata.name
161+
value: group-one-gitops-policy-argocd
162+
equal:
163+
path: spec.policy-templates[0].objectDefinition.spec.object-templates[1].objectDefinition.spec.text
164+
value: ArgoCD VP
165+
166+
- it: should NOT create ConsoleLink when vpArgoNamespace is openshift-gitops
167+
values:
168+
- ./clusterselector_values.yaml
169+
asserts:
170+
- documentSelector:
171+
path: metadata.name
172+
value: group-one-gitops-policy-argocd
173+
lengthEqual:
174+
path: spec.policy-templates[0].objectDefinition.spec.object-templates
175+
count: 1
176+
177+
- it: should have 3 object-templates with custom vpArgoNamespace and no gitOpsSubNamespace
178+
values:
179+
- ./clusterselector_values.yaml
180+
set:
181+
global:
182+
vpArgoNamespace: custom-argocd
183+
asserts:
184+
- documentSelector:
185+
path: metadata.name
186+
value: group-one-gitops-policy
187+
lengthEqual:
188+
path: spec.policy-templates[0].objectDefinition.spec.object-templates
189+
count: 3
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
suite: Test vpArgoNamespace in acm-hub-ca-policy
2+
templates:
3+
- templates/policies/acm-hub-ca-policy.yaml
4+
release:
5+
name: release-test
6+
tests:
7+
- it: should use custom vpArgoNamespace for trusted-hub-bundle ConfigMap namespace
8+
set:
9+
global:
10+
vpArgoNamespace: custom-argocd
11+
secretStore:
12+
backend: vault
13+
clusterGroup:
14+
isHubCluster: true
15+
managedClusterGroups:
16+
testRegion:
17+
name: region-one
18+
acmlabels:
19+
- name: clusterGroup
20+
value: region-one
21+
asserts:
22+
- documentSelector:
23+
path: metadata.name
24+
value: region-one-hub-argo-ca-gitops-policy
25+
equal:
26+
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.metadata.namespace
27+
value: custom-argocd
28+
- documentSelector:
29+
path: metadata.name
30+
value: region-one-hub-argo-ca-gitops-policy
31+
equal:
32+
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.metadata.name
33+
value: trusted-hub-bundle
34+
35+
- it: should use default vpArgoNamespace for trusted-hub-bundle ConfigMap namespace
36+
set:
37+
global:
38+
secretStore:
39+
backend: vault
40+
clusterGroup:
41+
isHubCluster: true
42+
managedClusterGroups:
43+
testRegion:
44+
name: region-one
45+
acmlabels:
46+
- name: clusterGroup
47+
value: region-one
48+
asserts:
49+
- documentSelector:
50+
path: metadata.name
51+
value: region-one-hub-argo-ca-gitops-policy
52+
equal:
53+
path: spec.policy-templates[0].objectDefinition.spec.object-templates[0].objectDefinition.metadata.namespace
54+
value: openshift-gitops

0 commit comments

Comments
 (0)