diff options
| author | Douwe Maan <douwe@gitlab.com> | 2018-12-13 10:23:17 +0000 |
|---|---|---|
| committer | Douwe Maan <douwe@gitlab.com> | 2018-12-13 10:23:17 +0000 |
| commit | df89099ed954a6673bb8388ef74480940d40a759 (patch) | |
| tree | c3db905b0890895303b2f1ca91f3ac02664ce48a /spec | |
| parent | 528960c801aed81a977e7ce58a9706b4ea32ab4a (diff) | |
| parent | 46e81d93ff74a98cf4f02735d310ee4417be0217 (diff) | |
| download | gitlab-shell-df89099ed954a6673bb8388ef74480940d40a759.tar.gz | |
Merge branch 'sh-bump-ruby-version' into 'master'
Upgrade to Ruby 2.5.3
See merge request gitlab-org/gitlab-shell!257
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/gitlab_keys_spec.rb | 14 | ||||
| -rw-r--r-- | spec/gitlab_logger_spec.rb | 8 | ||||
| -rw-r--r-- | spec/gitlab_net_spec.rb | 2 | ||||
| -rw-r--r-- | spec/gitlab_shell_gitlab_shell_spec.rb | 8 | ||||
| -rw-r--r-- | spec/vcr_cassettes/custom-action-ok-not-json.yml | 2 |
5 files changed, 22 insertions, 12 deletions
diff --git a/spec/gitlab_keys_spec.rb b/spec/gitlab_keys_spec.rb index f86d00d..c6be139 100644 --- a/spec/gitlab_keys_spec.rb +++ b/spec/gitlab_keys_spec.rb @@ -5,6 +5,8 @@ require 'stringio' describe GitlabKeys do before do $logger = double('logger').as_null_object + # The default 'auth_file' value from config.yml.example is '/home/git/.ssh/authorized_keys' + allow(GitlabConfig).to receive_message_chain(:new, :auth_file).and_return('/home/git/.ssh/authorized_keys') end describe '.command' do @@ -148,7 +150,9 @@ describe GitlabKeys do context "without file writing" do before do - expect(gitlab_keys).to receive(:open).and_yield(double(:file, puts: nil, chmod: nil)) + file = double(:file, puts: nil, chmod: nil, flock: nil) + expect(File).to receive(:open).with(tmp_authorized_keys_path + '.lock', 'w+').and_yield(file) + expect(File).to receive(:open).with(tmp_authorized_keys_path, "a", 0o600).and_yield(file) end it "should log an add-key event" do @@ -189,7 +193,8 @@ describe GitlabKeys do context "without file writing" do before do - allow(gitlab_keys).to receive(:open) + allow(File).to receive(:open).with("#{ROOT_PATH}/config.yml", 'r:bom|utf-8').and_call_original + allow(File).to receive(:open).with('/home/git/.ssh/authorized_keys', 'r+', 384) allow(gitlab_keys).to receive(:lock).and_yield end @@ -225,7 +230,8 @@ describe GitlabKeys do let(:gitlab_keys) { build_gitlab_keys('clear') } it "should return true" do - allow(gitlab_keys).to receive(:open) + allow(File).to receive(:open).with("#{ROOT_PATH}/config.yml", 'r:bom|utf-8').and_call_original + allow(File).to receive(:open).with('/home/git/.ssh/authorized_keys', 'w', 384) expect(gitlab_keys.send(:clear)).to be_truthy end end @@ -240,7 +246,7 @@ describe GitlabKeys do it 'returns false if opening raises an exception' do expect(gitlab_keys).to receive(:open_auth_file).and_raise("imaginary error") - expect(gitlab_keys.exec).to eq(false) + expect { expect(gitlab_keys.exec).to eq(false) }.to output(/imaginary error/).to_stdout end it 'creates the keys file if it does not exist' do diff --git a/spec/gitlab_logger_spec.rb b/spec/gitlab_logger_spec.rb index a9cd3fb..d5704c3 100644 --- a/spec/gitlab_logger_spec.rb +++ b/spec/gitlab_logger_spec.rb @@ -3,11 +3,13 @@ require_relative '../lib/gitlab_logger' require 'securerandom' describe :convert_log_level do - subject { convert_log_level :extreme } + it "returns desired Logger::<type>" do + expect(convert_log_level(:debug)).to eq(Logger::DEBUG) + end it "converts invalid log level to Logger::INFO" do - expect($stderr).to receive(:puts).at_least(:once) - is_expected.to eq(Logger::INFO) + expect { convert_log_level(:extreme) }.to output(/WARNING: Unrecognized log level :extreme. Falling back to INFO./).to_stderr + expect(convert_log_level(:extreme)).to eq(Logger::INFO) end end diff --git a/spec/gitlab_net_spec.rb b/spec/gitlab_net_spec.rb index 07b772b..564e5c0 100644 --- a/spec/gitlab_net_spec.rb +++ b/spec/gitlab_net_spec.rb @@ -67,7 +67,7 @@ describe GitlabNet, vcr: true do describe '#lfs_authenticate' do context 'lfs authentication succeeded' do - let(:repository_http_path) { URI.join(internal_api_endpoint.sub('api/v4', ''), project).to_s } + let(:repository_http_path) { URI.join(internal_api_endpoint.sub('/api/v4/internal', ''), project).to_s } context 'for download operation' do it 'should return the correct data' do diff --git a/spec/gitlab_shell_gitlab_shell_spec.rb b/spec/gitlab_shell_gitlab_shell_spec.rb index 9afeac8..e5342b7 100644 --- a/spec/gitlab_shell_gitlab_shell_spec.rb +++ b/spec/gitlab_shell_gitlab_shell_spec.rb @@ -1,4 +1,5 @@ require_relative 'spec_helper' +require 'open3' describe 'bin/gitlab-shell' do def original_root_path @@ -131,12 +132,13 @@ describe 'bin/gitlab-shell' do def run!(args) cmd = [ + 'SSH_CONNECTION=fake', gitlab_shell_path, args - ].flatten.compact + ].flatten.join(' ') - output = IO.popen({'SSH_CONNECTION' => 'fake'}, cmd, &:read) + stdout, _stderr, status = Open3.capture3(cmd) - [output, $?] + [stdout, status] end end diff --git a/spec/vcr_cassettes/custom-action-ok-not-json.yml b/spec/vcr_cassettes/custom-action-ok-not-json.yml index 3bfb390..405292d 100644 --- a/spec/vcr_cassettes/custom-action-ok-not-json.yml +++ b/spec/vcr_cassettes/custom-action-ok-not-json.yml @@ -46,6 +46,6 @@ http_interactions: - '1.436040' body: encoding: UTF-8 - string: '""' + string: '{' http_version: recorded_at: Fri, 20 Jul 2018 06:18:58 GMT |
