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
path: root/qa
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-12-22 09:07:06 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-12-22 09:07:06 +0300
commit968a9dd39b77628b541e0788488bad2493fefbee (patch)
tree328ed8019fc823d7a6a129d61700d6e5ad91dbb7 /qa
parent202fdd6ddfa47e69e5ac74853dc0deb51c9be36a (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'qa')
-rw-r--r--qa/qa/service/docker_run/smocker.rb14
-rw-r--r--qa/spec/service/docker_run/smocker_spec.rb67
2 files changed, 75 insertions, 6 deletions
diff --git a/qa/qa/service/docker_run/smocker.rb b/qa/qa/service/docker_run/smocker.rb
index da01b4a5223..cd69d8771e1 100644
--- a/qa/qa/service/docker_run/smocker.rb
+++ b/qa/qa/service/docker_run/smocker.rb
@@ -41,9 +41,7 @@ module QA
attr_reader :public_port, :admin_port
def host_name
- @host_name ||= if QA::Runtime::Env.running_in_ci? || QA::Runtime::Env.qa_hostname
- return host_ip if gdk_network
-
+ @host_name ||= if qa_environment? && !gdk_network && @network_cache != 'bridge'
"#{@name}.#{@network_cache}"
else
host_ip
@@ -67,12 +65,16 @@ module QA
#{@image}
CMD
- unless QA::Runtime::Env.running_in_ci? || QA::Runtime::Env.qa_hostname
- command.gsub!("--network #{@network_cache} ", '')
- end
+ command.gsub!("--network #{@network_cache} ", '') unless qa_environment?
shell command
end
+
+ private
+
+ def qa_environment?
+ QA::Runtime::Env.running_in_ci? || QA::Runtime::Env.qa_hostname
+ end
end
end
end
diff --git a/qa/spec/service/docker_run/smocker_spec.rb b/qa/spec/service/docker_run/smocker_spec.rb
new file mode 100644
index 00000000000..0017ee48e95
--- /dev/null
+++ b/qa/spec/service/docker_run/smocker_spec.rb
@@ -0,0 +1,67 @@
+# frozen_string_literal: true
+
+module QA
+ RSpec.describe Service::DockerRun::Smocker do
+ let(:name) { 'smocker-12345' }
+ let(:network) { 'thenet' }
+ let(:host_ip) { '1.2.3.4' }
+
+ subject(:smocker_container) { described_class.new(name: name) }
+
+ before do
+ # rubocop:disable RSpec/AnyInstanceOf -- allow_next_instance_of relies on gitlab/rspec
+ allow_any_instance_of(described_class).to receive(:network).and_return(network)
+ # rubocop:enable RSpec/AnyInstanceOf
+
+ allow(smocker_container).to receive(:host_ip).and_return(host_ip)
+ end
+
+ describe '#host_name' do
+ shared_examples 'returns host ip' do
+ it 'returns host ip' do
+ expect(smocker_container.host_name).to eq(host_ip)
+ end
+ end
+
+ shared_examples 'returns name.network' do
+ it 'returns name.network' do
+ expect(smocker_container.host_name).to eq("#{name}.#{network}")
+ end
+ end
+
+ context 'when running in CI' do
+ before do
+ allow(Runtime::Env).to receive(:running_in_ci?).and_return(true)
+ end
+
+ context 'when network is not bridge' do
+ it_behaves_like 'returns name.network'
+ end
+
+ context 'when network is bridge' do
+ let(:network) { 'bridge' }
+
+ it_behaves_like 'returns host ip'
+ end
+ end
+
+ context 'when running not in CI' do
+ before do
+ allow(Runtime::Env).to receive(:running_in_ci?).and_return(false)
+ end
+
+ context 'when QA hostname is not set' do
+ it_behaves_like 'returns host ip'
+ end
+
+ context 'when QA hostname is set' do
+ before do
+ allow(Runtime::Env).to receive(:qa_hostname).and_return('qa-hostname')
+ end
+
+ it_behaves_like 'returns name.network'
+ end
+ end
+ end
+ end
+end