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

release_spec.rb « entry « config « ci « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e5155f91be4b84883096ab3870e54899249f1753 (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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Ci::Config::Entry::Release do
  let(:entry) { described_class.new(config) }

  shared_examples_for 'a valid entry' do
    describe '#value' do
      it 'returns release configuration' do
        expect(entry.value).to eq config
      end
    end

    describe '#valid?' do
      it 'is valid' do
        expect(entry).to be_valid
      end
    end
  end

  shared_examples_for 'reports error' do |message|
    it 'reports error' do
      expect(entry.errors)
        .to include message
    end
  end

  describe 'validation' do
    context 'when entry config value is correct' do
      let(:config) { { tag_name: 'v0.06', description: "./release_changelog.txt" } }

      it_behaves_like 'a valid entry'
    end

    context "when value includes 'assets' keyword" do
      let(:config) do
        {
          tag_name: 'v0.06',
          description: "./release_changelog.txt",
          assets: [
            {
              name: "cool-app.zip",
              url: "http://my.awesome.download.site/1.0-$CI_COMMIT_SHORT_SHA.zip"
            }
          ]
        }
      end

      it_behaves_like 'a valid entry'
    end

    context "when value includes 'name' keyword" do
      let(:config) do
        {
          tag_name: 'v0.06',
          description: "./release_changelog.txt",
          name: "Release $CI_TAG_NAME"
        }
      end

      it_behaves_like 'a valid entry'
    end

    context "when value includes 'ref' keyword" do
      let(:config) do
        {
          tag_name: 'v0.06',
          description: "./release_changelog.txt",
          name: "Release $CI_TAG_NAME",
          ref: 'b3235930aa443112e639f941c69c578912189bdd'
        }
      end

      it_behaves_like 'a valid entry'
    end

    context "when value includes 'released_at' keyword" do
      let(:config) do
        {
          tag_name: 'v0.06',
          description: "./release_changelog.txt",
          name: "Release $CI_TAG_NAME",
          released_at: '2019-03-15T08:00:00Z'
        }
      end

      it_behaves_like 'a valid entry'
    end

    context "when value includes 'milestones' keyword" do
      let(:config) do
        {
          tag_name: 'v0.06',
          description: "./release_changelog.txt",
          name: "Release $CI_TAG_NAME",
          milestones: milestones
        }
      end

      context 'for an array of milestones' do
        let(:milestones) { %w[m1 m2 m3] }

        it_behaves_like 'a valid entry'
      end

      context 'for a single milestone' do
        let(:milestones) { 'm1' }

        it_behaves_like 'a valid entry'
      end
    end

    context "when value includes 'ref' keyword" do
      let(:config) do
        {
          tag_name: 'v0.06',
          description: "./release_changelog.txt",
          name: "Release $CI_TAG_NAME",
          ref: ref
        }
      end

      context "when 'ref' is a full commit SHA" do
        let(:ref) { 'b3235930aa443112e639f941c69c578912189bdd' }

        it_behaves_like 'a valid entry'
      end

      context "when 'ref' is a short commit SHA" do
        let(:ref) { 'b3235930'}

        it_behaves_like 'a valid entry'
      end

      context "when 'ref' is a branch name" do
        let(:ref) { 'fix/123-branch-name'}

        it_behaves_like 'a valid entry'
      end

      context "when 'ref' is a semantic versioning tag" do
        let(:ref) { 'v1.2.3'}

        it_behaves_like 'a valid entry'
      end

      context "when 'ref' is a semantic versioning tag rc" do
        let(:ref) { 'v1.2.3-rc'}

        it_behaves_like 'a valid entry'
      end
    end

    context "when value includes 'released_at' keyword" do
      let(:config) do
        {
          tag_name: 'v0.06',
          description: "./release_changelog.txt",
          name: "Release $CI_TAG_NAME",
          released_at: '2019-03-15T08:00:00Z'
        }
      end

      it_behaves_like 'a valid entry'
    end

    context "when value includes 'milestones' keyword" do
      let(:config) do
        {
          tag_name: 'v0.06',
          description: "./release_changelog.txt",
          name: "Release $CI_TAG_NAME",
          milestones: milestones
        }
      end

      context 'for an array of milestones' do
        let(:milestones) { %w[m1 m2 m3] }

        it_behaves_like 'a valid entry'
      end

      context 'for a single milestone' do
        let(:milestones) { 'm1' }

        it_behaves_like 'a valid entry'
      end
    end

    context 'when entry value is not correct' do
      describe '#errors' do
        context 'when value of attribute is invalid' do
          let(:config) { { description: 10 } }

          it_behaves_like 'reports error', 'release description should be a string'
        end

        context 'when release description is missing' do
          let(:config) { { tag_name: 'v0.06' } }

          it_behaves_like 'reports error', "release description can't be blank"
        end

        context 'when release tag_name is missing' do
          let(:config) { { description: "./release_changelog.txt" } }

          it_behaves_like 'reports error', "release tag name can't be blank"
        end

        context 'when there is an unknown key present' do
          let(:config) { { test: 100 } }

          it_behaves_like 'reports error', 'release config contains unknown keys: test'
        end

        context 'when `released_at` is not a valid date' do
          let(:config) { { released_at: 'ABC123' } }

          it_behaves_like 'reports error', 'release released at must be a valid datetime'
        end

        context 'when `ref` is not valid' do
          let(:config) { { ref: 'invalid\branch' } }

          it_behaves_like 'reports error', 'release ref must be a valid ref'
        end

        context 'when `milestones` is not an array of strings' do
          let(:config) { { milestones: [1, 2, 3] } }

          it_behaves_like 'reports error', 'release milestones should be an array of strings or a string'
        end
      end
    end
  end
end