diff options
author | Sean McGivern <sean@gitlab.com> | 2016-07-29 17:17:06 +0300 |
---|---|---|
committer | Fatih Acet <acetfatih@gmail.com> | 2016-08-12 23:24:44 +0300 |
commit | 18398152fa4e5237a7b682d955457b12a7d59b31 (patch) | |
tree | c5d83e9dd8603ad923d6212045799984cecb8807 /spec/lib/gitlab/conflict | |
parent | f2f844693ecd8a10d48530adf8d59a7c125d2752 (diff) |
Raise errors for large and binary files
Diffstat (limited to 'spec/lib/gitlab/conflict')
-rw-r--r-- | spec/lib/gitlab/conflict/parser_spec.rb | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/spec/lib/gitlab/conflict/parser_spec.rb b/spec/lib/gitlab/conflict/parser_spec.rb index 1eda14f3e26..65a828accde 100644 --- a/spec/lib/gitlab/conflict/parser_spec.rb +++ b/spec/lib/gitlab/conflict/parser_spec.rb @@ -4,6 +4,10 @@ describe Gitlab::Conflict::Parser, lib: true do let(:parser) { Gitlab::Conflict::Parser.new } describe '#parse' do + def parse_text(text) + parser.parse(text, our_path: 'README.md', their_path: 'README.md') + end + context 'when the file has valid conflicts' do let(:text) do <<CONFLICT @@ -116,12 +120,6 @@ CONFLICT end context 'when the file contents include conflict delimiters' do - let(:path) { 'README.md' } - - def parse_text(text) - parser.parse(text, our_path: path, their_path: path) - end - it 'raises UnexpectedDelimiter when there is a non-start delimiter first' do expect { parse_text('=======') }. to raise_error(Gitlab::Conflict::Parser::UnexpectedDelimiter) @@ -172,9 +170,19 @@ CONFLICT end end - context 'when lines is blank' do - it { expect(parser.parse('', our_path: 'README.md', their_path: 'README.md')).to eq([]) } - it { expect(parser.parse(nil, our_path: 'README.md', their_path: 'README.md')).to eq([]) } + context 'other file types' do + it 'raises UnmergeableFile when lines is blank, indicating a binary file' do + expect { parse_text('') }. + to raise_error(Gitlab::Conflict::Parser::UnmergeableFile) + + expect { parse_text(nil) }. + to raise_error(Gitlab::Conflict::Parser::UnmergeableFile) + end + + it 'raises UnmergeableFile when the file is over 100 KB' do + expect { parse_text('a' * 102401) }. + to raise_error(Gitlab::Conflict::Parser::UnmergeableFile) + end end end end |