Skip to content
代码片段 群组 项目
提交 315bea33 编辑于 作者: Gabriel Mazetto's avatar Gabriel Mazetto
浏览文件

Add error handling to GitlabConfig

上级 2ee64cbe
No related branches found
No related tags found
无相关合并请求
......@@ -45,11 +45,21 @@ def initialize(source)
load!
end
def loaded?
@config.present?
end
private
def load!
yaml = ActiveSupport::ConfigurationFile.parse(@source)
all_configs = yaml.deep_stringify_keys
@config = all_configs
rescue Errno::ENOENT
Gitlab::Backup::Cli::Output.error "GitLab configuration file: #{@source} does not exist"
rescue Errno::EACCES
Gitlab::Backup::Cli::Output.error "GitLab configuration file: #{@source} can't be read (permission denied)"
end
end
end
......
......@@ -11,5 +11,34 @@
expect(gitlab_config.keys).to include('test')
end
end
context 'when provided with a filepath that doesnt exist' do
let(:config_fixture) { fixtures_path.join('unknown-gitlab.yml') }
it 'does not raise an exception', :silence_output do
expect { gitlab_config }.not_to raise_error
expect(gitlab_config).not_to be_loaded
end
it 'displays an error message' do
expect { gitlab_config }.to output(/GitLab configuration file: .+ does not exist/).to_stderr
end
end
context 'when process lack enough permission to read provided config file' do
before do
allow(ActiveSupport::ConfigurationFile).to receive(:parse).and_raise(Errno::EACCES)
end
it 'does not raise an exception', :silence_output do
expect { gitlab_config }.not_to raise_error
expect(gitlab_config).not_to be_loaded
end
it 'displays an error message' do
error_message_pattern = /GitLab configuration file: .+ can't be read \(permission denied\)/
expect { gitlab_config }.to output(error_message_pattern).to_stderr
end
end
end
end
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册