env_test.yaml 12 KB

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