service_account_name_test.yaml 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. suite: pod service account name test
  2. templates:
  3. - common.yaml
  4. tests:
  5. - it: should assign serviceAccount to primary pod
  6. set:
  7. workload:
  8. workload-name1:
  9. enabled: true
  10. primary: true
  11. type: CronJob
  12. schedule: "* * * * *"
  13. podSpec: {}
  14. workload-name2:
  15. enabled: true
  16. primary: false
  17. type: Deployment
  18. podSpec: {}
  19. serviceAccount:
  20. sa-name1:
  21. enabled: true
  22. primary: true
  23. asserts:
  24. - documentIndex: &cronJobDoc 1
  25. isKind:
  26. of: CronJob
  27. - documentIndex: *cronJobDoc
  28. equal:
  29. path: metadata.name
  30. value: release-name-common-test
  31. - documentIndex: *cronJobDoc
  32. equal:
  33. path: spec.jobTemplate.spec.template.spec.serviceAccountName
  34. value: release-name-common-test
  35. - documentIndex: &otherDeploymentDoc 2
  36. isKind:
  37. of: Deployment
  38. - documentIndex: *otherDeploymentDoc
  39. equal:
  40. path: spec.template.spec.serviceAccountName
  41. value: default
  42. - it: should assign serviceAccount to all pods
  43. set:
  44. workload:
  45. workload-name1:
  46. enabled: true
  47. primary: true
  48. type: Deployment
  49. podSpec: {}
  50. workload-name2:
  51. enabled: true
  52. primary: false
  53. type: Deployment
  54. podSpec: {}
  55. serviceAccount:
  56. sa-name1:
  57. enabled: true
  58. primary: true
  59. targetSelectAll: true
  60. asserts:
  61. - documentIndex: &deploymentDoc 1
  62. isKind:
  63. of: Deployment
  64. - documentIndex: *deploymentDoc
  65. equal:
  66. path: spec.template.spec.serviceAccountName
  67. value: release-name-common-test
  68. - documentIndex: &otherDeploymentDoc 2
  69. isKind:
  70. of: Deployment
  71. - documentIndex: *otherDeploymentDoc
  72. equal:
  73. path: spec.template.spec.serviceAccountName
  74. value: release-name-common-test
  75. - it: should assign serviceAccount to selected pods
  76. set:
  77. workload:
  78. workload-name1:
  79. enabled: true
  80. primary: true
  81. type: Deployment
  82. podSpec: {}
  83. workload-name2:
  84. enabled: true
  85. primary: false
  86. type: Deployment
  87. podSpec: {}
  88. serviceAccount:
  89. sa-name1:
  90. enabled: true
  91. primary: true
  92. targetSelector:
  93. - workload-name1
  94. sa-name2:
  95. enabled: true
  96. primary: false
  97. targetSelector:
  98. - workload-name2
  99. asserts:
  100. - documentIndex: &deploymentDoc 2
  101. isKind:
  102. of: Deployment
  103. - documentIndex: *deploymentDoc
  104. equal:
  105. path: spec.template.spec.serviceAccountName
  106. value: release-name-common-test
  107. - documentIndex: &otherDeploymentDoc 3
  108. isKind:
  109. of: Deployment
  110. - documentIndex: *otherDeploymentDoc
  111. equal:
  112. path: spec.template.spec.serviceAccountName
  113. value: release-name-common-test-sa-name2
  114. - it: should assign serviceAccount to selected pods
  115. set:
  116. workload:
  117. workload-name1:
  118. enabled: true
  119. primary: true
  120. type: Deployment
  121. podSpec: {}
  122. workload-name2:
  123. enabled: true
  124. primary: false
  125. type: Deployment
  126. podSpec: {}
  127. serviceAccount:
  128. sa-name1:
  129. enabled: true
  130. primary: true
  131. targetSelector:
  132. - workload-name1
  133. - workload-name2
  134. asserts:
  135. - documentIndex: &deploymentDoc 1
  136. isKind:
  137. of: Deployment
  138. - documentIndex: *deploymentDoc
  139. equal:
  140. path: spec.template.spec.serviceAccountName
  141. value: release-name-common-test
  142. - documentIndex: &otherDeploymentDoc 2
  143. isKind:
  144. of: Deployment
  145. - documentIndex: *otherDeploymentDoc
  146. equal:
  147. path: spec.template.spec.serviceAccountName
  148. value: release-name-common-test
  149. # Failures
  150. - it: should fail with more than 1 SA assigned to a pod
  151. set:
  152. workload:
  153. workload-name1:
  154. enabled: true
  155. primary: true
  156. type: Deployment
  157. podSpec: {}
  158. serviceAccount:
  159. sa-name1:
  160. enabled: true
  161. primary: true
  162. targetSelector:
  163. - workload-name1
  164. sa-name2:
  165. enabled: true
  166. targetSelector:
  167. - workload-name1
  168. asserts:
  169. - failedTemplate:
  170. errorMessage: Expected at most 1 ServiceAccount to be assigned on a pod [workload-name1]. But [2] were assigned