From aec34658b08715933f1379f1346beee354d4a324 Mon Sep 17 00:00:00 2001 From: Dylan Griffith <dyl.griffith@gmail.com> Date: Sun, 7 Apr 2024 08:40:34 -0700 Subject: [PATCH] Add spec for housekeeper --target-branch This adds the test coverage for the feature added in the earlier commit. --- .../spec/gitlab/housekeeper/runner_spec.rb | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/gems/gitlab-housekeeper/spec/gitlab/housekeeper/runner_spec.rb b/gems/gitlab-housekeeper/spec/gitlab/housekeeper/runner_spec.rb index 6acbf64a45d83..c9495855a28ee 100644 --- a/gems/gitlab-housekeeper/spec/gitlab/housekeeper/runner_spec.rb +++ b/gems/gitlab-housekeeper/spec/gitlab/housekeeper/runner_spec.rb @@ -135,6 +135,36 @@ expect(change2.keep_class).to eq(fake_keep) end + context 'when given target_branch' do + it 'branches from that target branch' do + # Branches get created + expect(::Gitlab::Housekeeper::Git).to receive(:new) + .with(logger: anything, branch_from: 'the-target-branch') + .and_return(git) + + # Branches get shown and pushed + expect(::Gitlab::Housekeeper::Shell).to receive(:execute) + .with('git', '--no-pager', 'diff', '--color=always', 'the-target-branch', + 'the-identifier-for-the-first-change', '--', 'change1.txt', 'change2.txt') + + # Merge requests get created + expect(gitlab_client).to receive(:create_or_update_merge_request) + .with( + change: change1, + source_project_id: '123', + source_branch: 'the-identifier-for-the-first-change', + target_branch: 'the-target-branch', + target_project_id: '456', + update_title: true, + update_description: true, + update_labels: true, + update_reviewers: true + ).twice.and_return({ 'web_url' => 'https://example.com' }) + + described_class.new(max_mrs: 1, keeps: [fake_keep], target_branch: 'the-target-branch').run + end + end + context 'when given filter_identifiers' do it 'skips a change that does not match the filter_identifiers' do # Branches get created -- GitLab