How to test Gitaly while it is optional in gitlab
There are tests that need to work with gitaly on and off:
For example, from spec/models/repository_spec.rb
:
describe '#branch_names_contains' do
subject { repository.branch_names_contains(sample_commit.id) }
it { is_expected.to include('master') }
it { is_expected.not_to include('feature') }
it { is_expected.not_to include('fix') }
end
When https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/9291 gets merged, depending on the value of Gitlab::GitalyClient.feature_enabled?
for the test environment (which depends in turn on ENV
variables), that test will rely on a) Gitlab::Git::Repository, or b)
Gitlab::GitalyClient::Ref`.
Other tests like
describe '#root_ref' do
it 'caches the output' do
expect(repository.raw_repository).to receive(:root_ref).
once.
and_return('master')
repository.root_ref
repository.root_ref
end
end
directly reference the underlying component, so they would have to be changed to two cases, one which references Gitlab::Git::Repository
, and another which references Gitlab::GitalyClient::Ref
.