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

truncate_spec.rb « functions « 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: 93e5d4ef48cf49ff1c81199ddc1c22f82e0edee4 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Ci::Config::Interpolation::Functions::Truncate, feature_category: :pipeline_composition do
  it 'matches exactly the truncate function with 2 numeric arguments' do
    expect(described_class.matches?('truncate(1,2)')).to be_truthy
    expect(described_class.matches?('truncate( 11 , 222 )')).to be_truthy
    expect(described_class.matches?('truncate( string , 222 )')).to be_falsey
    expect(described_class.matches?('truncate(222)')).to be_falsey
    expect(described_class.matches?('unknown(1,2)')).to be_falsey
  end

  it 'truncates the given input' do
    function = described_class.new('truncate(1,2)', nil)

    output = function.execute('test')

    expect(function).to be_valid
    expect(output).to eq('es')
  end

  context 'when given a non-string input' do
    it 'returns an error' do
      function = described_class.new('truncate(1,2)', nil)

      function.execute(100)

      expect(function).not_to be_valid
      expect(function.errors).to contain_exactly(
        'error in `truncate` function: invalid input type: truncate can only be used with string inputs'
      )
    end
  end
end