env_test.yaml 11 KB

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