diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-18 11:17:02 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-18 11:17:02 +0300 |
commit | b39512ed755239198a9c294b6a45e65c05900235 (patch) | |
tree | d234a3efade1de67c46b9e5a38ce813627726aa7 /spec/services/ci/track_failed_build_service_spec.rb | |
parent | d31474cf3b17ece37939d20082b07f6657cc79a9 (diff) |
Add latest changes from gitlab-org/gitlab@15-3-stable-eev15.3.0-rc42
Diffstat (limited to 'spec/services/ci/track_failed_build_service_spec.rb')
-rw-r--r-- | spec/services/ci/track_failed_build_service_spec.rb | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/spec/services/ci/track_failed_build_service_spec.rb b/spec/services/ci/track_failed_build_service_spec.rb new file mode 100644 index 00000000000..d83e56f0669 --- /dev/null +++ b/spec/services/ci/track_failed_build_service_spec.rb @@ -0,0 +1,56 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Ci::TrackFailedBuildService do + let_it_be(:user) { create(:user) } + let_it_be(:project) { create(:project, :public) } + let_it_be(:pipeline) { create(:ci_pipeline, project: project, user: user) } + + let_it_be(:exit_code) { 42 } + let_it_be(:failure_reason) { "script_failure" } + + describe '#execute' do + context 'when a build has failed' do + let_it_be(:build) { create(:ci_build, :failed, :sast_report, pipeline: pipeline, user: user) } + + subject { described_class.new(build: build, exit_code: exit_code, failure_reason: failure_reason) } + + it 'tracks the build failed event', :snowplow do + response = subject.execute + + expect(response.success?).to be true + + expect_snowplow_event( + category: 'ci::build', + action: 'failed', + context: [{ + schema: described_class::SCHEMA_URL, + data: { + build_id: build.id, + build_name: build.name, + build_artifact_types: ["sast"], + exit_code: exit_code, + failure_reason: failure_reason + } + }], + user: user, + project: project.id) + end + end + + context 'when a build has not failed' do + let_it_be(:build) { create(:ci_build, :success, :sast_report, pipeline: pipeline, user: user) } + + subject { described_class.new(build: build, exit_code: nil, failure_reason: nil) } + + it 'does not track the build failed event', :snowplow do + response = subject.execute + + expect(response.error?).to be true + + expect_no_snowplow_event + end + end + end +end |