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

global_spec.rb « entry « config « web_ide « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3e29bf89785c5e6c7632168c6d63f47be5665ec7 (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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::WebIde::Config::Entry::Global do
  let(:global) { described_class.new(hash) }

  describe '.nodes' do
    it 'returns a hash' do
      expect(described_class.nodes).to be_a(Hash)
    end

    context 'when filtering all the entry/node names' do
      it 'contains the expected node names' do
        expect(described_class.nodes.keys).to match_array(described_class.allowed_keys)
      end
    end
  end

  context 'when configuration is valid' do
    context 'when some entries defined' do
      let(:hash) do
        { terminal: { before_script: ['ls'], variables: {}, script: 'sleep 10s', services: ['mysql'] } }
      end

      describe '#compose!' do
        before do
          global.compose!
        end

        it 'creates nodes hash' do
          expect(global.descendants).to be_an Array
        end

        it 'creates node object for each entry' do
          expect(global.descendants.count).to eq described_class.allowed_keys.length
        end

        it 'creates node object using valid class' do
          expect(global.descendants.first)
            .to be_an_instance_of Gitlab::WebIde::Config::Entry::Terminal
        end

        it 'sets correct description for nodes' do
          expect(global.descendants.first.description)
            .to eq 'Configuration of the webide terminal.'
        end

        describe '#leaf?' do
          it 'is not leaf' do
            expect(global).not_to be_leaf
          end
        end
      end

      context 'when not composed' do
        describe '#terminal_value' do
          it 'returns nil' do
            expect(global.terminal_value).to be nil
          end
        end

        describe '#leaf?' do
          it 'is leaf' do
            expect(global).to be_leaf
          end
        end
      end

      context 'when composed' do
        before do
          global.compose!
        end

        describe '#errors' do
          it 'has no errors' do
            expect(global.errors).to be_empty
          end
        end

        describe '#terminal_value' do
          it 'returns correct script' do
            expect(global.terminal_value).to eq({
              tag_list: [],
              yaml_variables: [],
              options: {
                before_script: ['ls'],
                script: ['sleep 10s'],
                services: [{ name: "mysql" }]
              }
            })
          end
        end
      end
    end
  end

  context 'when configuration is not valid' do
    before do
      global.compose!
    end

    context 'when job does not have valid before script' do
      let(:hash) do
        { terminal: { before_script: 100 } }
      end

      describe '#errors' do
        it 'reports errors about missing script' do
          expect(global.errors)
            .to include "terminal:before_script config should be an array containing strings and arrays of strings"
        end
      end
    end
  end

  context 'when value is not a hash' do
    let(:hash) { [] }

    describe '#valid?' do
      it 'is not valid' do
        expect(global).not_to be_valid
      end
    end

    describe '#errors' do
      it 'returns error about invalid type' do
        expect(global.errors.first).to match /should be a hash/
      end
    end
  end

  describe '#specified?' do
    it 'is concrete entry that is defined' do
      expect(global.specified?).to be true
    end
  end

  describe '#[]' do
    before do
      global.compose!
    end

    let(:hash) do
      { terminal: { before_script: ['ls'] } }
    end

    context 'when entry exists' do
      it 'returns correct entry' do
        expect(global[:terminal])
          .to be_an_instance_of Gitlab::WebIde::Config::Entry::Terminal
        expect(global[:terminal][:before_script].value).to eq ['ls']
      end
    end

    context 'when entry does not exist' do
      it 'always return unspecified node' do
        expect(global[:some][:unknown][:node])
          .not_to be_specified
      end
    end
  end
end