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

inputs_spec.rb « input « ci « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5d2d519229900fe19d23d621ed5509f5b4954955 (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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# frozen_string_literal: true

require 'fast_spec_helper'

RSpec.describe Gitlab::Ci::Input::Inputs, feature_category: :pipeline_composition do
  describe '#valid?' do
    let(:spec) { { website: nil } }

    it 'describes user-provided inputs' do
      inputs = described_class.new(spec, { website: 'http://example.gitlab.com' })

      expect(inputs).to be_valid
    end
  end

  context 'when proper specification has been provided' do
    let(:spec) do
      {
        website: nil,
        env: { default: 'development' },
        run: { options: %w[tests spec e2e] }
      }
    end

    let(:args) { { website: 'https://gitlab.com', run: 'tests' } }

    it 'fabricates desired input arguments' do
      inputs = described_class.new(spec, args)

      expect(inputs).to be_valid
      expect(inputs.count).to eq 3
      expect(inputs.to_hash).to eq(args.merge(env: 'development'))
    end
  end

  context 'when inputs and args are empty' do
    it 'is a valid use-case' do
      inputs = described_class.new({}, {})

      expect(inputs).to be_valid
      expect(inputs.to_hash).to be_empty
    end
  end

  context 'when there are arguments recoincilation errors present' do
    context 'when required argument is missing' do
      let(:spec) { { website: nil } }

      it 'returns an error' do
        inputs = described_class.new(spec, {})

        expect(inputs).not_to be_valid
        expect(inputs.errors.first).to eq '`website` input: required value has not been provided'
      end
    end

    context 'when argument is not present but configured as allowlist' do
      let(:spec) do
        { run: { options: %w[opt1 opt2] } }
      end

      it 'returns an error' do
        inputs = described_class.new(spec, {})

        expect(inputs).not_to be_valid
        expect(inputs.errors.first).to eq '`run` input: argument not provided'
      end
    end
  end

  context 'when unknown specification argument has been used' do
    let(:spec) do
      {
        website: nil,
        env: { default: 'development' },
        run: { options: %w[tests spec e2e] },
        test: { unknown: 'something' }
      }
    end

    let(:args) { { website: 'https://gitlab.com', run: 'tests' } }

    it 'fabricates an unknown argument entry and returns an error' do
      inputs = described_class.new(spec, args)

      expect(inputs).not_to be_valid
      expect(inputs.count).to eq 4
      expect(inputs.errors.first).to eq '`test` input: unrecognized input argument specification: `unknown`'
    end
  end

  context 'when unknown arguments are being passed by a user' do
    let(:spec) do
      { env: { default: 'development' } }
    end

    let(:args) { { website: 'https://gitlab.com', run: 'tests' } }

    it 'returns an error with a list of unknown arguments' do
      inputs = described_class.new(spec, args)

      expect(inputs).not_to be_valid
      expect(inputs.errors.first).to eq 'unknown input arguments: [:website, :run]'
    end
  end

  context 'when composite specification is being used' do
    let(:spec) do
      {
        env: {
          default: 'dev',
          options: %w[test dev prod]
        }
      }
    end

    let(:args) { { env: 'dev' } }

    it 'returns an error describing an unknown specification' do
      inputs = described_class.new(spec, args)

      expect(inputs).not_to be_valid
      expect(inputs.errors.first).to eq '`env` input: unrecognized input argument definition'
    end
  end
end