lifecycle_test.yaml 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. suite: container lifecycle test
  2. templates:
  3. - common.yaml
  4. tests:
  5. - it: should pass with lifecycle
  6. set:
  7. image: &image
  8. repository: nginx
  9. tag: 1.19.0
  10. pullPolicy: IfNotPresent
  11. workload:
  12. workload-name:
  13. enabled: true
  14. primary: true
  15. type: Deployment
  16. podSpec:
  17. containers:
  18. container-name1:
  19. enabled: true
  20. primary: true
  21. imageSelector: image
  22. probes: &probes
  23. liveness:
  24. enabled: false
  25. readiness:
  26. enabled: false
  27. startup:
  28. enabled: false
  29. lifecycle:
  30. postStart:
  31. type: exec
  32. command:
  33. - echo
  34. - hello
  35. preStop:
  36. type: http
  37. port: 80
  38. asserts:
  39. - documentIndex: &deploymentDoc 0
  40. isKind:
  41. of: Deployment
  42. - documentIndex: *deploymentDoc
  43. isAPIVersion:
  44. of: apps/v1
  45. - documentIndex: *deploymentDoc
  46. isSubset:
  47. path: spec.template.spec.containers[0]
  48. content:
  49. lifecycle:
  50. postStart:
  51. exec:
  52. command:
  53. - echo
  54. - hello
  55. preStop:
  56. httpGet:
  57. port: 80
  58. path: /
  59. scheme: HTTP
  60. - it: should pass with lifecycle
  61. set:
  62. image: *image
  63. some_command: ./some_command
  64. some_port: 80
  65. some_host: some_host
  66. some_path: /api/v1
  67. some_value: 123
  68. workload:
  69. workload-name:
  70. enabled: true
  71. primary: true
  72. type: Deployment
  73. podSpec:
  74. containers:
  75. container-name1:
  76. enabled: true
  77. primary: true
  78. imageSelector: image
  79. probes: *probes
  80. lifecycle:
  81. postStart:
  82. type: https
  83. port: "{{ .Values.some_port }}"
  84. host: "{{ .Values.some_host }}"
  85. path: "{{ .Values.some_path }}"
  86. httpHeaders:
  87. key: "{{ .Values.some_value }}"
  88. preStop:
  89. type: exec
  90. command: "{{ .Values.some_command }}"
  91. asserts:
  92. - documentIndex: &deploymentDoc 0
  93. isKind:
  94. of: Deployment
  95. - documentIndex: *deploymentDoc
  96. isAPIVersion:
  97. of: apps/v1
  98. - documentIndex: *deploymentDoc
  99. isSubset:
  100. path: spec.template.spec.containers[0]
  101. content:
  102. lifecycle:
  103. postStart:
  104. httpGet:
  105. port: 80
  106. path: /api/v1
  107. scheme: HTTPS
  108. host: some_host
  109. httpHeaders:
  110. - name: key
  111. value: "123"
  112. preStop:
  113. exec:
  114. command:
  115. - ./some_command
  116. # Failures
  117. - it: should fail with invalid lifecycle hook
  118. set:
  119. image: *image
  120. workload:
  121. workload-name:
  122. enabled: true
  123. primary: true
  124. type: Deployment
  125. podSpec:
  126. containers:
  127. container-name1:
  128. enabled: true
  129. primary: true
  130. probes: *probes
  131. imageSelector: image
  132. lifecycle:
  133. invalid: {}
  134. asserts:
  135. - failedTemplate:
  136. errorMessage: Container - Expected <lifecycle> <hook> to be one of [preStop, postStart], but got [invalid]
  137. - it: should fail with empty lifecycle type
  138. set:
  139. image: *image
  140. workload:
  141. workload-name:
  142. enabled: true
  143. primary: true
  144. type: Deployment
  145. podSpec:
  146. containers:
  147. container-name1:
  148. enabled: true
  149. primary: true
  150. imageSelector: image
  151. lifecycle:
  152. preStop:
  153. command: []
  154. asserts:
  155. - failedTemplate:
  156. errorMessage: Container - Expected non-empty <lifecycle> <type>
  157. - it: should fail with invalid lifecycle type
  158. set:
  159. image: *image
  160. workload:
  161. workload-name:
  162. enabled: true
  163. primary: true
  164. type: Deployment
  165. podSpec:
  166. containers:
  167. container-name1:
  168. enabled: true
  169. primary: true
  170. imageSelector: image
  171. lifecycle:
  172. preStop:
  173. type: invalid
  174. command: []
  175. asserts:
  176. - failedTemplate:
  177. errorMessage: Container - Expected <lifecycle> <type> to be one of [exec, http, https], but got [invalid]
  178. - it: should fail with empty command on exec lifecycle type
  179. set:
  180. image: *image
  181. workload:
  182. workload-name:
  183. enabled: true
  184. primary: true
  185. type: Deployment
  186. podSpec:
  187. containers:
  188. container-name1:
  189. enabled: true
  190. primary: true
  191. imageSelector: image
  192. lifecycle:
  193. preStop:
  194. type: exec
  195. command: []
  196. asserts:
  197. - failedTemplate:
  198. errorMessage: Container - Expected non-empty <lifecycle> <command> on [exec] type
  199. - it: should fail with empty port on http lifecycle type
  200. set:
  201. image: *image
  202. workload:
  203. workload-name:
  204. enabled: true
  205. primary: true
  206. type: Deployment
  207. podSpec:
  208. containers:
  209. container-name1:
  210. enabled: true
  211. primary: true
  212. imageSelector: image
  213. lifecycle:
  214. preStop:
  215. type: http
  216. port: ""
  217. asserts:
  218. - failedTemplate:
  219. errorMessage: Container - Expected non-empty <lifecycle> <port> on [http] type
  220. - it: should fail with path not starting with / on http lifecycle type
  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. lifecycle:
  235. preStop:
  236. type: http
  237. port: 80
  238. path: "api/v1"
  239. asserts:
  240. - failedTemplate:
  241. errorMessage: Container - Expected <lifecycle> <path> to start with a forward slash [/] on <http> type
  242. - it: should fail with empty value on httpHeaders on http lifecycle type
  243. set:
  244. image: *image
  245. workload:
  246. workload-name:
  247. enabled: true
  248. primary: true
  249. type: Deployment
  250. podSpec:
  251. containers:
  252. container-name1:
  253. enabled: true
  254. primary: true
  255. imageSelector: image
  256. lifecycle:
  257. preStop:
  258. type: http
  259. port: 80
  260. httpHeaders:
  261. key: ""
  262. asserts:
  263. - failedTemplate:
  264. errorMessage: Container - Expected non-empty <value> on <httpHeaders>