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

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

require 'spec_helper'

RSpec.describe Gitlab::Ci::Config::Interpolation::FunctionsStack, feature_category: :pipeline_composition do
  let(:functions) { ['truncate(0,4)', 'truncate(1,2)'] }
  let(:input_value) { 'test_input_value' }

  subject { described_class.new(functions).evaluate(input_value) }

  it 'modifies the given input value according to the function expressions' do
    expect(subject).to be_success
    expect(subject.value).to eq('es')
  end

  context 'when applying a function fails' do
    let(:input_value) { 666 }

    it 'returns the error given by the failure' do
      expect(subject).not_to be_success
      expect(subject.errors).to contain_exactly(
        'error in `truncate` function: invalid input type: truncate can only be used with string inputs'
      )
    end
  end

  context 'when function expressions do not match any function' do
    let(:functions) { ['truncate(0)', 'unknown'] }

    it 'returns an error' do
      expect(subject).not_to be_success
      expect(subject.errors).to contain_exactly(
        'no function matching `truncate(0)`: check that the function name, arguments, and types are correct',
        'no function matching `unknown`: check that the function name, arguments, and types are correct'
      )
    end
  end
end