debian-mirror-gitlab/spec/lib/gitlab/ci/config/entry/release_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

268 lines
6.7 KiB
Ruby
Raw Normal View History

2020-03-13 15:44:24 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Gitlab::Ci::Config::Entry::Release do
2020-03-13 15:44:24 +05:30
let(:entry) { described_class.new(config) }
2020-07-28 23:09:34 +05:30
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
2020-03-13 15:44:24 +05:30
describe 'validation' do
context 'when entry config value is correct' do
let(:config) { { tag_name: 'v0.06', description: "./release_changelog.txt" } }
2020-07-28 23:09:34 +05:30
it_behaves_like 'a valid entry'
2020-03-13 15:44:24 +05:30
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
2020-07-28 23:09:34 +05:30
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"
}
2020-03-13 15:44:24 +05:30
end
2020-07-28 23:09:34 +05:30
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'
}
2020-03-13 15:44:24 +05:30
end
2020-07-28 23:09:34 +05:30
it_behaves_like 'a valid entry'
2020-03-13 15:44:24 +05:30
end
2020-07-28 23:09:34 +05:30
context "when value includes 'released_at' keyword" do
2020-03-13 15:44:24 +05:30
let(:config) do
{
tag_name: 'v0.06',
description: "./release_changelog.txt",
2020-07-28 23:09:34 +05:30
name: "Release $CI_TAG_NAME",
released_at: '2019-03-15T08:00:00Z'
2020-03-13 15:44:24 +05:30
}
end
2020-07-28 23:09:34 +05:30
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
}
2020-03-13 15:44:24 +05:30
end
2020-07-28 23:09:34 +05:30
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
2022-08-27 11:52:29 +05:30
let(:ref) { 'b3235930' }
2020-07-28 23:09:34 +05:30
it_behaves_like 'a valid entry'
end
context "when 'ref' is a branch name" do
2022-08-27 11:52:29 +05:30
let(:ref) { 'fix/123-branch-name' }
2020-07-28 23:09:34 +05:30
it_behaves_like 'a valid entry'
end
context "when 'ref' is a semantic versioning tag" do
2022-08-27 11:52:29 +05:30
let(:ref) { 'v1.2.3' }
2020-07-28 23:09:34 +05:30
it_behaves_like 'a valid entry'
end
context "when 'ref' is a semantic versioning tag rc" do
2022-08-27 11:52:29 +05:30
let(:ref) { 'v1.2.3-rc' }
2020-07-28 23:09:34 +05:30
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'
2020-03-13 15:44:24 +05:30
end
end
2022-08-27 11:52:29 +05:30
context "when value includes 'tag_message' keyword" do
let(:config) do
{
tag_name: 'v0.06',
description: "./release_changelog.txt",
tag_message: "Annotated tag message"
}
end
it_behaves_like 'a valid entry'
end
context "when 'tag_message' is nil" do
let(:config) do
{
tag_name: 'v0.06',
description: "./release_changelog.txt",
tag_message: nil
}
end
it_behaves_like 'a valid entry'
end
2020-03-13 15:44:24 +05:30
context 'when entry value is not correct' do
describe '#errors' do
context 'when value of attribute is invalid' do
let(:config) { { description: 10 } }
2020-07-28 23:09:34 +05:30
it_behaves_like 'reports error', 'release description should be a string'
2020-03-13 15:44:24 +05:30
end
context 'when release description is missing' do
let(:config) { { tag_name: 'v0.06' } }
2020-07-28 23:09:34 +05:30
it_behaves_like 'reports error', "release description can't be blank"
2020-03-13 15:44:24 +05:30
end
context 'when release tag_name is missing' do
let(:config) { { description: "./release_changelog.txt" } }
2020-07-28 23:09:34 +05:30
it_behaves_like 'reports error', "release tag name can't be blank"
2020-03-13 15:44:24 +05:30
end
context 'when there is an unknown key present' do
let(:config) { { test: 100 } }
2020-07-28 23:09:34 +05:30
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'
2020-03-13 15:44:24 +05:30
end
2022-08-27 11:52:29 +05:30
context 'when `tag_message` is not a string' do
let(:config) { { tag_message: 100 } }
it_behaves_like 'reports error', 'release tag message should be a string'
end
2020-03-13 15:44:24 +05:30
end
end
end
end