summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Thomas <nick@gitlab.com>2018-03-13 13:52:42 +0000
committerNick Thomas <nick@gitlab.com>2018-03-13 13:52:42 +0000
commit385c981760d236b269a790defc84f7e184943d3a (patch)
tree11324b5ed992705def4820456439bb6ad8c69a66
parent77524085f5d4fe3e174589499a038d5bb42ea364 (diff)
parenta9e4f68d299222070f0c25af65f94419c9c233a6 (diff)
downloadgitlab-shell-385c981760d236b269a790defc84f7e184943d3a.tar.gz
Merge branch 'fix-tests' into 'master'
Fix tests that fail locally See merge request gitlab-org/gitlab-shell!196
-rw-r--r--spec/gitlab_shell_authorized_keys_check_spec.rb30
-rw-r--r--spec/httpunix_spec.rb4
2 files changed, 22 insertions, 12 deletions
diff --git a/spec/gitlab_shell_authorized_keys_check_spec.rb b/spec/gitlab_shell_authorized_keys_check_spec.rb
index 166e675..30237e0 100644
--- a/spec/gitlab_shell_authorized_keys_check_spec.rb
+++ b/spec/gitlab_shell_authorized_keys_check_spec.rb
@@ -1,21 +1,27 @@
require_relative 'spec_helper'
describe 'bin/gitlab-shell-authorized-keys-check' do
- def config_path
- File.join(ROOT_PATH, 'config.yml')
+ def original_root_path
+ ROOT_PATH
end
- def tmp_config_path
- config_path + ".#{$$}"
+ def tmp_root_path
+ @tmp_root_path ||= File.realpath(Dir.mktmpdir)
+ end
+
+ def config_path
+ File.join(tmp_root_path, 'config.yml')
end
def tmp_socket_path
- File.join(ROOT_PATH, 'tmp', 'gitlab-shell-authorized-keys-check-socket')
+ # This has to be a relative path shorter than 100 bytes due to
+ # limitations in how Unix sockets work.
+ 'tmp/gitlab-shell-authorized-keys-check-socket'
end
before(:all) do
FileUtils.mkdir_p(File.dirname(tmp_socket_path))
- FileUtils.touch(File.join(ROOT_PATH, '.gitlab_shell_secret'))
+ FileUtils.touch(File.join(tmp_root_path, '.gitlab_shell_secret'))
@server = HTTPUNIXServer.new(BindAddress: tmp_socket_path)
@server.mount_proc('/api/v4/internal/authorized_keys') do |req, res|
@@ -33,21 +39,23 @@ describe 'bin/gitlab-shell-authorized-keys-check' do
sleep(0.1) while @webrick_thread.alive? && @server.status != :Running
raise "Couldn't start stub GitlabNet server" unless @server.status == :Running
- FileUtils.mv(config_path, tmp_config_path) if File.exist?(config_path)
File.open(config_path, 'w') do |f|
f.write("---\ngitlab_url: http+unix://#{CGI.escape(tmp_socket_path)}\n")
end
+
+ copy_dirs = ['bin', 'lib']
+ FileUtils.rm_rf(copy_dirs.map { |d| File.join(tmp_root_path, d) })
+ FileUtils.cp_r(copy_dirs, tmp_root_path)
end
after(:all) do
@server.shutdown if @server
@webrick_thread.join if @webrick_thread
- FileUtils.rm_f(config_path)
- FileUtils.mv(tmp_config_path, config_path) if File.exist?(tmp_config_path)
+ FileUtils.rm_rf(tmp_root_path)
end
- let(:gitlab_shell_path) { File.join(ROOT_PATH, 'bin', 'gitlab-shell') }
- let(:authorized_keys_check_path) { File.join(ROOT_PATH, 'bin', 'gitlab-shell-authorized-keys-check') }
+ let(:gitlab_shell_path) { File.join(tmp_root_path, 'bin', 'gitlab-shell') }
+ let(:authorized_keys_check_path) { File.join(tmp_root_path, 'bin', 'gitlab-shell-authorized-keys-check') }
it 'succeeds when a valid key is given' do
output, status = run!
diff --git a/spec/httpunix_spec.rb b/spec/httpunix_spec.rb
index 4c59340..b49bc0a 100644
--- a/spec/httpunix_spec.rb
+++ b/spec/httpunix_spec.rb
@@ -15,7 +15,9 @@ end
describe Net::HTTPUNIX do
def tmp_socket_path
- File.join(ROOT_PATH, 'tmp/test-socket')
+ # This has to be a relative path shorter than 100 bytes due to
+ # limitations in how Unix sockets work.
+ 'tmp/test-socket'
end
before(:all) do