summaryrefslogtreecommitdiff
path: root/spec/bin
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-08-20 18:42:06 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-08-20 18:42:06 +0000
commit6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch)
tree78be5963ec075d80116a932011d695dd33910b4e /spec/bin
parent1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff)
downloadgitlab-ce-6e4e1050d9dba2b7b2523fdd1768823ab85feef4.tar.gz
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'spec/bin')
-rw-r--r--spec/bin/feature_flag_spec.rb91
1 files changed, 74 insertions, 17 deletions
diff --git a/spec/bin/feature_flag_spec.rb b/spec/bin/feature_flag_spec.rb
index 3a315a13686..f85b8f22210 100644
--- a/spec/bin/feature_flag_spec.rb
+++ b/spec/bin/feature_flag_spec.rb
@@ -8,7 +8,7 @@ RSpec.describe 'bin/feature-flag' do
using RSpec::Parameterized::TableSyntax
describe FeatureFlagCreator do
- let(:argv) { %w[feature-flag-name -t development -g group::memory -i https://url] }
+ let(:argv) { %w[feature-flag-name -t development -g group::memory -i https://url -m http://url] }
let(:options) { FeatureFlagOptionParser.parse(argv) }
let(:creator) { described_class.new(options) }
let(:existing_flag) { File.join('config', 'feature_flags', 'development', 'existing-feature-flag.yml') }
@@ -115,24 +115,45 @@ RSpec.describe 'bin/feature-flag' do
describe '.read_type' do
let(:type) { 'development' }
- it 'reads type from $stdin' do
- expect($stdin).to receive(:gets).and_return(type)
- expect do
+ context 'when there is only a single type defined' do
+ before do
+ stub_const('FeatureFlagOptionParser::TYPES',
+ development: { description: 'short' }
+ )
+ end
+
+ it 'returns that type' do
expect(described_class.read_type).to eq(:development)
- end.to output(/specify the type/).to_stdout
+ end
end
- context 'invalid type given' do
- let(:type) { 'invalid' }
+ context 'when there are many types defined' do
+ before do
+ stub_const('FeatureFlagOptionParser::TYPES',
+ development: { description: 'short' },
+ licensed: { description: 'licensed' }
+ )
+ end
- it 'shows error message and retries' do
+ it 'reads type from $stdin' do
expect($stdin).to receive(:gets).and_return(type)
- expect($stdin).to receive(:gets).and_raise('EOF')
-
expect do
- expect { described_class.read_type }.to raise_error(/EOF/)
+ expect(described_class.read_type).to eq(:development)
end.to output(/specify the type/).to_stdout
- .and output(/Invalid type specified/).to_stderr
+ end
+
+ context 'when invalid type is given' do
+ let(:type) { 'invalid' }
+
+ it 'shows error message and retries' do
+ expect($stdin).to receive(:gets).and_return(type)
+ expect($stdin).to receive(:gets).and_raise('EOF')
+
+ expect do
+ expect { described_class.read_type }.to raise_error(/EOF/)
+ end.to output(/specify the type/).to_stdout
+ .and output(/Invalid type specified/).to_stderr
+ end
end
end
end
@@ -162,15 +183,51 @@ RSpec.describe 'bin/feature-flag' do
end
end
- describe '.rollout_issue_url' do
+ describe '.read_introduced_by_url' do
+ let(:url) { 'https://merge-request' }
+
+ it 'reads type from $stdin' do
+ expect($stdin).to receive(:gets).and_return(url)
+ expect do
+ expect(described_class.read_introduced_by_url).to eq('https://merge-request')
+ end.to output(/can you paste the URL here/).to_stdout
+ end
+
+ context 'empty URL given' do
+ let(:url) { '' }
+
+ it 'skips entry' do
+ expect($stdin).to receive(:gets).and_return(url)
+ expect do
+ expect(described_class.read_introduced_by_url).to be_nil
+ end.to output(/can you paste the URL here/).to_stdout
+ end
+ end
+
+ context 'invalid URL given' do
+ let(:url) { 'invalid' }
+
+ it 'shows error message and retries' do
+ expect($stdin).to receive(:gets).and_return(url)
+ expect($stdin).to receive(:gets).and_raise('EOF')
+
+ expect do
+ expect { described_class.read_introduced_by_url }.to raise_error(/EOF/)
+ end.to output(/can you paste the URL here/).to_stdout
+ .and output(/URL needs to start with/).to_stderr
+ end
+ end
+ end
+
+ describe '.read_rollout_issue_url' do
let(:options) { OpenStruct.new(name: 'foo', type: :development) }
let(:url) { 'https://issue' }
it 'reads type from $stdin' do
expect($stdin).to receive(:gets).and_return(url)
expect do
- expect(described_class.read_issue_url(options)).to eq('https://issue')
- end.to output(/Paste URL here/).to_stdout
+ expect(described_class.read_rollout_issue_url(options)).to eq('https://issue')
+ end.to output(/Paste URL of `rollout issue` here/).to_stdout
end
context 'invalid URL given' do
@@ -181,8 +238,8 @@ RSpec.describe 'bin/feature-flag' do
expect($stdin).to receive(:gets).and_raise('EOF')
expect do
- expect { described_class.read_issue_url(options) }.to raise_error(/EOF/)
- end.to output(/Paste URL here/).to_stdout
+ expect { described_class.read_rollout_issue_url(options) }.to raise_error(/EOF/)
+ end.to output(/Paste URL of `rollout issue` here/).to_stdout
.and output(/URL needs to start/).to_stderr
end
end