|
| 1 | +require 'spec_helper' |
| 2 | + |
| 3 | +RSpec.describe 'gitlab_com', type: :rake do |
| 4 | + before(:all) do |
| 5 | + Rake.application.rake_require 'gitlab/tasks/gitlab_com' |
| 6 | + end |
| 7 | + |
| 8 | + describe 'gitlab_com:deployer' do |
| 9 | + before do |
| 10 | + Rake::Task['gitlab_com:deployer'].reenable |
| 11 | + |
| 12 | + allow(ENV).to receive(:[]).and_call_original |
| 13 | + stub_env_var('PATCH_DEPLOY_ENVIRONMENT', 'patch-environment') |
| 14 | + stub_env_var('RELEASE_DEPLOY_ENVIRONMENT', 'release-environment') |
| 15 | + allow(DeployerHelper).to receive(:new).and_return(double(trigger_deploy: 'dummy-url')) |
| 16 | + end |
| 17 | + |
| 18 | + context 'when DEPLOYER_TRIGGER_TOKEN is not set' do |
| 19 | + before do |
| 20 | + stub_env_var('DEPLOYER_TRIGGER_TOKEN', nil) |
| 21 | + end |
| 22 | + |
| 23 | + it 'prints warning' do |
| 24 | + expect { Rake::Task['gitlab_com:deployer'].invoke }.to raise_error(SystemExit, "This task requires DEPLOYER_TRIGGER_TOKEN to be set") |
| 25 | + end |
| 26 | + end |
| 27 | + |
| 28 | + context 'when DEPLOYER_TRIGGER_TOKEN is set' do |
| 29 | + before do |
| 30 | + stub_env_var('DEPLOYER_TRIGGER_TOKEN', 'dummy-token') |
| 31 | + end |
| 32 | + |
| 33 | + context 'when building Community Edition (CE)' do |
| 34 | + before do |
| 35 | + stub_is_ee(false) |
| 36 | + end |
| 37 | + |
| 38 | + it 'prints warning' do |
| 39 | + expect { Rake::Task['gitlab_com:deployer'].invoke }.to output(/gitlab-ce is not an ee package, not doing anything./).to_stdout |
| 40 | + end |
| 41 | + end |
| 42 | + |
| 43 | + context 'when building Enterprise Edition (EE)' do |
| 44 | + before do |
| 45 | + stub_is_ee(true) |
| 46 | + end |
| 47 | + |
| 48 | + context 'with the auto-deploy tag' do |
| 49 | + before do |
| 50 | + allow(OhaiHelper).to receive(:fetch_os_with_codename).and_return(%w[ubuntu bionic]) |
| 51 | + allow(Build::Check).to receive(:is_auto_deploy?).and_return(true) |
| 52 | + end |
| 53 | + |
| 54 | + it 'shows a warning' do |
| 55 | + expect { Rake::Task['gitlab_com:deployer'].invoke }.to output(/Auto-deploys are handled in release-tools, exiting.../).to_stdout |
| 56 | + end |
| 57 | + end |
| 58 | + |
| 59 | + context 'when running on Ubuntu 18.04' do |
| 60 | + before do |
| 61 | + allow(OhaiHelper).to receive(:fetch_os_with_codename).and_return(%w[ubuntu bionic]) |
| 62 | + end |
| 63 | + |
| 64 | + context 'with a release candidate (RC) tag' do |
| 65 | + before do |
| 66 | + allow(Build::Check).to receive(:is_rc_tag?).and_return(true) |
| 67 | + end |
| 68 | + |
| 69 | + it 'triggers deployment to specified environment' do |
| 70 | + expect(DeployerHelper).to receive(:new).with('dummy-token', 'patch-environment', :master) |
| 71 | + |
| 72 | + Rake::Task['gitlab_com:deployer'].invoke |
| 73 | + end |
| 74 | + end |
| 75 | + |
| 76 | + context 'with a stable tag' do |
| 77 | + before do |
| 78 | + allow(Build::Check).to receive(:is_rc_tag?).and_return(false) |
| 79 | + allow(Build::Check).to receive(:is_latest_stable_tag?).and_return(true) |
| 80 | + end |
| 81 | + |
| 82 | + it 'does not trigger deployment' do |
| 83 | + expect(DeployerHelper).not_to receive(:new) |
| 84 | + |
| 85 | + Rake::Task['gitlab_com:deployer'].invoke |
| 86 | + end |
| 87 | + end |
| 88 | + end |
| 89 | + |
| 90 | + context 'when running on Ubuntu 20.04' do |
| 91 | + before do |
| 92 | + allow(OhaiHelper).to receive(:fetch_os_with_codename).and_return(%w[ubuntu focal]) |
| 93 | + end |
| 94 | + |
| 95 | + context 'with a release candidate (RC) tag' do |
| 96 | + before do |
| 97 | + allow(Build::Check).to receive(:is_rc_tag?).and_return(true) |
| 98 | + end |
| 99 | + |
| 100 | + it 'does not trigger deployment' do |
| 101 | + expect(DeployerHelper).not_to receive(:new) |
| 102 | + |
| 103 | + Rake::Task['gitlab_com:deployer'].invoke |
| 104 | + end |
| 105 | + end |
| 106 | + |
| 107 | + context 'with a stable tag' do |
| 108 | + before do |
| 109 | + allow(Build::Check).to receive(:is_rc_tag?).and_return(false) |
| 110 | + allow(Build::Check).to receive(:is_latest_stable_tag?).and_return(true) |
| 111 | + end |
| 112 | + |
| 113 | + it 'triggers deployment to specified environment' do |
| 114 | + expect(DeployerHelper).to receive(:new).with('dummy-token', 'release-environment', :master) |
| 115 | + |
| 116 | + Rake::Task['gitlab_com:deployer'].invoke |
| 117 | + end |
| 118 | + end |
| 119 | + end |
| 120 | + |
| 121 | + context 'running on any other operating system' do |
| 122 | + before do |
| 123 | + allow(OhaiHelper).to receive(:fetch_os_with_codename).and_return(%w[debian buster]) |
| 124 | + end |
| 125 | + |
| 126 | + context 'with a release candidate (RC) tag' do |
| 127 | + before do |
| 128 | + allow(Build::Check).to receive(:is_rc_tag?).and_return(true) |
| 129 | + end |
| 130 | + |
| 131 | + it 'does not trigger deployment' do |
| 132 | + expect(DeployerHelper).not_to receive(:new) |
| 133 | + |
| 134 | + Rake::Task['gitlab_com:deployer'].invoke |
| 135 | + end |
| 136 | + end |
| 137 | + |
| 138 | + context 'with a stable tag' do |
| 139 | + before do |
| 140 | + allow(Build::Check).to receive(:is_rc_tag?).and_return(false) |
| 141 | + allow(Build::Check).to receive(:is_latest_stable_tag?).and_return(true) |
| 142 | + end |
| 143 | + |
| 144 | + it 'does not trigger deployment' do |
| 145 | + expect(DeployerHelper).not_to receive(:new) |
| 146 | + |
| 147 | + Rake::Task['gitlab_com:deployer'].invoke |
| 148 | + end |
| 149 | + end |
| 150 | + end |
| 151 | + end |
| 152 | + end |
| 153 | + end |
| 154 | +end |
0 commit comments