diff options
author | Sean McGivern <sean@mcgivern.me.uk> | 2018-03-05 14:16:17 +0300 |
---|---|---|
committer | Micaƫl Bergeron <mbergeron@gitlab.com> | 2018-03-08 18:20:40 +0300 |
commit | edbcde8877f497ea675fde811065679286a1aa56 (patch) | |
tree | beefe40d469f06fc72f2513f73b336115b0f6144 /spec/support | |
parent | 2387ef2b4a9944749f0cd1db5c7e7f55f3745780 (diff) |
[cherry-pick] '4862-verify-file-checksums'
See merge request gitlab-org/gitlab-ee!4753
Diffstat (limited to 'spec/support')
-rw-r--r-- | spec/support/gitlab_verify.rb | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/spec/support/gitlab_verify.rb b/spec/support/gitlab_verify.rb new file mode 100644 index 00000000000..13e2e37624d --- /dev/null +++ b/spec/support/gitlab_verify.rb @@ -0,0 +1,45 @@ +RSpec.shared_examples 'Gitlab::Verify::BatchVerifier subclass' do + describe 'batching' do + let(:first_batch) { objects[0].id..objects[0].id } + let(:second_batch) { objects[1].id..objects[1].id } + let(:third_batch) { objects[2].id..objects[2].id } + + it 'iterates through objects in batches' do + expect(collect_ranges).to eq([first_batch, second_batch, third_batch]) + end + + it 'allows the starting ID to be specified' do + expect(collect_ranges(start: second_batch.first)).to eq([second_batch, third_batch]) + end + + it 'allows the finishing ID to be specified' do + expect(collect_ranges(finish: second_batch.last)).to eq([first_batch, second_batch]) + end + end +end + +module GitlabVerifyHelpers + def collect_ranges(args = {}) + verifier = described_class.new(args.merge(batch_size: 1)) + + collect_results(verifier).map { |range, _| range } + end + + def collect_failures + verifier = described_class.new(batch_size: 1) + + out = {} + + collect_results(verifier).map { |_, failures| out.merge!(failures) } + + out + end + + def collect_results(verifier) + out = [] + + verifier.run_batches { |*args| out << args } + + out + end +end |