summaryrefslogtreecommitdiff
path: root/spec/services/ci/create_pipeline_service/parameter_content_spec.rb
blob: 761504ffb589e729be5f7c01ebb6886d221fd656 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Ci::CreatePipelineService do
  let_it_be(:project) { create(:project, :repository) }
  let_it_be(:user) { project.owner }

  let(:service) { described_class.new(project, user, { ref: 'refs/heads/master' }) }
  let(:content) do
    <<~EOY
      ---
      stages:
        - dast

      variables:
        DAST_VERSION: 1
        SECURE_ANALYZERS_PREFIX: "registry.gitlab.com/gitlab-org/security-products/analyzers"

      dast:
        stage: dast
        image:
          name: "$SECURE_ANALYZERS_PREFIX/dast:$DAST_VERSION"
        variables:
          GIT_STRATEGY: none
        script:
          - /analyze
    EOY
  end

  describe '#execute' do
    context 'when source is a dangling build' do
      subject { service.execute(:ondemand_dast_scan, content: content).payload }

      context 'parameter config content' do
        it 'creates a pipeline' do
          expect(subject).to be_persisted
        end

        it 'creates builds with the correct names' do
          expect(subject.builds.pluck(:name)).to match_array %w[dast]
        end

        it 'creates stages with the correct names' do
          expect(subject.stages.pluck(:name)).to match_array %w[dast]
        end

        it 'sets the correct config source' do
          expect(subject.config_source).to eq 'parameter_source'
        end
      end
    end
  end
end