env_test.yaml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. suite: container env test
  2. templates:
  3. - common.yaml
  4. tests:
  5. - it: should create the correct env
  6. set:
  7. some_value: value1
  8. some_other_value: 2
  9. image: &image
  10. repository: nginx
  11. tag: 1.19.0
  12. pullPolicy: IfNotPresent
  13. configmap:
  14. configmap-name:
  15. enabled: true
  16. data:
  17. key1: value1
  18. key2: value2
  19. secret:
  20. secret-name:
  21. enabled: true
  22. data:
  23. key1: value1
  24. key2: value2
  25. workload:
  26. workload-name:
  27. enabled: true
  28. primary: true
  29. type: Deployment
  30. podSpec:
  31. containers:
  32. container-name1:
  33. enabled: true
  34. primary: true
  35. imageSelector: image
  36. probes: &probes
  37. liveness:
  38. enabled: false
  39. readiness:
  40. enabled: false
  41. startup:
  42. enabled: false
  43. env:
  44. VAR1: "{{ .Values.some_value }}"
  45. VAR2: some_value
  46. VAR3:
  47. configMapKeyRef:
  48. name: configmap-name
  49. key: key1
  50. VAR4:
  51. secretKeyRef:
  52. name: secret-name
  53. key: key2
  54. VAR5:
  55. configMapKeyRef:
  56. expandObjectName: false
  57. name: configmap-name
  58. key: key3
  59. VAR6:
  60. secretKeyRef:
  61. expandObjectName: false
  62. name: secret-name
  63. key: key4
  64. VAR7:
  65. fieldRef:
  66. fieldPath: metadata.name
  67. VAR8: ""
  68. asserts:
  69. - documentIndex: &deploymentDoc 2
  70. isKind:
  71. of: Deployment
  72. - documentIndex: *deploymentDoc
  73. isAPIVersion:
  74. of: apps/v1
  75. - documentIndex: *deploymentDoc
  76. contains:
  77. path: spec.template.spec.containers[0].env
  78. content:
  79. name: VAR1
  80. value: value1
  81. - documentIndex: *deploymentDoc
  82. contains:
  83. path: spec.template.spec.containers[0].env
  84. content:
  85. name: VAR2
  86. value: some_value
  87. - documentIndex: *deploymentDoc
  88. contains:
  89. path: spec.template.spec.containers[0].env
  90. content:
  91. name: VAR3
  92. valueFrom:
  93. configMapKeyRef:
  94. key: key1
  95. name: release-name-common-test-configmap-name
  96. - documentIndex: *deploymentDoc
  97. contains:
  98. path: spec.template.spec.containers[0].env
  99. content:
  100. name: VAR4
  101. valueFrom:
  102. secretKeyRef:
  103. key: key2
  104. name: release-name-common-test-secret-name
  105. - documentIndex: *deploymentDoc
  106. contains:
  107. path: spec.template.spec.containers[0].env
  108. content:
  109. name: VAR5
  110. valueFrom:
  111. configMapKeyRef:
  112. key: key3
  113. name: configmap-name
  114. - documentIndex: *deploymentDoc
  115. contains:
  116. path: spec.template.spec.containers[0].env
  117. content:
  118. name: VAR6
  119. valueFrom:
  120. secretKeyRef:
  121. key: key4
  122. name: secret-name
  123. - documentIndex: *deploymentDoc
  124. contains:
  125. path: spec.template.spec.containers[0].env
  126. content:
  127. name: VAR7
  128. valueFrom:
  129. fieldRef:
  130. fieldPath: metadata.name
  131. - documentIndex: *deploymentDoc
  132. contains:
  133. path: spec.template.spec.containers[0].env
  134. content:
  135. name: VAR8
  136. value: ""
  137. # Failures
  138. - it: it should fail invalid ref
  139. set:
  140. image: *image
  141. workload:
  142. workload-name:
  143. enabled: true
  144. primary: true
  145. type: Deployment
  146. podSpec:
  147. containers:
  148. container-name1:
  149. enabled: true
  150. primary: true
  151. imageSelector: image
  152. probes: *probes
  153. env:
  154. VAR:
  155. invalidKeyRef: {}
  156. asserts:
  157. - failedTemplate:
  158. errorMessage: Container - Expected <env> with a ref to have one of [configMapKeyRef, secretKeyRef, fieldRef], but got [invalidKeyRef]
  159. - it: it should fail with more than one ref
  160. set:
  161. image: *image
  162. workload:
  163. workload-name:
  164. enabled: true
  165. primary: true
  166. type: Deployment
  167. podSpec:
  168. containers:
  169. container-name1:
  170. enabled: true
  171. primary: true
  172. imageSelector: image
  173. probes: *probes
  174. env:
  175. VAR:
  176. configMapKeyRef: {}
  177. secretKeyRef: {}
  178. asserts:
  179. - failedTemplate:
  180. errorMessage: Container - Expected <env> with a ref to have one of [configMapKeyRef, secretKeyRef, fieldRef], but got [configMapKeyRef, secretKeyRef]
  181. - it: it should fail with empty name in configMapKeyRef
  182. set:
  183. image: *image
  184. workload:
  185. workload-name:
  186. enabled: true
  187. primary: true
  188. type: Deployment
  189. podSpec:
  190. containers:
  191. container-name1:
  192. enabled: true
  193. primary: true
  194. imageSelector: image
  195. probes: *probes
  196. env:
  197. VAR:
  198. configMapKeyRef:
  199. name: ""
  200. key: key
  201. asserts:
  202. - failedTemplate:
  203. errorMessage: Container - Expected non-empty <env.configMapKeyRef.name>
  204. - it: it should fail with empty key in configMapKeyRef
  205. set:
  206. image: *image
  207. workload:
  208. workload-name:
  209. enabled: true
  210. primary: true
  211. type: Deployment
  212. podSpec:
  213. containers:
  214. container-name1:
  215. enabled: true
  216. primary: true
  217. imageSelector: image
  218. probes: *probes
  219. env:
  220. VAR:
  221. configMapKeyRef:
  222. name: name
  223. key: ""
  224. asserts:
  225. - failedTemplate:
  226. errorMessage: Container - Expected non-empty <env.configMapKeyRef.key>
  227. - it: it should fail with empty name in secretKeyRef
  228. set:
  229. image: *image
  230. workload:
  231. workload-name:
  232. enabled: true
  233. primary: true
  234. type: Deployment
  235. podSpec:
  236. containers:
  237. container-name1:
  238. enabled: true
  239. primary: true
  240. imageSelector: image
  241. probes: *probes
  242. env:
  243. VAR:
  244. secretKeyRef:
  245. name: ""
  246. key: key
  247. asserts:
  248. - failedTemplate:
  249. errorMessage: Container - Expected non-empty <env.secretKeyRef.name>
  250. - it: it should fail with empty key in secretKeyRef
  251. set:
  252. image: *image
  253. workload:
  254. workload-name:
  255. enabled: true
  256. primary: true
  257. type: Deployment
  258. podSpec:
  259. containers:
  260. container-name1:
  261. enabled: true
  262. primary: true
  263. imageSelector: image
  264. probes: *probes
  265. env:
  266. VAR:
  267. secretKeyRef:
  268. name: name
  269. key: ""
  270. asserts:
  271. - failedTemplate:
  272. errorMessage: Container - Expected non-empty <env.secretKeyRef.key>
  273. - it: it should fail with referenced secret not defined
  274. set:
  275. image: *image
  276. workload:
  277. workload-name:
  278. enabled: true
  279. primary: true
  280. type: Deployment
  281. podSpec:
  282. containers:
  283. container-name1:
  284. enabled: true
  285. primary: true
  286. imageSelector: image
  287. probes: *probes
  288. env:
  289. VAR:
  290. secretKeyRef:
  291. name: secret-name
  292. key: somekey
  293. asserts:
  294. - failedTemplate:
  295. errorMessage: Container - Expected in <env> the referenced Secret [secret-name] to be defined
  296. - it: it should fail with referenced configmap not defined
  297. set:
  298. image: *image
  299. workload:
  300. workload-name:
  301. enabled: true
  302. primary: true
  303. type: Deployment
  304. podSpec:
  305. containers:
  306. container-name1:
  307. enabled: true
  308. primary: true
  309. imageSelector: image
  310. probes: *probes
  311. env:
  312. VAR:
  313. configMapKeyRef:
  314. name: configmap-name
  315. key: somekey
  316. asserts:
  317. - failedTemplate:
  318. errorMessage: Container - Expected in <env> the referenced Configmap [configmap-name] to be defined
  319. - it: it should fail with referenced key in configmap not defined
  320. set:
  321. image: *image
  322. configmap:
  323. configmap-name:
  324. enabled: true
  325. data:
  326. key1: value1
  327. key2: value2
  328. workload:
  329. workload-name:
  330. enabled: true
  331. primary: true
  332. type: Deployment
  333. podSpec:
  334. containers:
  335. container-name1:
  336. enabled: true
  337. primary: true
  338. imageSelector: image
  339. probes: *probes
  340. env:
  341. VAR:
  342. configMapKeyRef:
  343. name: configmap-name
  344. key: somekey
  345. asserts:
  346. - failedTemplate:
  347. errorMessage: Container - Expected in <env> the referenced key [somekey] in Configmap [configmap-name] to be defined
  348. - it: it should fail with referenced key in secret not defined
  349. set:
  350. image: *image
  351. secret:
  352. secret-name:
  353. enabled: true
  354. data:
  355. key1: value1
  356. key2: value2
  357. workload:
  358. workload-name:
  359. enabled: true
  360. primary: true
  361. type: Deployment
  362. podSpec:
  363. containers:
  364. container-name1:
  365. enabled: true
  366. primary: true
  367. imageSelector: image
  368. probes: *probes
  369. env:
  370. VAR:
  371. secretKeyRef:
  372. name: secret-name
  373. key: somekey
  374. asserts:
  375. - failedTemplate:
  376. errorMessage: Container - Expected in <env> the referenced key [somekey] in Secret [secret-name] to be defined
  377. - it: it should fail with empty fieldPath in fieldRef
  378. set:
  379. image: *image
  380. workload:
  381. workload-name:
  382. enabled: true
  383. primary: true
  384. type: Deployment
  385. podSpec:
  386. containers:
  387. container-name1:
  388. enabled: true
  389. primary: true
  390. imageSelector: image
  391. probes: *probes
  392. env:
  393. VAR:
  394. fieldRef:
  395. fieldPath: ""
  396. asserts:
  397. - failedTemplate:
  398. errorMessage: Container - Expected non-empty <env.fieldRef.fieldPath>