2017-08-24 11:01:33 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-09-04 13:44:46 +00:00
|
|
|
describe ProjectAutoDevops do
|
2017-09-06 19:00:34 +00:00
|
|
|
set(:project) { build(:project) }
|
2017-08-24 11:01:33 +00:00
|
|
|
|
|
|
|
it { is_expected.to belong_to(:project) }
|
|
|
|
|
2018-06-01 21:39:24 +00:00
|
|
|
it { is_expected.to define_enum_for(:deploy_strategy) }
|
|
|
|
|
2017-08-24 11:01:33 +00:00
|
|
|
it { is_expected.to respond_to(:created_at) }
|
|
|
|
it { is_expected.to respond_to(:updated_at) }
|
|
|
|
|
2017-09-16 13:02:37 +00:00
|
|
|
describe '#has_domain?' do
|
2017-09-19 13:56:44 +00:00
|
|
|
context 'when domain is defined' do
|
|
|
|
let(:auto_devops) { build_stubbed(:project_auto_devops, project: project, domain: 'domain.com') }
|
|
|
|
|
|
|
|
it { expect(auto_devops).to have_domain }
|
|
|
|
end
|
2017-09-16 13:02:37 +00:00
|
|
|
|
2017-09-19 13:56:44 +00:00
|
|
|
context 'when domain is empty' do
|
|
|
|
let(:auto_devops) { build_stubbed(:project_auto_devops, project: project, domain: '') }
|
|
|
|
|
2018-02-01 22:59:14 +00:00
|
|
|
context 'when there is an instance domain specified' do
|
|
|
|
before do
|
2018-02-03 00:56:11 +00:00
|
|
|
allow(Gitlab::CurrentSettings).to receive(:auto_devops_domain).and_return('example.com')
|
2018-02-01 22:59:14 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(auto_devops).to have_domain }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there is no instance domain specified' do
|
|
|
|
before do
|
2018-02-03 00:56:11 +00:00
|
|
|
allow(Gitlab::CurrentSettings).to receive(:auto_devops_domain).and_return(nil)
|
2018-02-01 22:59:14 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(auto_devops).not_to have_domain }
|
|
|
|
end
|
2017-09-19 13:56:44 +00:00
|
|
|
end
|
2017-09-16 13:02:37 +00:00
|
|
|
end
|
|
|
|
|
2018-03-13 13:00:14 +00:00
|
|
|
describe '#predefined_variables' do
|
2017-09-06 19:00:34 +00:00
|
|
|
let(:auto_devops) { build_stubbed(:project_auto_devops, project: project, domain: domain) }
|
|
|
|
|
|
|
|
context 'when domain is defined' do
|
|
|
|
let(:domain) { 'example.com' }
|
|
|
|
|
|
|
|
it 'returns AUTO_DEVOPS_DOMAIN' do
|
2018-03-13 13:00:14 +00:00
|
|
|
expect(auto_devops.predefined_variables).to include(domain_variable)
|
2017-09-06 19:00:34 +00:00
|
|
|
end
|
|
|
|
end
|
2018-02-01 22:59:14 +00:00
|
|
|
|
|
|
|
context 'when domain is not defined' do
|
|
|
|
let(:domain) { nil }
|
|
|
|
|
|
|
|
context 'when there is an instance domain specified' do
|
|
|
|
before do
|
2018-02-03 00:56:11 +00:00
|
|
|
allow(Gitlab::CurrentSettings).to receive(:auto_devops_domain).and_return('example.com')
|
2018-02-01 22:59:14 +00:00
|
|
|
end
|
|
|
|
|
2018-03-13 13:00:14 +00:00
|
|
|
it { expect(auto_devops.predefined_variables).to include(domain_variable) }
|
2018-02-01 22:59:14 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there is no instance domain specified' do
|
|
|
|
before do
|
2018-02-03 00:56:11 +00:00
|
|
|
allow(Gitlab::CurrentSettings).to receive(:auto_devops_domain).and_return(nil)
|
2018-02-01 22:59:14 +00:00
|
|
|
end
|
|
|
|
|
2018-03-13 13:00:14 +00:00
|
|
|
it { expect(auto_devops.predefined_variables).not_to include(domain_variable) }
|
2018-02-01 22:59:14 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-06-06 17:09:46 +00:00
|
|
|
context 'when deploy_strategy is manual' do
|
2018-06-01 21:47:38 +00:00
|
|
|
let(:domain) { 'example.com' }
|
|
|
|
|
|
|
|
before do
|
2018-06-06 17:09:46 +00:00
|
|
|
auto_devops.deploy_strategy = 'manual'
|
2018-06-01 21:47:38 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it do
|
|
|
|
expect(auto_devops.predefined_variables.map { |var| var[:key] })
|
|
|
|
.to include("STAGING_ENABLED", "INCREMENTAL_ROLLOUT_ENABLED")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-06-07 12:58:09 +00:00
|
|
|
context 'when deploy_strategy is continuous' do
|
|
|
|
let(:domain) { 'example.com' }
|
|
|
|
|
|
|
|
before do
|
|
|
|
auto_devops.deploy_strategy = 'continuous'
|
|
|
|
end
|
|
|
|
|
|
|
|
it do
|
|
|
|
expect(auto_devops.predefined_variables.map { |var| var[:key] })
|
|
|
|
.not_to include("STAGING_ENABLED", "INCREMENTAL_ROLLOUT_ENABLED")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-02-01 22:59:14 +00:00
|
|
|
def domain_variable
|
|
|
|
{ key: 'AUTO_DEVOPS_DOMAIN', value: 'example.com', public: true }
|
|
|
|
end
|
2017-09-06 19:00:34 +00:00
|
|
|
end
|
2018-06-07 18:09:14 +00:00
|
|
|
|
|
|
|
describe '#set_gitlab_deploy_token' do
|
|
|
|
let(:auto_devops) { build(:project_auto_devops, project: project) }
|
|
|
|
|
|
|
|
context 'when the project is public' do
|
|
|
|
let(:project) { create(:project, :repository, :public) }
|
|
|
|
|
|
|
|
it 'should not create a gitlab deploy token' do
|
|
|
|
expect do
|
|
|
|
auto_devops.save
|
|
|
|
end.not_to change { DeployToken.count }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the project is internal' do
|
|
|
|
let(:project) { create(:project, :repository, :internal) }
|
|
|
|
|
|
|
|
it 'should create a gitlab deploy token' do
|
|
|
|
expect do
|
|
|
|
auto_devops.save
|
|
|
|
end.to change { DeployToken.count }.by(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the project is private' do
|
|
|
|
let(:project) { create(:project, :repository, :private) }
|
|
|
|
|
|
|
|
it 'should create a gitlab deploy token' do
|
|
|
|
expect do
|
|
|
|
auto_devops.save
|
|
|
|
end.to change { DeployToken.count }.by(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when autodevops is enabled at project level' do
|
|
|
|
let(:project) { create(:project, :repository, :internal) }
|
|
|
|
let(:auto_devops) { build(:project_auto_devops, project: project) }
|
|
|
|
|
|
|
|
it 'should create a deploy token' do
|
|
|
|
expect do
|
|
|
|
auto_devops.save
|
|
|
|
end.to change { DeployToken.count }.by(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when autodevops is enabled at instancel level' do
|
|
|
|
let(:project) { create(:project, :repository, :internal) }
|
|
|
|
let(:auto_devops) { build(:project_auto_devops, :disabled, project: project) }
|
|
|
|
|
|
|
|
it 'should create a deploy token' do
|
|
|
|
allow(Gitlab::CurrentSettings).to receive(:auto_devops_enabled?).and_return(true)
|
|
|
|
|
|
|
|
expect do
|
|
|
|
auto_devops.save
|
|
|
|
end.to change { DeployToken.count }.by(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when autodevops is disabled' do
|
|
|
|
let(:project) { create(:project, :repository, :internal) }
|
|
|
|
let(:auto_devops) { build(:project_auto_devops, :disabled, project: project) }
|
|
|
|
|
|
|
|
it 'should not create a deploy token' do
|
|
|
|
expect do
|
|
|
|
auto_devops.save
|
|
|
|
end.not_to change { DeployToken.count }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the project already has an active gitlab-deploy-token' do
|
|
|
|
let(:project) { create(:project, :repository, :internal) }
|
|
|
|
let!(:deploy_token) { create(:deploy_token, :gitlab_deploy_token, projects: [project]) }
|
|
|
|
let(:auto_devops) { build(:project_auto_devops, project: project) }
|
|
|
|
|
|
|
|
it 'should not create a deploy token' do
|
|
|
|
expect do
|
|
|
|
auto_devops.save
|
|
|
|
end.not_to change { DeployToken.count }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the project already has a revoked gitlab-deploy-token' do
|
|
|
|
let(:project) { create(:project, :repository, :internal) }
|
|
|
|
let!(:deploy_token) { create(:deploy_token, :gitlab_deploy_token, :expired, projects: [project]) }
|
|
|
|
let(:auto_devops) { build(:project_auto_devops, project: project) }
|
|
|
|
|
|
|
|
it 'should not create a deploy token' do
|
|
|
|
expect do
|
|
|
|
auto_devops.save
|
|
|
|
end.not_to change { DeployToken.count }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-08-24 11:01:33 +00:00
|
|
|
end
|