2019-11-21 04:06:16 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-11-19 10:03:58 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Gitlab::Git::RepositoryCleaner do
|
2018-12-15 08:49:15 -05:00
|
|
|
include HttpIOHelpers
|
|
|
|
|
2018-11-19 10:03:58 -05:00
|
|
|
let(:project) { create(:project, :repository) }
|
|
|
|
let(:repository) { project.repository }
|
|
|
|
let(:head_sha) { repository.head_commit.id }
|
2019-03-25 10:29:51 -04:00
|
|
|
let(:object_map_data) { "#{head_sha} #{Gitlab::Git::BLANK_SHA}" }
|
2018-11-19 10:03:58 -05:00
|
|
|
|
2019-03-25 10:29:51 -04:00
|
|
|
let(:clean_refs) { %W[refs/environments/1 refs/merge-requests/1 refs/keep-around/#{head_sha}] }
|
|
|
|
let(:keep_refs) { %w[refs/heads/_keep refs/tags/_keep] }
|
2018-11-19 10:03:58 -05:00
|
|
|
|
2019-03-25 10:29:51 -04:00
|
|
|
subject(:cleaner) { described_class.new(repository.raw) }
|
2018-12-15 08:49:15 -05:00
|
|
|
|
2019-03-25 10:29:51 -04:00
|
|
|
shared_examples_for '#apply_bfg_object_map_stream' do
|
2018-12-15 08:49:15 -05:00
|
|
|
before do
|
|
|
|
(clean_refs + keep_refs).each { |ref| repository.create_ref(head_sha, ref) }
|
|
|
|
end
|
|
|
|
|
2019-03-25 10:29:51 -04:00
|
|
|
it 'removes internal references' do
|
|
|
|
entries = []
|
2018-12-15 08:49:15 -05:00
|
|
|
|
2019-03-25 10:29:51 -04:00
|
|
|
cleaner.apply_bfg_object_map_stream(object_map) do |rsp|
|
|
|
|
entries.concat(rsp.entries)
|
|
|
|
end
|
2018-12-15 08:49:15 -05:00
|
|
|
|
2019-03-25 10:29:51 -04:00
|
|
|
aggregate_failures do
|
|
|
|
clean_refs.each { |ref| expect(repository.ref_exists?(ref)).to be(false) }
|
|
|
|
keep_refs.each { |ref| expect(repository.ref_exists?(ref)).to be(true) }
|
|
|
|
|
|
|
|
expect(entries).to contain_exactly(
|
|
|
|
Gitaly::ApplyBfgObjectMapStreamResponse::Entry.new(
|
|
|
|
type: :COMMIT,
|
|
|
|
old_oid: head_sha,
|
|
|
|
new_oid: Gitlab::Git::BLANK_SHA
|
|
|
|
)
|
|
|
|
)
|
2018-12-15 08:49:15 -05:00
|
|
|
end
|
|
|
|
end
|
2019-03-25 10:29:51 -04:00
|
|
|
end
|
2018-12-15 08:49:15 -05:00
|
|
|
|
2019-03-25 10:29:51 -04:00
|
|
|
describe '#apply_bfg_object_map_stream (from StringIO)' do
|
|
|
|
let(:object_map) { StringIO.new(object_map_data) }
|
2018-12-15 08:49:15 -05:00
|
|
|
|
2019-03-25 10:29:51 -04:00
|
|
|
include_examples '#apply_bfg_object_map_stream'
|
|
|
|
end
|
2018-12-15 08:49:15 -05:00
|
|
|
|
2019-03-25 10:29:51 -04:00
|
|
|
describe '#apply_bfg_object_map_stream (from Gitlab::HttpIO)' do
|
|
|
|
let(:url) { 'http://example.com/bfg_object_map.txt' }
|
|
|
|
let(:tempfile) { Tempfile.new }
|
|
|
|
let(:object_map) { Gitlab::HttpIO.new(url, object_map_data.size) }
|
2018-12-15 08:49:15 -05:00
|
|
|
|
2019-03-25 10:29:51 -04:00
|
|
|
around do |example|
|
|
|
|
tempfile.write(object_map_data)
|
|
|
|
tempfile.close
|
2018-12-15 08:49:15 -05:00
|
|
|
|
2019-03-25 10:29:51 -04:00
|
|
|
stub_remote_url_200(url, tempfile.path)
|
2018-12-15 08:49:15 -05:00
|
|
|
|
2019-03-25 10:29:51 -04:00
|
|
|
example.run
|
|
|
|
ensure
|
|
|
|
tempfile.unlink
|
2018-11-19 10:03:58 -05:00
|
|
|
end
|
2019-03-25 10:29:51 -04:00
|
|
|
|
|
|
|
include_examples '#apply_bfg_object_map_stream'
|
2018-11-19 10:03:58 -05:00
|
|
|
end
|
|
|
|
end
|