debian-mirror-gitlab/spec/lib/gitlab/ci/pipeline/seed/deployment_spec.rb

87 lines
2.5 KiB
Ruby
Raw Normal View History

2019-12-21 20:55:43 +05:30
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::Ci::Pipeline::Seed::Deployment do
2020-03-09 13:42:32 +05:30
let_it_be(:project) { create(:project, :repository) }
let(:pipeline) do
create(:ci_pipeline, project: project,
sha: 'b83d6e391c22777fca1ed3012fce84f633d7fed0')
end
let(:job) { build(:ci_build, project: project, pipeline: pipeline) }
2019-12-21 20:55:43 +05:30
let(:seed) { described_class.new(job) }
let(:attributes) { {} }
before do
job.assign_attributes(**attributes)
end
describe '#to_resource' do
subject { seed.to_resource }
context 'when job has environment attribute' do
let(:attributes) do
{
environment: 'production',
options: { environment: { name: 'production' } }
}
end
it 'returns a deployment object with environment' do
expect(subject).to be_a(Deployment)
expect(subject.iid).to be_present
expect(subject.environment.name).to eq('production')
expect(subject.cluster).to be_nil
2020-03-09 13:42:32 +05:30
expect(subject.deployment_cluster).to be_nil
2019-12-21 20:55:43 +05:30
end
context 'when environment has deployment platform' do
let!(:cluster) { create(:cluster, :provided_by_gcp, projects: [project]) }
2020-03-09 13:42:32 +05:30
it 'sets the cluster and deployment_cluster' do
expect(subject.cluster).to eq(cluster) # until we stop double writing in 12.9: https://gitlab.com/gitlab-org/gitlab/issues/202628
expect(subject.deployment_cluster).to have_attributes(
cluster_id: cluster.id,
kubernetes_namespace: subject.environment.deployment_namespace
)
2019-12-21 20:55:43 +05:30
end
end
context 'when environment has an invalid URL' do
let(:attributes) do
{
environment: '!!!',
options: { environment: { name: '!!!' } }
}
end
it 'returns nothing' do
is_expected.to be_nil
end
end
context 'when job has already deployment' do
let(:job) { build(:ci_build, :with_deployment, project: project, environment: 'production') }
it 'returns the persisted deployment' do
is_expected.to eq(job.deployment)
end
end
end
context 'when job has environment attribute with stop action' do
let(:attributes) do
{
environment: 'production',
options: { environment: { name: 'production', action: 'stop' } }
}
end
it 'returns nothing' do
is_expected.to be_nil
end
end
end
end