Welcome to mirror list, hosted at ThFree Co, Russian Federation.

pipeline_spec.rb « seed « pipeline « ci « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1790388da03e13301c071bfab198265cfd58b2bb (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Ci::Pipeline::Seed::Pipeline do
  let_it_be(:project) { create(:project, :repository) }
  let_it_be(:pipeline) { create(:ci_pipeline, project: project) }

  let(:stages_attributes) do
    [
      {
        name: 'build',
        index: 0,
        builds: [
          { name: 'init', scheduling_type: :stage },
          { name: 'build', scheduling_type: :stage }
        ]
      },
      {
        name: 'test',
        index: 1,
        builds: [
          { name: 'rspec', scheduling_type: :stage },
          { name: 'staging', scheduling_type: :stage, environment: 'staging' },
          { name: 'deploy', scheduling_type: :stage, environment: 'production' }
        ]
      }
    ]
  end

  subject(:seed) do
    described_class.new(pipeline, stages_attributes)
  end

  describe '#stages' do
    it 'returns the stage resources' do
      stages = seed.stages

      expect(stages).to all(be_a(Ci::Stage))
      expect(stages.map(&:name)).to contain_exactly('build', 'test')
    end
  end

  describe '#size' do
    it 'returns the number of jobs' do
      expect(seed.size).to eq(5)
    end
  end

  describe '#errors' do
    context 'when attributes are valid' do
      it 'returns nil' do
        expect(seed.errors).to be_nil
      end
    end

    context 'when attributes are not valid' do
      it 'returns the errors' do
        stages_attributes[0][:builds] << {
          name: 'invalid_job',
          scheduling_type: :dag,
          needs_attributes: [{ name: 'non-existent', artifacts: true }]
        }

        expect(seed.errors).to contain_exactly("invalid_job: needs 'non-existent'")
      end
    end
  end

  describe '#deployments_count' do
    it 'counts the jobs having an environment associated' do
      expect(seed.deployments_count).to eq(2)
    end
  end
end