diff options
Diffstat (limited to 'spec/models/ci')
-rw-r--r-- | spec/models/ci/build_annotation_spec.rb | 84 | ||||
-rw-r--r-- | spec/models/ci/build_spec.rb | 45 |
2 files changed, 129 insertions, 0 deletions
diff --git a/spec/models/ci/build_annotation_spec.rb b/spec/models/ci/build_annotation_spec.rb new file mode 100644 index 00000000000..7b716be48ab --- /dev/null +++ b/spec/models/ci/build_annotation_spec.rb @@ -0,0 +1,84 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Ci::BuildAnnotation do + def annotation(*args) + described_class.new(*args).tap do |annotation| + annotation.validate + end + end + + describe 'when validating the severity' do + it 'produces an error if it is missing' do + expect(annotation.errors[:severity]).not_to be_empty + end + end + + describe 'when validating the CI build ID' do + it 'produces an error if it is missing' do + expect(annotation.errors[:build_id]).not_to be_empty + end + end + + describe 'when validating the summary' do + it 'produces an error if it is missing' do + expect(annotation.errors[:summary]).not_to be_empty + end + + it 'produces an error if it exceeds the maximum length' do + expect(annotation(summary: 'a' * 1024).errors[:summary]).not_to be_empty + end + + it 'does not produce an error if it is valid' do + expect(annotation(summary: 'a').errors[:summary]).to be_empty + end + end + + describe 'when validating the line number' do + it 'produces an error if it is zero' do + expect(annotation(line_number: 0).errors[:line_number]).not_to be_empty + end + + it 'produces an error if it is negative' do + expect(annotation(line_number: -1).errors[:line_number]).not_to be_empty + end + + it 'produces an error if it is too great' do + expect(annotation(line_number: 40_000).errors[:line_number]) + .not_to be_empty + end + + it 'produces an error if the file path is not present' do + expect(annotation(line_number: 1).errors[:file_path]).not_to be_empty + end + + it 'does not produce an error if it is valid' do + row = annotation(line_number: 1, file_path: 'foo.rb') + + expect(row.errors[:line_number]).to be_empty + expect(row.errors[:file_path]).to be_empty + end + + it 'does not produce an error if it and the file path are not given' do + row = annotation + + expect(row.errors[:line_number]).to be_empty + expect(row.errors[:file_path]).to be_empty + end + end + + describe 'when validating the file path' do + it 'produces an error if the line number is not present' do + expect(annotation(file_path: 'foo.rb').errors[:line_number]) + .not_to be_empty + end + + it 'does not produce an error if it is valid' do + row = annotation(line_number: 1, file_path: 'foo.rb') + + expect(row.errors[:file_path]).to be_empty + expect(row.errors[:line_number]).to be_empty + end + end +end diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index 8a1bbb26e57..0550b456c21 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -3602,4 +3602,49 @@ describe Ci::Build do end end end + + describe '#first_build_annotation_artifact' do + context 'when there are no build annotations' do + it 'returns nil' do + build = create(:ci_build) + + expect(build.first_build_annotation_artifact).to be_nil + end + end + + context 'when there is one build annotation artifact' do + it 'returns the artifact' do + build = create(:ci_build) + artifact = create( + :ci_job_artifact, + job: build, + file_type: :annotation, + file_format: :gzip + ) + + expect(build.first_build_annotation_artifact).to eq(artifact) + end + end + + context 'when there are multiple build annotation artifacts' do + it 'returns the oldest artifact' do + build = create(:ci_build) + artifact1 = create( + :ci_job_artifact, + job: build, + file_type: :annotation, + file_format: :gzip + ) + + create( + :ci_job_artifact, + job: build, + file_type: :annotation, + file_format: :gzip + ) + + expect(build.first_build_annotation_artifact).to eq(artifact1) + end + end + end end |