Skip to content
代码片段 群组 项目
提交 2cc04c0b 编辑于 作者: Lin Jen-Shin's avatar Lin Jen-Shin
浏览文件

Make sure we cover all the code paths

上级 94c24c3e
No related branches found
No related tags found
无相关合并请求
......@@ -3,22 +3,24 @@
require_relative '../../../../tooling/lib/tooling/find_codeowners'
RSpec.describe Tooling::FindCodeowners do
describe '#execute' do
let(:subject) { described_class.new }
let(:subject) { described_class.new }
describe '#execute' do
before do
allow(subject).to receive(:git_ls_files).and_return(<<~LINES)
dir/0/0/0
dir/0/0/2
dir/0/0/2/0
dir/0/0/2/2
dir/0/0/3
dir/0/1
dir/1
dir/2
LINES
find_results = {
'dir/0/0' => "dir/0/0\ndir/0/0/0\ndir/0/0/2\n",
'dir/0' => "dir/0\ndir/0/0/0\ndir/0/0/2\ndir/0/1\n",
'dir' => "dir\ndir/0/0/0\ndir/0/0/2\ndir/0/1\ndir/1\ndir/2\n"
'dir/0/0/2' => "dir/0/0/2\ndir/0/0/2/0\ndir/0/0/2/2\n",
'dir/0/0' => "dir/0/0\ndir/0/0/2\ndir/0/0/3\n",
'dir/0' => "dir/0\ndir/0/0\ndir/0/1\n",
'dir' => "dir\ndir/0\ndir/1\ndir/2\n"
}
allow(subject).to receive(:find_dir_maxdepth_1) do |dir|
......@@ -52,7 +54,7 @@
describe '#load_definitions' do
it 'expands the allow and deny list with keywords and patterns' do
described_class.new.__send__(:load_definitions).each do |section, group_defintions|
subject.__send__(:load_definitions).each do |section, group_defintions|
group_defintions.each do |group, definitions|
expect(definitions[:allow]).to be_an(Array)
expect(definitions[:deny]).to be_an(Array)
......@@ -61,7 +63,7 @@
end
it 'expands the auth group' do
auth = described_class.new.__send__(:load_definitions).dig(
auth = subject.__send__(:load_definitions).dig(
:'[Authentication and Authorization]',
:'@gitlab-org/manage/authentication-and-authorization')
......@@ -96,11 +98,35 @@
describe '#load_config' do
it 'loads the config with symbolized keys' do
config = described_class.new.__send__(:load_config)
config = subject.__send__(:load_config)
expect_hash_keys_to_be_symbols(config)
end
context 'when YAML has safe_load_file' do
before do
allow(YAML).to receive(:respond_to?).with(:safe_load_file).and_return(true)
end
it 'calls safe_load_file' do
expect(YAML).to receive(:safe_load_file)
subject.__send__(:load_config)
end
end
context 'when YAML does not have safe_load_file' do
before do
allow(YAML).to receive(:respond_to?).with(:safe_load_file).and_return(false)
end
it 'calls load_file' do
expect(YAML).to receive(:safe_load)
subject.__send__(:load_config)
end
end
def expect_hash_keys_to_be_symbols(object)
if object.is_a?(Hash)
object.each do |key, value|
......@@ -122,13 +148,11 @@ def expect_hash_keys_to_be_symbols(object)
expect(File).to receive(:fnmatch?).with(pattern, path, expected_flags)
described_class.new.__send__(:path_matches?, pattern, path)
subject.__send__(:path_matches?, pattern, path)
end
end
describe '#consolidate_paths' do
let(:subject) { described_class.new }
before do
allow(subject).to receive(:find_dir_maxdepth_1).and_return(<<~LINES)
dir
......@@ -159,4 +183,20 @@ def expect_hash_keys_to_be_symbols(object)
end
end
end
describe '#find_dir_maxdepth_1' do
it 'calls `find dir -maxdepth 1`' do
expect(subject).to receive(:`).with('find tmp -maxdepth 1').and_call_original
subject.__send__(:find_dir_maxdepth_1, 'tmp')
end
end
describe '#git_ls_files' do
it 'calls `git ls-files`' do
expect(subject).to receive(:`).with('git ls-files').and_call_original
subject.__send__(:git_ls_files)
end
end
end
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册