/spec/chef/recipes/gitlab-workhorse_spec.rb

https://gitlab.com/jgsqware/omnibus-gitlab · Ruby · 197 lines · 169 code · 28 blank · 0 comment · 0 complexity · 66ebb55506324c13e2e0df7cda27d505 MD5 · raw file

  1. require 'chef_helper'
  2. describe 'gitlab::gitlab-workhorse' do
  3. let(:chef_run) { ChefSpec::SoloRunner.converge('gitlab::default') }
  4. before do
  5. allow(Gitlab).to receive(:[]).and_call_original
  6. end
  7. context 'with environment variables' do
  8. context 'by default' do
  9. it_behaves_like "enabled gitlab-workhorse env", "HOME", '\/var\/opt\/gitlab'
  10. it_behaves_like "enabled gitlab-workhorse env", "PATH", '\/opt\/gitlab\/bin:\/opt\/gitlab\/embedded\/bin:\/bin:\/usr\/bin'
  11. context 'when a custom env variable is specified' do
  12. before do
  13. stub_gitlab_rb(gitlab_workhorse: { env: { 'IAM' => 'CUSTOMVAR'}})
  14. end
  15. it_behaves_like "enabled gitlab-workhorse env", "IAM", 'CUSTOMVAR'
  16. end
  17. end
  18. end
  19. context 'without api rate limiting' do
  20. it 'correctly renders out the workhorse service file' do
  21. expect(chef_run).to_not render_file("/opt/gitlab/sv/gitlab-workhorse/run").with_content(/\-apiLimit/)
  22. expect(chef_run).to_not render_file("/opt/gitlab/sv/gitlab-workhorse/run").with_content(/\-apiQueueDuration/)
  23. expect(chef_run).to_not render_file("/opt/gitlab/sv/gitlab-workhorse/run").with_content(/\-apiQueueLimit/)
  24. end
  25. end
  26. context 'with api rate limiting' do
  27. before do
  28. stub_gitlab_rb(gitlab_workhorse: { api_limit: 3, api_queue_limit: 6, api_queue_duration: '1m' })
  29. end
  30. it 'correctly renders out the workhorse service file' do
  31. expect(chef_run).to render_file("/opt/gitlab/sv/gitlab-workhorse/run").with_content(/\-apiLimit 3 \\/)
  32. expect(chef_run).to render_file("/opt/gitlab/sv/gitlab-workhorse/run").with_content(/\-apiQueueDuration 1m \\/)
  33. expect(chef_run).to render_file("/opt/gitlab/sv/gitlab-workhorse/run").with_content(/\-apiQueueLimit 6 \\/)
  34. end
  35. end
  36. context 'without prometheus listen address' do
  37. before do
  38. stub_gitlab_rb(gitlab_workhorse: {})
  39. end
  40. it 'correctly renders out the workhorse service file' do
  41. expect(chef_run).to render_file("/opt/gitlab/sv/gitlab-workhorse/run")
  42. expect(chef_run).not_to render_file("/opt/gitlab/sv/gitlab-workhorse/run").with_content(/\-prometheusListenAddr/)
  43. end
  44. end
  45. context 'with prometheus listen address' do
  46. before do
  47. stub_gitlab_rb(gitlab_workhorse: { prometheus_listen_addr: ':9100'})
  48. end
  49. it 'correctly renders out the workhorse service file' do
  50. expect(chef_run).to render_file("/opt/gitlab/sv/gitlab-workhorse/run").with_content(/\-prometheusListenAddr :9100 \\/)
  51. end
  52. end
  53. context 'without api ci long polling duration defined' do
  54. it 'correctly renders out the workhorse service file' do
  55. expect(chef_run).not_to render_file("/opt/gitlab/sv/gitlab-workhorse/run").with_content(/\-apiCiLongPollingDuration/)
  56. end
  57. end
  58. context 'with api ci long polling duration defined' do
  59. before do
  60. stub_gitlab_rb(gitlab_workhorse: { api_ci_long_polling_duration: "60s" })
  61. end
  62. it 'correctly renders out the workhorse service file' do
  63. expect(chef_run).to render_file("/opt/gitlab/sv/gitlab-workhorse/run").with_content(/\-apiCiLongPollingDuration 60s/)
  64. end
  65. end
  66. context 'with default value for working directory' do
  67. it 'should generate config file in the correct directory' do
  68. expect(chef_run).to render_file("/var/opt/gitlab/gitlab-workhorse/config.toml")
  69. end
  70. end
  71. context 'with working directory specified' do
  72. before do
  73. stub_gitlab_rb(gitlab_workhorse: { dir: "/home/random/dir" })
  74. end
  75. it 'should generate config file in the correct directory' do
  76. expect(chef_run).to render_file("/home/random/dir/config.toml")
  77. end
  78. end
  79. context 'with default values for redis' do
  80. it 'should generate config file' do
  81. content_url = 'URL = "unix:/var/opt/gitlab/redis/redis.socket"'
  82. expect(chef_run).to render_file("/var/opt/gitlab/gitlab-workhorse/config.toml").with_content(content_url)
  83. expect(chef_run).not_to render_file("/var/opt/gitlab/gitlab-workhorse/config.toml").with_content(/Sentinel/)
  84. end
  85. it 'should pass config file to workhorse' do
  86. expect(chef_run).to render_file("/opt/gitlab/sv/gitlab-workhorse/run").with_content(/\-config config.toml/)
  87. end
  88. end
  89. context 'with host/port/password values for redis specified and socket disabled' do
  90. before do
  91. stub_gitlab_rb(
  92. gitlab_rails: {
  93. redis_host: "10.0.15.1",
  94. redis_port: "1234",
  95. redis_password: 'examplepassword'
  96. }
  97. )
  98. end
  99. it 'should generate config file with the specified values' do
  100. content_url = 'URL = "tcp://10.0.15.1:1234/"'
  101. content_password = 'Password = "examplepassword"'
  102. content_sentinel = 'Sentinel'
  103. content_sentinel_master = 'SentinelMaster'
  104. expect(chef_run).to render_file("/var/opt/gitlab/gitlab-workhorse/config.toml").with_content(content_url)
  105. expect(chef_run).to render_file("/var/opt/gitlab/gitlab-workhorse/config.toml").with_content(content_password)
  106. expect(chef_run).to_not render_file("/var/opt/gitlab/gitlab-workhorse/config.toml").with_content(content_sentinel)
  107. expect(chef_run).to_not render_file("/var/opt/gitlab/gitlab-workhorse/config.toml").with_content(content_sentinel_master)
  108. end
  109. end
  110. context 'with socket for redis specified' do
  111. before do
  112. stub_gitlab_rb(gitlab_rails: { redis_socket: "/home/random/path.socket", redis_password: 'examplepassword' })
  113. end
  114. it 'should generate config file with the specified values' do
  115. content_url = 'URL = "unix:/home/random/path.socket"'
  116. content_password = 'Password = "examplepassword"'
  117. expect(chef_run).to render_file("/var/opt/gitlab/gitlab-workhorse/config.toml").with_content(content_url)
  118. expect(chef_run).to render_file("/var/opt/gitlab/gitlab-workhorse/config.toml").with_content(content_password)
  119. expect(chef_run).to_not render_file("/var/opt/gitlab/gitlab-workhorse/config.toml").with_content(/Sentinel/)
  120. expect(chef_run).to_not render_file("/var/opt/gitlab/gitlab-workhorse/config.toml").with_content(/SentinelMaster/)
  121. end
  122. end
  123. context 'with Sentinels specified with default master' do
  124. before do
  125. stub_gitlab_rb(
  126. gitlab_rails: {
  127. redis_sentinels: [
  128. {'host' => '127.0.0.1', 'port' => 2637},
  129. {'host' => '127.0.8.1', 'port' => 1234}
  130. ]
  131. }
  132. )
  133. end
  134. it 'should generate config file with the specified values' do
  135. content = 'Sentinel = ["tcp://127.0.0.1:2637", "tcp://127.0.8.1:1234"]'
  136. content_url = 'URL ='
  137. content_sentinel_master = 'SentinelMaster = "gitlab-redis"'
  138. expect(chef_run).to render_file("/var/opt/gitlab/gitlab-workhorse/config.toml").with_content(content)
  139. expect(chef_run).to render_file("/var/opt/gitlab/gitlab-workhorse/config.toml").with_content(content_sentinel_master)
  140. expect(chef_run).not_to render_file("/var/opt/gitlab/gitlab-workhorse/config.toml").with_content(content_url)
  141. end
  142. end
  143. context 'with Sentinels and master specified' do
  144. before do
  145. stub_gitlab_rb(
  146. gitlab_rails: {
  147. redis_sentinels: [
  148. {'host' => '127.0.0.1', 'port' => 26379},
  149. {'host' => '127.0.8.1', 'port' => 12345}
  150. ]
  151. },
  152. redis: {
  153. master_name: 'examplemaster',
  154. master_password: 'examplepassword'
  155. }
  156. )
  157. end
  158. it 'should generate config file with the specified values' do
  159. content = 'Sentinel = ["tcp://127.0.0.1:26379", "tcp://127.0.8.1:12345"]'
  160. content_sentinel_master = 'SentinelMaster = "examplemaster"'
  161. content_sentinel_password = 'Password = "examplepassword"'
  162. content_url = 'URL ='
  163. expect(chef_run).to render_file("/var/opt/gitlab/gitlab-workhorse/config.toml").with_content(content)
  164. expect(chef_run).to render_file("/var/opt/gitlab/gitlab-workhorse/config.toml").with_content(content_sentinel_master)
  165. expect(chef_run).to render_file("/var/opt/gitlab/gitlab-workhorse/config.toml").with_content(content_sentinel_password)
  166. expect(chef_run).not_to render_file("/var/opt/gitlab/gitlab-workhorse/config.toml").with_content(content_url)
  167. end
  168. end
  169. end