2019-03-30 03:23:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-24 07:01:33 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-09-04 09:44:46 -04:00
|
|
|
describe ProjectAutoDevops do
|
2017-09-06 15:00:34 -04:00
|
|
|
set(:project) { build(:project) }
|
2017-08-24 07:01:33 -04:00
|
|
|
|
2018-12-04 05:24:21 -05:00
|
|
|
it_behaves_like 'having unique enum values'
|
|
|
|
|
2017-08-24 07:01:33 -04:00
|
|
|
it { is_expected.to belong_to(:project) }
|
|
|
|
|
2018-06-01 17:39:24 -04:00
|
|
|
it { is_expected.to define_enum_for(:deploy_strategy) }
|
|
|
|
|
2017-08-24 07:01:33 -04:00
|
|
|
it { is_expected.to respond_to(:created_at) }
|
|
|
|
it { is_expected.to respond_to(:updated_at) }
|
|
|
|
|
2018-03-13 09:00:14 -04:00
|
|
|
describe '#predefined_variables' do
|
2019-07-22 01:44:28 -04:00
|
|
|
let(:auto_devops) { build_stubbed(:project_auto_devops, project: project) }
|
2017-09-06 15:00:34 -04:00
|
|
|
|
2018-06-06 13:09:46 -04:00
|
|
|
context 'when deploy_strategy is manual' do
|
2018-10-01 09:03:48 -04:00
|
|
|
let(:auto_devops) { build_stubbed(:project_auto_devops, :manual_deployment, project: project) }
|
|
|
|
let(:expected_variables) do
|
|
|
|
[
|
|
|
|
{ key: 'INCREMENTAL_ROLLOUT_MODE', value: 'manual' },
|
|
|
|
{ key: 'STAGING_ENABLED', value: '1' },
|
|
|
|
{ key: 'INCREMENTAL_ROLLOUT_ENABLED', value: '1' }
|
|
|
|
]
|
2018-06-01 17:47:38 -04:00
|
|
|
end
|
|
|
|
|
2018-10-01 09:03:48 -04:00
|
|
|
it { expect(auto_devops.predefined_variables).to include(*expected_variables) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when deploy_strategy is continuous' do
|
|
|
|
let(:auto_devops) { build_stubbed(:project_auto_devops, :continuous_deployment, project: project) }
|
|
|
|
|
2018-06-01 17:47:38 -04:00
|
|
|
it do
|
|
|
|
expect(auto_devops.predefined_variables.map { |var| var[:key] })
|
2018-10-01 09:03:48 -04:00
|
|
|
.not_to include("STAGING_ENABLED", "INCREMENTAL_ROLLOUT_ENABLED")
|
2018-06-01 17:47:38 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-10-01 09:03:48 -04:00
|
|
|
context 'when deploy_strategy is timed_incremental' do
|
|
|
|
let(:auto_devops) { build_stubbed(:project_auto_devops, :timed_incremental_deployment, project: project) }
|
2018-06-07 08:58:09 -04:00
|
|
|
|
2018-10-01 09:03:48 -04:00
|
|
|
it { expect(auto_devops.predefined_variables).to include(key: 'INCREMENTAL_ROLLOUT_MODE', value: 'timed') }
|
2018-06-07 08:58:09 -04:00
|
|
|
|
|
|
|
it do
|
|
|
|
expect(auto_devops.predefined_variables.map { |var| var[:key] })
|
|
|
|
.not_to include("STAGING_ENABLED", "INCREMENTAL_ROLLOUT_ENABLED")
|
|
|
|
end
|
|
|
|
end
|
2017-09-06 15:00:34 -04:00
|
|
|
end
|
2018-06-07 14:09:14 -04:00
|
|
|
|
2018-08-16 09:24:25 -04:00
|
|
|
describe '#create_gitlab_deploy_token' do
|
2018-06-07 14:09:14 -04:00
|
|
|
let(:auto_devops) { build(:project_auto_devops, project: project) }
|
|
|
|
|
|
|
|
context 'when the project is public' do
|
|
|
|
let(:project) { create(:project, :repository, :public) }
|
|
|
|
|
2019-04-05 04:43:27 -04:00
|
|
|
it 'does not create a gitlab deploy token' do
|
2018-06-07 14:09:14 -04:00
|
|
|
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) }
|
|
|
|
|
2019-04-05 04:43:27 -04:00
|
|
|
it 'creates a gitlab deploy token' do
|
2018-06-07 14:09:14 -04:00
|
|
|
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) }
|
|
|
|
|
2019-04-05 04:43:27 -04:00
|
|
|
it 'creates a gitlab deploy token' do
|
2018-06-07 14:09:14 -04:00
|
|
|
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) }
|
|
|
|
|
2019-04-05 04:43:27 -04:00
|
|
|
it 'creates a deploy token' do
|
2018-06-07 14:09:14 -04:00
|
|
|
expect do
|
|
|
|
auto_devops.save
|
|
|
|
end.to change { DeployToken.count }.by(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-08-16 09:24:25 -04:00
|
|
|
context 'when autodevops is enabled at instance level' do
|
2018-06-07 14:09:14 -04:00
|
|
|
let(:project) { create(:project, :repository, :internal) }
|
2018-08-16 09:24:25 -04:00
|
|
|
let(:auto_devops) { build(:project_auto_devops, enabled: nil, project: project) }
|
2018-06-07 14:09:14 -04:00
|
|
|
|
2019-04-05 04:43:27 -04:00
|
|
|
it 'creates a deploy token' do
|
2018-06-07 14:09:14 -04:00
|
|
|
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) }
|
|
|
|
|
2019-04-05 04:43:27 -04:00
|
|
|
it 'does not create a deploy token' do
|
2018-06-07 14:09:14 -04:00
|
|
|
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) }
|
|
|
|
|
2019-04-05 04:43:27 -04:00
|
|
|
it 'does not create a deploy token' do
|
2018-06-07 14:09:14 -04:00
|
|
|
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) }
|
|
|
|
|
2019-04-05 04:43:27 -04:00
|
|
|
it 'does not create a deploy token' do
|
2018-06-07 14:09:14 -04:00
|
|
|
expect do
|
|
|
|
auto_devops.save
|
|
|
|
end.not_to change { DeployToken.count }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-08-24 07:01:33 -04:00
|
|
|
end
|