|
| 1 | +require 'spec_helper' |
| 2 | +require 'gitlab/build/info/components' |
| 3 | + |
| 4 | +RSpec.describe Build::Info::Components::GitLabRails do |
| 5 | + before do |
| 6 | + stub_default_package_version |
| 7 | + stub_env_var('GITLAB_ALTERNATIVE_REPO', nil) |
| 8 | + stub_env_var('ALTERNATIVE_PRIVATE_TOKEN', nil) |
| 9 | + end |
| 10 | + |
| 11 | + describe '.version' do |
| 12 | + describe 'GITLAB_VERSION variable specified' do |
| 13 | + it 'returns passed value' do |
| 14 | + allow(ENV).to receive(:[]).with("GITLAB_VERSION").and_return("9.0.0") |
| 15 | + expect(described_class.version).to eq('9.0.0') |
| 16 | + end |
| 17 | + end |
| 18 | + |
| 19 | + describe 'GITLAB_VERSION variable not specified' do |
| 20 | + it 'returns content of VERSION' do |
| 21 | + allow(File).to receive(:read).with("VERSION").and_return("8.5.6") |
| 22 | + expect(described_class.version).to eq('8.5.6') |
| 23 | + end |
| 24 | + end |
| 25 | + end |
| 26 | + |
| 27 | + describe '.ref' do |
| 28 | + context 'with prepend_version true' do |
| 29 | + context 'when on tags and stable branches' do |
| 30 | + # On stable branches and tags, generate-facts will not populate version facts |
| 31 | + # So, the content of the VERSION file will be used as-is. |
| 32 | + it 'returns tag with v prefix' do |
| 33 | + allow(File).to receive(:exist?).with(/gitlab-rails_version/).and_return(false) |
| 34 | + allow(File).to receive(:read).with(/VERSION/).and_return('15.7.0') |
| 35 | + expect(described_class.ref).to eq('v15.7.0') |
| 36 | + end |
| 37 | + end |
| 38 | + |
| 39 | + context 'when on feature branches' do |
| 40 | + it 'returns commit SHA without any prefix' do |
| 41 | + allow(File).to receive(:exist?).with(/gitlab-rails_version/).and_return(true) |
| 42 | + allow(File).to receive(:read).with(/gitlab-rails_version/).and_return('arandomcommit') |
| 43 | + expect(described_class.ref).to eq('arandomcommit') |
| 44 | + end |
| 45 | + end |
| 46 | + end |
| 47 | + |
| 48 | + context 'with prepend_version false' do |
| 49 | + context 'when on tags and stable branches' do |
| 50 | + # On stable branches and tags, generate-facts will not populate version facts |
| 51 | + # So, whatever is on VERSION file, will be used. |
| 52 | + it 'returns tag without v prefix' do |
| 53 | + allow(File).to receive(:exist?).with(/gitlab-rails_version/).and_return(false) |
| 54 | + allow(File).to receive(:read).with(/VERSION/).and_return('15.7.0') |
| 55 | + expect(described_class.ref(prepend_version: false)).to eq('15.7.0') |
| 56 | + end |
| 57 | + end |
| 58 | + |
| 59 | + context 'when on feature branches' do |
| 60 | + it 'returns commit SHA without any prefix' do |
| 61 | + allow(File).to receive(:exist?).with(/gitlab-rails_version/).and_return(true) |
| 62 | + allow(File).to receive(:read).with(/gitlab-rails_version/).and_return('arandomcommit') |
| 63 | + expect(described_class.ref(prepend_version: false)).to eq('arandomcommit') |
| 64 | + end |
| 65 | + end |
| 66 | + end |
| 67 | + end |
| 68 | + |
| 69 | + describe '.repo' do |
| 70 | + context 'when alternative sources channel selected' do |
| 71 | + before do |
| 72 | + allow(::Gitlab::Version).to receive(:sources_channel).and_return('alternative') |
| 73 | + end |
| 74 | + |
| 75 | + it 'returns public mirror for GitLab CE' do |
| 76 | + allow(Build::Info::Package).to receive(:name).and_return("gitlab-ce") |
| 77 | + expect(described_class.repo).to eq("https://gitlab.com/gitlab-org/gitlab-foss.git") |
| 78 | + end |
| 79 | + |
| 80 | + it 'returns public mirror for GitLab EE' do |
| 81 | + allow(Build::Info::Package).to receive(:name).and_return("gitlab-ee") |
| 82 | + expect(described_class.repo).to eq("https://gitlab.com/gitlab-org/gitlab.git") |
| 83 | + end |
| 84 | + end |
| 85 | + |
| 86 | + context 'when default sources channel' do |
| 87 | + before do |
| 88 | + allow(::Gitlab::Version).to receive(:sources_channel).and_return('remote') |
| 89 | + end |
| 90 | + |
| 91 | + it 'returns dev repo for GitLab CE' do |
| 92 | + allow(Build::Info::Package).to receive(:name).and_return("gitlab-ce") |
| 93 | + expect(described_class.repo).to eq("[email protected]:gitlab/gitlabhq.git") |
| 94 | + end |
| 95 | + |
| 96 | + it 'returns dev repo for GitLab EE' do |
| 97 | + allow(Build::Info::Package).to receive(:name).and_return("gitlab-ee") |
| 98 | + expect(described_class.repo).to eq("[email protected]:gitlab/gitlab-ee.git") |
| 99 | + end |
| 100 | + end |
| 101 | + |
| 102 | + context 'when security sources channel selected' do |
| 103 | + before do |
| 104 | + allow(::Gitlab::Version).to receive(:sources_channel).and_return('security') |
| 105 | + stub_env_var('CI_JOB_TOKEN', 'CJT') |
| 106 | + end |
| 107 | + |
| 108 | + it 'returns security mirror for GitLab CE with attached credential' do |
| 109 | + allow(Build::Info::Package).to receive(:name).and_return("gitlab-ce") |
| 110 | + expect(described_class.repo).to eq("https://gitlab-ci-token:[email protected]/gitlab-org/security/gitlab-foss.git") |
| 111 | + end |
| 112 | + it 'returns security mirror for GitLab EE with attached credential' do |
| 113 | + allow(Build::Info::Package).to receive(:name).and_return("gitlab-ee") |
| 114 | + expect(described_class.repo).to eq("https://gitlab-ci-token:[email protected]/gitlab-org/security/gitlab.git") |
| 115 | + end |
| 116 | + end |
| 117 | + end |
| 118 | + |
| 119 | + describe '.project_path' do |
| 120 | + context 'when building CE' do |
| 121 | + before do |
| 122 | + stub_is_ee(false) |
| 123 | + end |
| 124 | + |
| 125 | + context 'when on the build mirror' do |
| 126 | + before do |
| 127 | + stub_env_var('CI_SERVER_HOST', 'dev.gitlab.org') |
| 128 | + stub_env_var('SECURITY_SOURCES', '') |
| 129 | + end |
| 130 | + |
| 131 | + it 'returns correct path for GitLab rails project' do |
| 132 | + expect(described_class.project_path).to eq("gitlab/gitlabhq") |
| 133 | + end |
| 134 | + end |
| 135 | + |
| 136 | + context 'when on running on the canonical project or QA mirror' do |
| 137 | + before do |
| 138 | + stub_env_var('CI_SERVER_HOST', 'gitlab.com') |
| 139 | + stub_env_var('SECURITY_SOURCES', '') |
| 140 | + end |
| 141 | + |
| 142 | + it 'returns correct path for GitLab rails project' do |
| 143 | + expect(described_class.project_path).to eq("gitlab-org/gitlab-foss") |
| 144 | + end |
| 145 | + end |
| 146 | + |
| 147 | + context 'when running on the security mirror' do |
| 148 | + before do |
| 149 | + stub_env_var('CI_SERVER_HOST', 'gitlab.com') |
| 150 | + stub_env_var('SECURITY_SOURCES', 'true') |
| 151 | + end |
| 152 | + |
| 153 | + it 'returns correct path for GitLab rails project' do |
| 154 | + expect(described_class.project_path).to eq("gitlab-org/security/gitlab-foss") |
| 155 | + end |
| 156 | + end |
| 157 | + end |
| 158 | + |
| 159 | + context 'when building EE' do |
| 160 | + before do |
| 161 | + stub_is_ee(true) |
| 162 | + end |
| 163 | + |
| 164 | + context 'when running on the build mirror' do |
| 165 | + before do |
| 166 | + stub_env_var('CI_SERVER_HOST', 'dev.gitlab.org') |
| 167 | + stub_env_var('SECURITY_SOURCES', '') |
| 168 | + end |
| 169 | + |
| 170 | + it 'returns correct path for GitLab rails project' do |
| 171 | + expect(described_class.project_path).to eq("gitlab/gitlab-ee") |
| 172 | + end |
| 173 | + end |
| 174 | + |
| 175 | + context 'when running on the canonical project or QA mirror' do |
| 176 | + before do |
| 177 | + stub_env_var('CI_SERVER_HOST', 'gitlab.com') |
| 178 | + stub_env_var('SECURITY_SOURCES', '') |
| 179 | + end |
| 180 | + |
| 181 | + it 'returns correct path for GitLab rails project' do |
| 182 | + expect(described_class.project_path).to eq("gitlab-org/gitlab") |
| 183 | + end |
| 184 | + end |
| 185 | + |
| 186 | + context 'when running on the security mirror' do |
| 187 | + before do |
| 188 | + stub_env_var('CI_SERVER_HOST', 'gitlab.com') |
| 189 | + stub_env_var('SECURITY_SOURCES', 'true') |
| 190 | + end |
| 191 | + |
| 192 | + it 'returns correct path for GitLab rails project' do |
| 193 | + expect(described_class.project_path).to eq("gitlab-org/security/gitlab") |
| 194 | + end |
| 195 | + end |
| 196 | + end |
| 197 | + end |
| 198 | +end |
0 commit comments