diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-19 18:07:55 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-19 18:07:55 +0300 |
commit | f92a53a216e6e7d5037ac701efbee5628f91aa9a (patch) | |
tree | 1eb957f0277b50002258681f61db869a2b683fec /spec | |
parent | e3764d340e2849fccee8c06278d1f5f686edd35b (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/factories/ci/builds.rb | 8 | ||||
-rw-r--r-- | spec/factories/ci/resource.rb | 11 | ||||
-rw-r--r-- | spec/factories/ci/resource_group.rb | 8 | ||||
-rw-r--r-- | spec/features/merge_request/user_suggests_changes_on_diff_spec.rb | 3 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/pipeline/seed/build/resource_group_spec.rb | 46 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/pipeline/seed/build_spec.rb | 9 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/yaml_processor_spec.rb | 15 | ||||
-rw-r--r-- | spec/lib/gitlab/import_export/all_models.yml | 1 | ||||
-rw-r--r-- | spec/models/ci/resource_group_spec.rb | 88 | ||||
-rw-r--r-- | spec/models/ci/resource_spec.rb | 28 | ||||
-rw-r--r-- | spec/models/concerns/safe_url_spec.rb | 4 | ||||
-rw-r--r-- | spec/services/ci/create_pipeline_service_spec.rb | 38 | ||||
-rw-r--r-- | spec/services/ci/retry_build_service_spec.rb | 6 | ||||
-rw-r--r-- | spec/validators/qualified_domain_array_validator_spec.rb | 4 |
14 files changed, 261 insertions, 8 deletions
diff --git a/spec/factories/ci/builds.rb b/spec/factories/ci/builds.rb index ecb1f1996d9..a38935c89ba 100644 --- a/spec/factories/ci/builds.rb +++ b/spec/factories/ci/builds.rb @@ -207,6 +207,14 @@ FactoryBot.define do trigger_request factory: :ci_trigger_request end + trait :resource_group do + waiting_for_resource_at { 5.minutes.ago } + + after(:build) do |build, evaluator| + build.resource_group = create(:ci_resource_group, project: build.project) + end + end + after(:build) do |build, evaluator| build.project ||= build.pipeline.project end diff --git a/spec/factories/ci/resource.rb b/spec/factories/ci/resource.rb new file mode 100644 index 00000000000..d47b3ba4635 --- /dev/null +++ b/spec/factories/ci/resource.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :ci_resource, class: Ci::Resource do + resource_group factory: :ci_resource_group + + trait(:retained) do + build factory: :ci_build + end + end +end diff --git a/spec/factories/ci/resource_group.rb b/spec/factories/ci/resource_group.rb new file mode 100644 index 00000000000..bdfc0740a45 --- /dev/null +++ b/spec/factories/ci/resource_group.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +FactoryBot.define do + factory :ci_resource_group, class: Ci::ResourceGroup do + project + sequence(:key) { |n| "IOS_#{n}" } + end +end diff --git a/spec/features/merge_request/user_suggests_changes_on_diff_spec.rb b/spec/features/merge_request/user_suggests_changes_on_diff_spec.rb index 859638f1a52..085fe38b47a 100644 --- a/spec/features/merge_request/user_suggests_changes_on_diff_spec.rb +++ b/spec/features/merge_request/user_suggests_changes_on_diff_spec.rb @@ -97,7 +97,8 @@ describe 'User comments on a diff', :js do end context 'multiple suggestions in expanded lines' do - it 'suggestions are appliable' do + # https://gitlab.com/gitlab-org/gitlab/issues/38277 + it 'suggestions are appliable', :quarantine do diff_file = merge_request.diffs(paths: ['files/ruby/popen.rb']).diff_files.first hash = Digest::SHA1.hexdigest(diff_file.file_path) diff --git a/spec/lib/gitlab/ci/pipeline/seed/build/resource_group_spec.rb b/spec/lib/gitlab/ci/pipeline/seed/build/resource_group_spec.rb new file mode 100644 index 00000000000..bf6985156d3 --- /dev/null +++ b/spec/lib/gitlab/ci/pipeline/seed/build/resource_group_spec.rb @@ -0,0 +1,46 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Gitlab::Ci::Pipeline::Seed::Build::ResourceGroup do + let_it_be(:project) { create(:project) } + let(:job) { build(:ci_build, project: project) } + let(:seed) { described_class.new(job, resource_group_key) } + + describe '#to_resource' do + subject { seed.to_resource } + + context 'when resource group key is specified' do + let(:resource_group_key) { 'iOS' } + + it 'returns a resource group object' do + is_expected.to be_a(Ci::ResourceGroup) + expect(subject.key).to eq('iOS') + end + + context 'when environment has an invalid URL' do + let(:resource_group_key) { ':::' } + + it 'returns nothing' do + is_expected.to be_nil + end + end + + context 'when there is a resource group already' do + let!(:resource_group) { create(:ci_resource_group, project: project, key: 'iOS') } + + it 'does not create a new resource group' do + expect { subject }.not_to change { Ci::ResourceGroup.count } + end + end + end + + context 'when resource group key is nil' do + let(:resource_group_key) { nil } + + it 'returns nothing' do + is_expected.to be_nil + end + end + end +end diff --git a/spec/lib/gitlab/ci/pipeline/seed/build_spec.rb b/spec/lib/gitlab/ci/pipeline/seed/build_spec.rb index 2ae513aea1b..5526ec9e16f 100644 --- a/spec/lib/gitlab/ci/pipeline/seed/build_spec.rb +++ b/spec/lib/gitlab/ci/pipeline/seed/build_spec.rb @@ -231,6 +231,15 @@ describe Gitlab::Ci::Pipeline::Seed::Build do end end end + + context 'when job belongs to a resource group' do + let(:attributes) { { name: 'rspec', ref: 'master', resource_group_key: 'iOS' } } + + it 'returns a job with resource group' do + expect(subject.resource_group).not_to be_nil + expect(subject.resource_group.key).to eq('iOS') + end + end end context 'when job is a bridge' do diff --git a/spec/lib/gitlab/ci/yaml_processor_spec.rb b/spec/lib/gitlab/ci/yaml_processor_spec.rb index 8f9c5c74260..f61b28b06c8 100644 --- a/spec/lib/gitlab/ci/yaml_processor_spec.rb +++ b/spec/lib/gitlab/ci/yaml_processor_spec.rb @@ -241,6 +241,21 @@ module Gitlab end end end + + describe 'resource group' do + context 'when resource group is defined' do + let(:config) do + YAML.dump(rspec: { + script: 'test', + resource_group: 'iOS' + }) + end + + it 'has the attributes' do + expect(subject[:resource_group_key]).to eq 'iOS' + end + end + end end describe '#stages_attributes' do diff --git a/spec/lib/gitlab/import_export/all_models.yml b/spec/lib/gitlab/import_export/all_models.yml index 2ea563c50b6..8f0f09bc0be 100644 --- a/spec/lib/gitlab/import_export/all_models.yml +++ b/spec/lib/gitlab/import_export/all_models.yml @@ -444,6 +444,7 @@ project: - service_desk_setting - import_failures - container_expiration_policy +- resource_groups award_emoji: - awardable - user diff --git a/spec/models/ci/resource_group_spec.rb b/spec/models/ci/resource_group_spec.rb new file mode 100644 index 00000000000..ce8b03282bc --- /dev/null +++ b/spec/models/ci/resource_group_spec.rb @@ -0,0 +1,88 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Ci::ResourceGroup do + describe 'validation' do + it 'valids when key includes allowed character' do + resource_group = build(:ci_resource_group, key: 'test') + + expect(resource_group).to be_valid + end + + it 'invalids when key includes invalid character' do + resource_group = build(:ci_resource_group, key: ':::') + + expect(resource_group).not_to be_valid + end + end + + describe '#ensure_resource' do + it 'creates one resource when resource group is created' do + resource_group = create(:ci_resource_group) + + expect(resource_group.resources.count).to eq(1) + expect(resource_group.resources.all?(&:persisted?)).to eq(true) + end + end + + describe '#assign_resource_to' do + subject { resource_group.assign_resource_to(build) } + + let(:build) { create(:ci_build) } + let(:resource_group) { create(:ci_resource_group) } + + it 'retains resource for the build' do + expect(resource_group.resources.first.build).to be_nil + + is_expected.to eq(true) + + expect(resource_group.resources.first.build).to eq(build) + end + + context 'when there are no free resources' do + before do + resource_group.assign_resource_to(create(:ci_build)) + end + + it 'fails to retain resource' do + is_expected.to eq(false) + end + end + + context 'when the build has already retained a resource' do + let!(:another_resource) { create(:ci_resource, resource_group: resource_group, build: build) } + + it 'fails to retain resource' do + expect { subject }.to raise_error(ActiveRecord::RecordNotUnique) + end + end + end + + describe '#release_resource_from' do + subject { resource_group.release_resource_from(build) } + + let(:build) { create(:ci_build) } + let(:resource_group) { create(:ci_resource_group) } + + context 'when the build has already retained a resource' do + before do + resource_group.assign_resource_to(build) + end + + it 'releases resource from the build' do + expect(resource_group.resources.first.build).to eq(build) + + is_expected.to eq(true) + + expect(resource_group.resources.first.build).to be_nil + end + end + + context 'when the build has already released a resource' do + it 'fails to release resource' do + is_expected.to eq(false) + end + end + end +end diff --git a/spec/models/ci/resource_spec.rb b/spec/models/ci/resource_spec.rb new file mode 100644 index 00000000000..27e512e2c45 --- /dev/null +++ b/spec/models/ci/resource_spec.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Ci::Resource do + describe '.free' do + subject { described_class.free } + + let(:resource_group) { create(:ci_resource_group) } + let!(:free_resource) { resource_group.resources.take } + let!(:retained_resource) { create(:ci_resource, :retained, resource_group: resource_group) } + + it 'returns free resources' do + is_expected.to eq([free_resource]) + end + end + + describe '.retained_by' do + subject { described_class.retained_by(build) } + + let(:build) { create(:ci_build) } + let!(:resource) { create(:ci_resource, build: build) } + + it 'returns retained resources' do + is_expected.to eq([resource]) + end + end +end diff --git a/spec/models/concerns/safe_url_spec.rb b/spec/models/concerns/safe_url_spec.rb index 3244410181e..0ad26660a60 100644 --- a/spec/models/concerns/safe_url_spec.rb +++ b/spec/models/concerns/safe_url_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' describe SafeUrl do describe '#safe_url' do - class TestClass + class SafeUrlTestClass include SafeUrl attr_reader :url @@ -14,7 +14,7 @@ describe SafeUrl do end end - let(:test_class) { TestClass.new(url) } + let(:test_class) { SafeUrlTestClass.new(url) } let(:url) { 'http://example.com' } subject { test_class.safe_url } diff --git a/spec/services/ci/create_pipeline_service_spec.rb b/spec/services/ci/create_pipeline_service_spec.rb index 5f760844046..a4432cbcf5b 100644 --- a/spec/services/ci/create_pipeline_service_spec.rb +++ b/spec/services/ci/create_pipeline_service_spec.rb @@ -915,6 +915,44 @@ describe Ci::CreatePipelineService do end end + context 'with resource group' do + context 'when resource group is defined' do + before do + config = YAML.dump( + test: { stage: 'test', script: 'ls', resource_group: resource_group_key } + ) + + stub_ci_pipeline_yaml_file(config) + end + + let(:resource_group_key) { 'iOS' } + + it 'persists the association correctly' do + result = execute_service + deploy_job = result.builds.find_by_name!(:test) + resource_group = project.resource_groups.find_by_key!(resource_group_key) + + expect(result).to be_persisted + expect(deploy_job.resource_group.key).to eq(resource_group_key) + expect(project.resource_groups.count).to eq(1) + expect(resource_group.builds.count).to eq(1) + expect(resource_group.resources.count).to eq(1) + expect(resource_group.resources.first.build).to eq(nil) + end + + context 'when resourc group key includes predefined variables' do + let(:resource_group_key) { '$CI_COMMIT_REF_NAME-$CI_JOB_NAME' } + + it 'interpolates the variables into the key correctly' do + result = execute_service + + expect(result).to be_persisted + expect(project.resource_groups.exists?(key: 'master-test')).to eq(true) + end + end + end + end + context 'with timeout' do context 'when builds with custom timeouts are configured' do before do diff --git a/spec/services/ci/retry_build_service_spec.rb b/spec/services/ci/retry_build_service_spec.rb index b1368f7776b..76fe6f53a11 100644 --- a/spec/services/ci/retry_build_service_spec.rb +++ b/spec/services/ci/retry_build_service_spec.rb @@ -31,7 +31,7 @@ describe Ci::RetryBuildService do job_artifacts_container_scanning job_artifacts_dast job_artifacts_license_management job_artifacts_performance job_artifacts_codequality job_artifacts_metrics scheduled_at - job_variables].freeze + job_variables waiting_for_resource_at].freeze IGNORE_ACCESSORS = %i[type lock_version target_url base_tags trace_sections @@ -40,14 +40,14 @@ describe Ci::RetryBuildService do user_id auto_canceled_by_id retried failure_reason sourced_pipelines artifacts_file_store artifacts_metadata_store metadata runner_session trace_chunks upstream_pipeline_id - artifacts_file artifacts_metadata artifacts_size commands].freeze + artifacts_file artifacts_metadata artifacts_size commands resource resource_group_id].freeze shared_examples 'build duplication' do let(:another_pipeline) { create(:ci_empty_pipeline, project: project) } let(:build) do create(:ci_build, :failed, :expired, :erased, :queued, :coverage, :tags, - :allowed_to_fail, :on_tag, :triggered, :teardown_environment, + :allowed_to_fail, :on_tag, :triggered, :teardown_environment, :resource_group, description: 'my-job', stage: 'test', stage_id: stage.id, pipeline: pipeline, auto_canceled_by: another_pipeline, scheduled_at: 10.seconds.since) diff --git a/spec/validators/qualified_domain_array_validator_spec.rb b/spec/validators/qualified_domain_array_validator_spec.rb index 6beb4c67f6f..ab6cca4b671 100644 --- a/spec/validators/qualified_domain_array_validator_spec.rb +++ b/spec/validators/qualified_domain_array_validator_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe QualifiedDomainArrayValidator do - class TestClass + class QualifiedDomainArrayValidatorTestClass include ActiveModel::Validations attr_accessor :domain_array @@ -14,7 +14,7 @@ describe QualifiedDomainArrayValidator do end let!(:record) do - TestClass.new(['gitlab.com']) + QualifiedDomainArrayValidatorTestClass.new(['gitlab.com']) end subject { validator.validate(record) } |