env_test.yaml 12 KB

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