2020-06-23 00:09:42 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Gitlab::Ci::Build::Releaser do
|
2020-06-23 00:09:42 +05:30
|
|
|
subject { described_class.new(config: config[:release]).script }
|
|
|
|
|
|
|
|
describe '#script' do
|
|
|
|
context 'all nodes' do
|
|
|
|
let(:config) do
|
|
|
|
{
|
|
|
|
release: {
|
|
|
|
name: 'Release $CI_COMMIT_SHA',
|
|
|
|
description: 'Created using the release-cli $EXTRA_DESCRIPTION',
|
|
|
|
tag_name: 'release-$CI_COMMIT_SHA',
|
2020-07-28 23:09:34 +05:30
|
|
|
ref: '$CI_COMMIT_SHA',
|
|
|
|
milestones: %w[m1 m2 m3],
|
2021-06-08 01:23:25 +05:30
|
|
|
released_at: '2020-07-15T08:00:00Z',
|
|
|
|
assets: {
|
|
|
|
links: [
|
|
|
|
{ name: 'asset1', url: 'https://example.com/assets/1', link_type: 'other', filepath: '/pretty/asset/1' },
|
|
|
|
{ name: 'asset2', url: 'https://example.com/assets/2' }
|
|
|
|
]
|
|
|
|
}
|
2020-06-23 00:09:42 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'generates the script' do
|
2021-06-08 01:23:25 +05:30
|
|
|
expect(subject).to eq(['release-cli create --name "Release $CI_COMMIT_SHA" --description "Created using the release-cli $EXTRA_DESCRIPTION" --tag-name "release-$CI_COMMIT_SHA" --ref "$CI_COMMIT_SHA" --released-at "2020-07-15T08:00:00Z" --milestone "m1" --milestone "m2" --milestone "m3" --assets-link "{\"name\":\"asset1\",\"url\":\"https://example.com/assets/1\",\"link_type\":\"other\",\"filepath\":\"/pretty/asset/1\"}" --assets-link "{\"name\":\"asset2\",\"url\":\"https://example.com/assets/2\"}"'])
|
2020-06-23 00:09:42 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'individual nodes' do
|
|
|
|
using RSpec::Parameterized::TableSyntax
|
2021-06-08 01:23:25 +05:30
|
|
|
links = { links: [{ name: 'asset1', url: 'https://example.com/assets/1', link_type: 'other', filepath: '/pretty/asset/1' }] }
|
2020-06-23 00:09:42 +05:30
|
|
|
|
|
|
|
where(:node_name, :node_value, :result) do
|
2020-07-28 23:09:34 +05:30
|
|
|
:name | 'Release $CI_COMMIT_SHA' | 'release-cli create --name "Release $CI_COMMIT_SHA"'
|
|
|
|
:description | 'Release-cli $EXTRA_DESCRIPTION' | 'release-cli create --description "Release-cli $EXTRA_DESCRIPTION"'
|
|
|
|
:tag_name | 'release-$CI_COMMIT_SHA' | 'release-cli create --tag-name "release-$CI_COMMIT_SHA"'
|
|
|
|
:ref | '$CI_COMMIT_SHA' | 'release-cli create --ref "$CI_COMMIT_SHA"'
|
|
|
|
:milestones | %w[m1 m2 m3] | 'release-cli create --milestone "m1" --milestone "m2" --milestone "m3"'
|
|
|
|
:released_at | '2020-07-15T08:00:00Z' | 'release-cli create --released-at "2020-07-15T08:00:00Z"'
|
2021-06-08 01:23:25 +05:30
|
|
|
:assets | links | "release-cli create --assets-link #{links[:links][0].to_json.to_json}"
|
2020-06-23 00:09:42 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
with_them do
|
|
|
|
let(:config) do
|
|
|
|
{
|
|
|
|
release: {
|
|
|
|
node_name => node_value
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'generates the script' do
|
2020-07-28 23:09:34 +05:30
|
|
|
expect(subject).to eq([result])
|
2020-06-23 00:09:42 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|