diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-15 06:09:27 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-15 06:09:27 +0300 |
commit | a7b6d465ae75b497ac34cb43361edd0c8ce45fbd (patch) | |
tree | d1cf9f860c07d082014a895a306a6eca8a8d2691 /spec/models | |
parent | afd8f58f2d0d42d21496fe4652c1664add9b68b7 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/ci/job_annotation_spec.rb | 81 | ||||
-rw-r--r-- | spec/models/ci/processable_spec.rb | 4 |
2 files changed, 84 insertions, 1 deletions
diff --git a/spec/models/ci/job_annotation_spec.rb b/spec/models/ci/job_annotation_spec.rb new file mode 100644 index 00000000000..f94494bc91d --- /dev/null +++ b/spec/models/ci/job_annotation_spec.rb @@ -0,0 +1,81 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Ci::JobAnnotation, feature_category: :build_artifacts do + let_it_be_with_reload(:job) { create(:ci_build, :success) } + + describe 'validations' do + subject { create(:ci_job_annotation, job: job) } + + it { is_expected.to belong_to(:job).class_name('Ci::Build').inverse_of(:job_annotations) } + it { is_expected.to validate_presence_of(:name) } + it { is_expected.to validate_length_of(:name).is_at_most(255) } + it { is_expected.to validate_uniqueness_of(:name).scoped_to([:job_id, :partition_id]) } + end + + describe '.create' do + context 'when JSON data is valid' do + subject do + job.job_annotations.create!( + name: 'external', + data: [{ external_link: { label: 'Example', url: 'https://example.com/' } }] + ) + end + + it 'creates the object' do + expect(subject).to be_a(described_class) + expect(subject.data).to contain_exactly(a_hash_including('external_link' => + a_hash_including('label' => 'Example', 'url' => 'https://example.com/'))) + end + end + + context 'when JSON data is invalid' do + subject { job.job_annotations.create!(name: 'external', data: [{ invalid: 'invalid' }]) } + + it 'throws an error' do + expect { subject }.to raise_error(ActiveRecord::RecordInvalid) + end + end + + context 'when there are more than 1000 JSON entries' do + subject { job.job_annotations.create!(data: [{ external_link: { label: 'Example', url: 'https://example.com/' } }] * 1001) } + + it 'throws an error' do + expect { subject }.to raise_error(ActiveRecord::RecordInvalid) + end + end + end + + describe 'partitioning' do + context 'with job' do + before do + job.partition_id = 123 + end + + let(:annotation) { build(:ci_job_annotation, job: job) } + + it 'copies the partition_id from job' do + expect { annotation.valid? }.to change { annotation.partition_id }.to(123) + end + + context 'when it is already set' do + let(:annotation) { build(:ci_job_annotation, job: job, partition_id: 125) } + + it 'does not change the partition_id value' do + expect { annotation.valid? }.not_to change { annotation.partition_id } + end + end + end + + context 'without job' do + let(:annotation) { build(:ci_job_annotation, job: nil) } + + it { is_expected.to validate_presence_of(:partition_id) } + + it 'does not change the partition_id value' do + expect { annotation.valid? }.not_to change { annotation.partition_id } + end + end + end +end diff --git a/spec/models/ci/processable_spec.rb b/spec/models/ci/processable_spec.rb index 34a56162dd9..86894ebcf2d 100644 --- a/spec/models/ci/processable_spec.rb +++ b/spec/models/ci/processable_spec.rb @@ -76,7 +76,8 @@ RSpec.describe Ci::Processable, feature_category: :continuous_integration do job_artifacts_cobertura needs job_artifacts_accessibility job_artifacts_requirements job_artifacts_coverage_fuzzing job_artifacts_requirements_v2 - job_artifacts_api_fuzzing terraform_state_versions job_artifacts_cyclonedx].freeze + job_artifacts_api_fuzzing terraform_state_versions job_artifacts_cyclonedx + job_annotations].freeze end let(:ignore_accessors) do @@ -102,6 +103,7 @@ RSpec.describe Ci::Processable, feature_category: :continuous_integration do create(:ci_job_variable, :dotenv_source, job: processable) create(:terraform_state_version, build: processable) + create(:ci_job_annotation, :external_link, job: processable) end before do |