diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-07-08 15:08:58 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-07-08 15:08:58 +0000 |
commit | 6c346448fd3e3443e04d96b90b9bdf9df2be1a3e (patch) | |
tree | 89d7a1a52ea0a8c2a064af42870bf21b7722b96e /spec/lib | |
parent | b0d4724e47f94c9b1b2676382084ef964200e3c1 (diff) | |
download | gitlab-ce-6c346448fd3e3443e04d96b90b9bdf9df2be1a3e.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/gitlab/ci/runner_releases_spec.rb | 75 | ||||
-rw-r--r-- | spec/lib/gitlab/jira_import/issue_serializer_spec.rb | 6 | ||||
-rw-r--r-- | spec/lib/gitlab/jira_import/issues_importer_spec.rb | 19 |
3 files changed, 81 insertions, 19 deletions
diff --git a/spec/lib/gitlab/ci/runner_releases_spec.rb b/spec/lib/gitlab/ci/runner_releases_spec.rb index eb29629730c..95396a883fa 100644 --- a/spec/lib/gitlab/ci/runner_releases_spec.rb +++ b/spec/lib/gitlab/ci/runner_releases_spec.rb @@ -5,12 +5,14 @@ require 'spec_helper' RSpec.describe Gitlab::Ci::RunnerReleases do subject { described_class.instance } - describe '#releases' do + let(:runner_releases_url) { 'the release API URL' } + + describe '#releases', :use_clean_rails_memory_store_caching do before do - subject.reset! + subject.reset_backoff! - stub_application_setting(public_runner_releases_url: 'the release API URL') - allow(Gitlab::HTTP).to receive(:try_get).with('the release API URL').once { mock_http_response(response) } + stub_application_setting(public_runner_releases_url: runner_releases_url) + allow(Gitlab::HTTP).to receive(:try_get).with(runner_releases_url).once { mock_http_response(response) } end def releases @@ -40,7 +42,9 @@ RSpec.describe Gitlab::Ci::RunnerReleases do releases travel followup_request_interval do - expect(Gitlab::HTTP).to receive(:try_get).with('the release API URL').once { mock_http_response(followup_response) } + expect(Gitlab::HTTP).to receive(:try_get) + .with(runner_releases_url) + .once { mock_http_response(followup_response) } expect(releases).to eq((expected_result || []) + [Gitlab::VersionInfo.new(14, 9, 2)]) end @@ -62,14 +66,14 @@ RSpec.describe Gitlab::Ci::RunnerReleases do start_time = Time.now.utc.change(usec: 0) http_call_timestamp_offsets = [] - allow(Gitlab::HTTP).to receive(:try_get).with('the release API URL') do + allow(Gitlab::HTTP).to receive(:try_get).with(runner_releases_url) do http_call_timestamp_offsets << Time.now.utc - start_time mock_http_response(response) end # An initial HTTP request fails travel_to(start_time) - subject.reset! + subject.reset_backoff! expect(releases).to be_nil # Successive failed requests result in HTTP requests only after specific backoff periods @@ -86,7 +90,7 @@ RSpec.describe Gitlab::Ci::RunnerReleases do # Finally a successful HTTP request results in releases being returned allow(Gitlab::HTTP).to receive(:try_get) - .with('the release API URL') + .with(runner_releases_url) .once { mock_http_response([{ 'name' => 'v14.9.1-beta1-ee' }]) } travel 1.hour expect(releases).not_to be_nil @@ -109,13 +113,58 @@ RSpec.describe Gitlab::Ci::RunnerReleases do it_behaves_like 'requests that follow cache status', 1.day end - def mock_http_response(response) - http_response = instance_double(HTTParty::Response) + context 'when response contains unexpected input type' do + let(:response) { 'error' } + + it { expect(releases).to be_nil } + end + + context 'when response contains unexpected input array' do + let(:response) { ['error'] } + + it { expect(releases).to be_nil } + end + end + + describe '#expired?', :use_clean_rails_memory_store_caching do + def expired? + described_class.instance.expired? + end - allow(http_response).to receive(:success?).and_return(response.present?) - allow(http_response).to receive(:parsed_response).and_return(response) + before do + stub_application_setting(public_runner_releases_url: runner_releases_url) - http_response + subject.send(:reset_backoff!) end + + it { expect(expired?).to be_truthy } + + it 'behaves appropriately in refetch' do + allow(Gitlab::HTTP).to receive(:try_get).with(runner_releases_url).once { mock_http_response([]) } + + subject.releases + expect(expired?).to be_falsey + + travel Gitlab::Ci::RunnerReleases::RELEASES_VALIDITY_PERIOD + 1.second do + expect(expired?).to be_truthy + + allow(Gitlab::HTTP).to receive(:try_get).with(runner_releases_url).once { mock_http_response(nil) } + subject.releases + expect(expired?).to be_truthy + + allow(Gitlab::HTTP).to receive(:try_get).with(runner_releases_url).once { mock_http_response([]) } + subject.releases + expect(expired?).to be_truthy + end + end + end + + def mock_http_response(response) + http_response = instance_double(HTTParty::Response) + + allow(http_response).to receive(:success?).and_return(!response.nil?) + allow(http_response).to receive(:parsed_response).and_return(response) + + http_response end end diff --git a/spec/lib/gitlab/jira_import/issue_serializer_spec.rb b/spec/lib/gitlab/jira_import/issue_serializer_spec.rb index 198d2db234c..f93835f4429 100644 --- a/spec/lib/gitlab/jira_import/issue_serializer_spec.rb +++ b/spec/lib/gitlab/jira_import/issue_serializer_spec.rb @@ -11,6 +11,7 @@ RSpec.describe Gitlab::JiraImport::IssueSerializer do let_it_be(:group_label) { create(:group_label, group: group, title: 'dev') } let_it_be(:current_user) { create(:user) } let_it_be(:user) { create(:user) } + let_it_be(:issue_type_id) { WorkItems::Type.default_issue_type.id } let(:iid) { 5 } let(:key) { 'PROJECT-5' } @@ -54,7 +55,7 @@ RSpec.describe Gitlab::JiraImport::IssueSerializer do let(:params) { { iid: iid } } - subject { described_class.new(project, jira_issue, current_user.id, params).execute } + subject { described_class.new(project, jira_issue, current_user.id, issue_type_id, params).execute } let(:expected_description) do <<~MD @@ -81,7 +82,8 @@ RSpec.describe Gitlab::JiraImport::IssueSerializer do created_at: created_at, author_id: current_user.id, assignee_ids: nil, - label_ids: [project_label.id, group_label.id] + Label.reorder(id: :asc).last(2).pluck(:id) + label_ids: [project_label.id, group_label.id] + Label.reorder(id: :asc).last(2).pluck(:id), + work_item_type_id: issue_type_id ) end diff --git a/spec/lib/gitlab/jira_import/issues_importer_spec.rb b/spec/lib/gitlab/jira_import/issues_importer_spec.rb index 565a9ad17e1..1bc052ee0b6 100644 --- a/spec/lib/gitlab/jira_import/issues_importer_spec.rb +++ b/spec/lib/gitlab/jira_import/issues_importer_spec.rb @@ -10,6 +10,7 @@ RSpec.describe Gitlab::JiraImport::IssuesImporter do let_it_be(:project) { create(:project) } let_it_be(:jira_import) { create(:jira_import_state, project: project, user: current_user) } let_it_be(:jira_integration) { create(:jira_integration, project: project) } + let_it_be(:default_issue_type_id) { WorkItems::Type.default_issue_type.id } subject { described_class.new(project) } @@ -47,12 +48,22 @@ RSpec.describe Gitlab::JiraImport::IssuesImporter do count.times do |i| if raise_exception_on_even_mocks && i.even? - expect(Gitlab::JiraImport::IssueSerializer).to receive(:new) - .with(project, jira_issues[i], current_user.id, { iid: next_iid + 1 }).and_raise('Some error') + expect(Gitlab::JiraImport::IssueSerializer).to receive(:new).with( + project, + jira_issues[i], + current_user.id, + default_issue_type_id, + { iid: next_iid + 1 } + ).and_raise('Some error') else next_iid += 1 - expect(Gitlab::JiraImport::IssueSerializer).to receive(:new) - .with(project, jira_issues[i], current_user.id, { iid: next_iid }).and_return(serializer) + expect(Gitlab::JiraImport::IssueSerializer).to receive(:new).with( + project, + jira_issues[i], + current_user.id, + default_issue_type_id, + { iid: next_iid } + ).and_return(serializer) end end end |