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

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

require 'spec_helper'

RSpec.describe Gitlab::Ci::Config::External::Mapper::Matcher, feature_category: :pipeline_authoring do
  let_it_be(:variables) do
    Gitlab::Ci::Variables::Collection.new.tap do |variables|
      variables.append(key: 'A_MASKED_VAR', value: 'this-is-secret', masked: true)
    end
  end

  let_it_be(:context) do
    Gitlab::Ci::Config::External::Context.new(variables: variables)
  end

  subject(:matcher) { described_class.new(context) }

  describe '#process' do
    let(:locations) do
      [{ local: 'file.yml' },
       { file: 'file.yml', project: 'namespace/project' },
       { remote: 'https://example.com/.gitlab-ci.yml' },
       { template: 'file.yml' },
       { artifact: 'generated.yml', job: 'test' }]
    end

    subject(:process) { matcher.process(locations) }

    it 'returns an array of file objects' do
      is_expected.to contain_exactly(
        an_instance_of(Gitlab::Ci::Config::External::File::Local),
        an_instance_of(Gitlab::Ci::Config::External::File::Project),
        an_instance_of(Gitlab::Ci::Config::External::File::Remote),
        an_instance_of(Gitlab::Ci::Config::External::File::Template),
        an_instance_of(Gitlab::Ci::Config::External::File::Artifact)
      )
    end

    context 'when a location is not valid' do
      let(:locations) { [{ invalid: 'file.yml' }] }

      it 'raises an error' do
        expect { process }.to raise_error(
          Gitlab::Ci::Config::External::Mapper::AmbigiousSpecificationError,
          '`{"invalid":"file.yml"}` does not have a valid subkey for include. ' \
          'Valid subkeys are: `local`, `project`, `remote`, `template`, `artifact`'
        )
      end

      context 'when the invalid location includes a masked variable' do
        let(:locations) { [{ invalid: 'this-is-secret.yml' }] }

        it 'raises an error with a masked sentence' do
          expect { process }.to raise_error(
            Gitlab::Ci::Config::External::Mapper::AmbigiousSpecificationError,
            '`{"invalid":"xxxxxxxxxxxxxx.yml"}` does not have a valid subkey for include. ' \
            'Valid subkeys are: `local`, `project`, `remote`, `template`, `artifact`'
          )
        end
      end
    end

    context 'when a location is ambiguous' do
      let(:locations) { [{ local: 'file.yml', remote: 'https://example.com/.gitlab-ci.yml' }] }

      it 'raises an error' do
        expect { process }.to raise_error(
          Gitlab::Ci::Config::External::Mapper::AmbigiousSpecificationError,
          "Each include must use only one of: `local`, `project`, `remote`, `template`, `artifact`"
        )
      end
    end
  end
end