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

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

require 'fast_spec_helper'

RSpec.describe Gitlab::Ci::Variables::Helpers do
  describe '.merge_variables' do
    let(:current_variables) do
      [{ key: 'key1', value: 'value1' },
       { key: 'key2', value: 'value2' }]
    end

    let(:new_variables) do
      [{ key: 'key2', value: 'value22' },
       { key: 'key3', value: 'value3' }]
    end

    let(:result) do
      [{ key: 'key1', value: 'value1', public: true },
       { key: 'key2', value: 'value22', public: true },
       { key: 'key3', value: 'value3', public: true }]
    end

    subject { described_class.merge_variables(current_variables, new_variables) }

    it { is_expected.to eq(result) }

    context 'when new variables is a hash' do
      let(:new_variables) do
        { 'key2' => 'value22', 'key3' => 'value3' }
      end

      it { is_expected.to eq(result) }
    end

    context 'when new variables is a hash with symbol keys' do
      let(:new_variables) do
        { key2: 'value22', key3: 'value3' }
      end

      it { is_expected.to eq(result) }
    end

    context 'when new variables is nil' do
      let(:new_variables) {}
      let(:result) do
        [{ key: 'key1', value: 'value1', public: true },
         { key: 'key2', value: 'value2', public: true }]
      end

      it { is_expected.to eq(result) }
    end
  end

  describe '.transform_to_yaml_variables' do
    let(:variables) do
      { 'key1' => 'value1', 'key2' => 'value2' }
    end

    let(:result) do
      [{ key: 'key1', value: 'value1', public: true },
       { key: 'key2', value: 'value2', public: true }]
    end

    subject { described_class.transform_to_yaml_variables(variables) }

    it { is_expected.to eq(result) }

    context 'when variables is nil' do
      let(:variables) {}

      it { is_expected.to eq([]) }
    end
  end

  describe '.transform_from_yaml_variables' do
    let(:variables) do
      [{ key: 'key1', value: 'value1', public: true },
       { key: 'key2', value: 'value2', public: true }]
    end

    let(:result) do
      { 'key1' => 'value1', 'key2' => 'value2' }
    end

    subject { described_class.transform_from_yaml_variables(variables) }

    it { is_expected.to eq(result) }

    context 'when variables is nil' do
      let(:variables) {}

      it { is_expected.to eq({}) }
    end

    context 'when variables is a hash' do
      let(:variables) do
        { key1: 'value1', 'key2' => 'value2' }
      end

      it { is_expected.to eq(result) }
    end
  end
end