diff options
Diffstat (limited to 'spec/services/git')
-rw-r--r-- | spec/services/git/branch_hooks_service_spec.rb | 83 | ||||
-rw-r--r-- | spec/services/git/wiki_push_service_spec.rb | 50 |
2 files changed, 130 insertions, 3 deletions
diff --git a/spec/services/git/branch_hooks_service_spec.rb b/spec/services/git/branch_hooks_service_spec.rb index a5290f0be68..bf2a7390258 100644 --- a/spec/services/git/branch_hooks_service_spec.rb +++ b/spec/services/git/branch_hooks_service_spec.rb @@ -93,12 +93,12 @@ RSpec.describe Git::BranchHooksService do describe 'Push Event' do let(:event) { Event.pushed_action.first } - before do - service.execute - end + subject(:execute_service) { service.execute } context "with an existing branch" do it 'generates a push event with one commit' do + execute_service + expect(event).to be_an_instance_of(PushEvent) expect(event.project).to eq(project) expect(event).to be_pushed_action @@ -109,12 +109,87 @@ RSpec.describe Git::BranchHooksService do expect(event.push_event_payload.ref).to eq('master') expect(event.push_event_payload.commit_count).to eq(1) end + + context 'with changing CI config' do + before do + allow_next_instance_of(Gitlab::Git::Diff) do |diff| + allow(diff).to receive(:new_path).and_return('.gitlab-ci.yml') + end + + allow(Gitlab::UsageDataCounters::HLLRedisCounter).to receive(:track_event) + end + + let!(:commit_author) { create(:user, email: sample_commit.author_email) } + + let(:tracking_params) do + ['o_pipeline_authoring_unique_users_committing_ciconfigfile', values: commit_author.id] + end + + it 'tracks the event' do + execute_service + + expect(Gitlab::UsageDataCounters::HLLRedisCounter) + .to have_received(:track_event).with(*tracking_params) + end + + context 'when the FF usage_data_unique_users_committing_ciconfigfile is disabled' do + before do + stub_feature_flags(usage_data_unique_users_committing_ciconfigfile: false) + end + + it 'does not track the event' do + execute_service + + expect(Gitlab::UsageDataCounters::HLLRedisCounter) + .not_to have_received(:track_event).with(*tracking_params) + end + end + + context 'when usage ping is disabled' do + before do + stub_application_setting(usage_ping_enabled: false) + end + + it 'does not track the event' do + execute_service + + expect(Gitlab::UsageDataCounters::HLLRedisCounter) + .not_to have_received(:track_event).with(*tracking_params) + end + end + + context 'when the branch is not the main branch' do + let(:branch) { 'feature' } + + it 'does not track the event' do + execute_service + + expect(Gitlab::UsageDataCounters::HLLRedisCounter) + .not_to have_received(:track_event).with(*tracking_params) + end + end + + context 'when the CI config is a different path' do + before do + project.ci_config_path = 'config/ci.yml' + end + + it 'does not track the event' do + execute_service + + expect(Gitlab::UsageDataCounters::HLLRedisCounter) + .not_to have_received(:track_event).with(*tracking_params) + end + end + end end context "with a new branch" do let(:oldrev) { Gitlab::Git::BLANK_SHA } it 'generates a push event with more than one commit' do + execute_service + expect(event).to be_an_instance_of(PushEvent) expect(event.project).to eq(project) expect(event).to be_pushed_action @@ -131,6 +206,8 @@ RSpec.describe Git::BranchHooksService do let(:newrev) { Gitlab::Git::BLANK_SHA } it 'generates a push event with no commits' do + execute_service + expect(event).to be_an_instance_of(PushEvent) expect(event.project).to eq(project) expect(event).to be_pushed_action diff --git a/spec/services/git/wiki_push_service_spec.rb b/spec/services/git/wiki_push_service_spec.rb index cd38f2e97fb..0431e06723f 100644 --- a/spec/services/git/wiki_push_service_spec.rb +++ b/spec/services/git/wiki_push_service_spec.rb @@ -257,6 +257,56 @@ RSpec.describe Git::WikiPushService, services: true do end end + describe '#perform_housekeeping', :clean_gitlab_redis_shared_state do + let(:housekeeping) { Repositories::HousekeepingService.new(wiki) } + + subject { create_service(current_sha).execute } + + before do + allow(Repositories::HousekeepingService).to receive(:new).and_return(housekeeping) + end + + it 'does not perform housekeeping when not needed' do + expect(housekeeping).not_to receive(:execute) + + subject + end + + context 'when housekeeping is needed' do + before do + allow(housekeeping).to receive(:needed?).and_return(true) + end + + it 'performs housekeeping' do + expect(housekeeping).to receive(:execute) + + subject + end + + it 'does not raise an exception' do + allow(housekeeping).to receive(:try_obtain_lease).and_return(false) + + expect { subject }.not_to raise_error + end + + context 'when feature flag :wiki_housekeeping is disabled' do + it 'does not perform housekeeping' do + stub_feature_flags(wiki_housekeeping: false) + + expect(housekeeping).not_to receive(:execute) + + subject + end + end + end + + it 'increments the push counter' do + expect(housekeeping).to receive(:increment!) + + subject + end + end + # In order to construct the correct GitPostReceive object that represents the # changes we are applying, we need to describe the changes between old-ref and # new-ref. Old ref (the base sha) we have to capture before we perform any |