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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'qa/spec/support')
-rw-r--r--qa/spec/support/repeater_spec.rb2
-rw-r--r--qa/spec/support/retrier_spec.rb2
-rw-r--r--qa/spec/support/run_spec.rb27
-rw-r--r--qa/spec/support/ssh_spec.rb114
-rw-r--r--qa/spec/support/wait_for_requests_spec.rb3
-rw-r--r--qa/spec/support/waiter_spec.rb2
6 files changed, 145 insertions, 5 deletions
diff --git a/qa/spec/support/repeater_spec.rb b/qa/spec/support/repeater_spec.rb
index b5d5058ef49..18ccbf250cb 100644
--- a/qa/spec/support/repeater_spec.rb
+++ b/qa/spec/support/repeater_spec.rb
@@ -4,7 +4,7 @@ require 'logger'
require 'timecop'
require 'active_support/core_ext/integer/time'
-describe QA::Support::Repeater do
+RSpec.describe QA::Support::Repeater do
before do
logger = ::Logger.new $stdout
logger.level = ::Logger::DEBUG
diff --git a/qa/spec/support/retrier_spec.rb b/qa/spec/support/retrier_spec.rb
index ef1d53e6b65..6f052519516 100644
--- a/qa/spec/support/retrier_spec.rb
+++ b/qa/spec/support/retrier_spec.rb
@@ -3,7 +3,7 @@
require 'logger'
require 'timecop'
-describe QA::Support::Retrier do
+RSpec.describe QA::Support::Retrier do
before do
logger = ::Logger.new $stdout
logger.level = ::Logger::DEBUG
diff --git a/qa/spec/support/run_spec.rb b/qa/spec/support/run_spec.rb
new file mode 100644
index 00000000000..62eed71012e
--- /dev/null
+++ b/qa/spec/support/run_spec.rb
@@ -0,0 +1,27 @@
+# frozen_string_literal: true
+
+RSpec.describe QA::Support::Run do
+ let(:class_instance) { (Class.new { include QA::Support::Run }).new }
+ let(:response) { 'successful response' }
+ let(:command) { 'some command' }
+ let(:expected_result) { described_class::Result.new("#{command} 2>&1", 0, response) }
+
+ it 'runs successfully' do
+ expect(Open3).to receive(:capture2e).and_return([+response, double(exitstatus: 0)])
+
+ expect(class_instance.run(command)).to eq(expected_result)
+ end
+
+ it 'retries twice and succeeds the third time' do
+ allow(Open3).to receive(:capture2e).and_return([+'', double(exitstatus: 1)]).twice
+ allow(Open3).to receive(:capture2e).and_return([+response, double(exitstatus: 0)])
+
+ expect(class_instance.run(command)).to eq(expected_result)
+ end
+
+ it 'raises an exception on 3rd failure' do
+ allow(Open3).to receive(:capture2e).and_return([+'FAILURE', double(exitstatus: 1)]).thrice
+
+ expect { class_instance.run(command) }.to raise_error(QA::Support::Run::CommandError, /The command .* failed \(1\) with the following output:\nFAILURE/)
+ end
+end
diff --git a/qa/spec/support/ssh_spec.rb b/qa/spec/support/ssh_spec.rb
new file mode 100644
index 00000000000..f4d382f8adc
--- /dev/null
+++ b/qa/spec/support/ssh_spec.rb
@@ -0,0 +1,114 @@
+# frozen_string_literal: true
+
+RSpec.describe QA::Support::SSH do
+ let(:key) { Struct.new(:private_key).new('private_key') }
+ let(:known_hosts_file) { Tempfile.new('known_hosts_file') }
+ let(:private_key_file) { Tempfile.new('private_key_file') }
+ let(:result) { QA::Support::Run::Result.new('', 0, '') }
+
+ let(:ssh) do
+ described_class.new.tap do |ssh|
+ ssh.uri = uri
+ ssh.key = key
+ ssh.private_key_file = private_key_file
+ ssh.known_hosts_file = known_hosts_file
+ end
+ end
+
+ shared_examples 'providing correct ports' do
+ context 'when no port specified in uri' do
+ let(:uri) { 'http://foo.com' }
+
+ it 'does not provide port in ssh command' do
+ expect(ssh).to receive(:run).with(expected_ssh_command_no_port, any_args).and_return(result)
+
+ call_method
+ end
+ end
+
+ context 'when port 80 specified in uri' do
+ let(:uri) { 'http://foo.com:80' }
+
+ it 'does not provide port in ssh command' do
+ expect(ssh).to receive(:run).with(expected_ssh_command_no_port, any_args).and_return(result)
+
+ call_method
+ end
+ end
+
+ context 'when other port is specified in uri' do
+ let(:port) { 1234 }
+ let(:uri) { "http://foo.com:#{port}" }
+
+ it "provides other port in ssh command" do
+ expect(ssh).to receive(:run).with(expected_ssh_command_port, any_args).and_return(result)
+
+ call_method
+ end
+ end
+ end
+
+ describe '#setup' do
+ let(:expected_ssh_command_no_port) { "ssh-keyscan -H foo.com >> #{known_hosts_file.path}" }
+ let(:expected_ssh_command_port) { "ssh-keyscan -H -p #{port} foo.com >> #{known_hosts_file.path}" }
+ let(:call_method) { ssh.setup }
+
+ before do
+ allow(File).to receive(:binwrite).with(private_key_file, key.private_key)
+ allow(File).to receive(:chmod).with(0700, private_key_file)
+ end
+
+ it_behaves_like 'providing correct ports'
+ end
+
+ describe '#reset_2fa_codes' do
+ let(:expected_ssh_command_no_port) { "echo yes | ssh -i #{private_key_file.path} -o UserKnownHostsFile=#{known_hosts_file.path} git@foo.com 2fa_recovery_codes" }
+ let(:expected_ssh_command_port) { "echo yes | ssh -i #{private_key_file.path} -o UserKnownHostsFile=#{known_hosts_file.path} git@foo.com -p #{port} 2fa_recovery_codes" }
+ let(:call_method) { ssh.reset_2fa_codes }
+
+ before do
+ allow(ssh).to receive(:git_user).and_return('git')
+ end
+
+ it_behaves_like 'providing correct ports'
+ end
+
+ describe '#git_user' do
+ context 'when running on CI' do
+ let(:uri) { 'http://gitlab.com' }
+
+ before do
+ allow(QA::Runtime::Env).to receive(:running_in_ci?).and_return(true)
+ end
+
+ it 'returns git user' do
+ expect(ssh.send(:git_user)).to eq('git')
+ end
+ end
+
+ context 'when running against environment on a port other than 80 or 443' do
+ let(:uri) { 'http://localhost:3000' }
+
+ before do
+ allow(Etc).to receive(:getlogin).and_return('dummy_username')
+ allow(QA::Runtime::Env).to receive(:running_in_ci?).and_return(false)
+ end
+
+ it 'returns the local user' do
+ expect(ssh.send(:git_user)).to eq('dummy_username')
+ end
+ end
+
+ context 'when running against environment on port 80 and not on CI (docker)' do
+ let(:uri) { 'http://localhost' }
+
+ before do
+ allow(QA::Runtime::Env).to receive(:running_in_ci?).and_return(false)
+ end
+
+ it 'returns git user' do
+ expect(ssh.send(:git_user)).to eq('git')
+ end
+ end
+ end
+end
diff --git a/qa/spec/support/wait_for_requests_spec.rb b/qa/spec/support/wait_for_requests_spec.rb
index 79ee3eb5099..47c35addd9f 100644
--- a/qa/spec/support/wait_for_requests_spec.rb
+++ b/qa/spec/support/wait_for_requests_spec.rb
@@ -1,9 +1,8 @@
# frozen_string_literal: true
-describe QA::Support::WaitForRequests do
+RSpec.describe QA::Support::WaitForRequests do
describe '.wait_for_requests' do
before do
- allow(subject).to receive(:finished_all_axios_requests?).and_return(true)
allow(subject).to receive(:finished_all_ajax_requests?).and_return(true)
allow(subject).to receive(:finished_loading?).and_return(true)
end
diff --git a/qa/spec/support/waiter_spec.rb b/qa/spec/support/waiter_spec.rb
index 35f1e01289a..5b0c2c95d0d 100644
--- a/qa/spec/support/waiter_spec.rb
+++ b/qa/spec/support/waiter_spec.rb
@@ -2,7 +2,7 @@
require 'logger'
-describe QA::Support::Waiter do
+RSpec.describe QA::Support::Waiter do
before do
logger = ::Logger.new $stdout
logger.level = ::Logger::DEBUG