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

documents_spec.rb « yaml « config « ci « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: babdea6623b563daad0458e6141b47f80263df93 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Ci::Config::Yaml::Documents, feature_category: :pipeline_composition do
  let(:documents) { described_class.new(yaml_documents) }

  describe '#valid?' do
    context 'when there are no errors' do
      let(:yaml_documents) { [::Gitlab::Config::Loader::Yaml.new('job:')] }

      it 'returns true' do
        expect(documents).to be_valid
      end
    end

    context 'when there are errors' do
      let(:yaml_documents) { [::Gitlab::Config::Loader::Yaml.new('_!@malformedyaml:&')] }

      it 'returns false' do
        expect(documents).not_to be_valid
      end
    end
  end

  describe '#header' do
    context 'when there are at least 2 documents and the first document has a `spec` keyword' do
      let(:yaml_documents) { [::Gitlab::Config::Loader::Yaml.new('spec:'), ::Gitlab::Config::Loader::Yaml.new('job:')] }

      it 'returns the header' do
        expect(documents.header).to eq(spec: nil)
      end
    end

    context 'when there are fewer than 2 documents' do
      let(:yaml_documents) { [::Gitlab::Config::Loader::Yaml.new('job:')] }

      it 'returns nil' do
        expect(documents.header).to be_nil
      end
    end

    context 'when there are at least 2 documents and the first document does not have a `spec` keyword' do
      let(:yaml_documents) do
        [::Gitlab::Config::Loader::Yaml.new('job1:'), ::Gitlab::Config::Loader::Yaml.new('job2:')]
      end

      it 'returns nil' do
        expect(documents.header).to be_nil
      end
    end
  end

  describe '#content' do
    context 'when there is a header' do
      let(:yaml_documents) { [::Gitlab::Config::Loader::Yaml.new('spec:'), ::Gitlab::Config::Loader::Yaml.new('job:')] }

      it 'returns the unparsed content of the last document' do
        expect(documents.content).to eq('job:')
      end
    end

    context 'when there is no header' do
      let(:yaml_documents) { [::Gitlab::Config::Loader::Yaml.new('job:')] }

      it 'returns the unparsed content of the first document' do
        expect(documents.content).to eq('job:')
      end
    end
  end
end