diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-14 18:09:54 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-14 18:09:54 +0000 |
commit | f697dc5e76dfc5894df006d53b2b7e751653cf05 (patch) | |
tree | 1387cd225039e611f3683f96b318bb17d4c422cb /spec/lib/gitlab | |
parent | 874ead9c3a50de4c4ca4551eaf5b7eb976d26b50 (diff) | |
download | gitlab-ce-f697dc5e76dfc5894df006d53b2b7e751653cf05.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab')
3 files changed, 70 insertions, 18 deletions
diff --git a/spec/lib/gitlab/background_migration/backfill_deployment_clusters_from_deployments_spec.rb b/spec/lib/gitlab/background_migration/backfill_deployment_clusters_from_deployments_spec.rb new file mode 100644 index 00000000000..fdabc8e8f7c --- /dev/null +++ b/spec/lib/gitlab/background_migration/backfill_deployment_clusters_from_deployments_spec.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Gitlab::BackgroundMigration::BackfillDeploymentClustersFromDeployments, :migration, schema: 20200227140242 do + subject { described_class.new } + + describe '#perform' do + it 'backfills deployment_cluster for all deployments in the given range with a non-null cluster_id' do + deployment_clusters = table(:deployment_clusters) + + namespace = table(:namespaces).create(name: 'the-namespace', path: 'the-path') + project = table(:projects).create(name: 'the-project', namespace_id: namespace.id) + environment = table(:environments).create(name: 'the-environment', project_id: project.id, slug: 'slug') + cluster = table(:clusters).create(name: 'the-cluster') + + deployment_data = { cluster_id: cluster.id, project_id: project.id, environment_id: environment.id, ref: 'abc', tag: false, sha: 'sha', status: 1 } + expected_deployment_1 = create_deployment(**deployment_data) + create_deployment(**deployment_data, cluster_id: nil) # no cluster_id + expected_deployment_2 = create_deployment(**deployment_data) + out_of_range_deployment = create_deployment(**deployment_data, cluster_id: cluster.id) # expected to be out of range + + # to test "ON CONFLICT DO NOTHING" + existing_record_for_deployment_2 = deployment_clusters.create( + deployment_id: expected_deployment_2.id, + cluster_id: expected_deployment_2.cluster_id, + kubernetes_namespace: 'production' + ) + + subject.perform(expected_deployment_1.id, out_of_range_deployment.id - 1) + + expect(deployment_clusters.all.pluck(:deployment_id, :cluster_id, :kubernetes_namespace)).to contain_exactly( + [expected_deployment_1.id, cluster.id, nil], + [expected_deployment_2.id, cluster.id, existing_record_for_deployment_2.kubernetes_namespace] + ) + end + + def create_deployment(**data) + @iid ||= 0 + @iid += 1 + table(:deployments).create(iid: @iid, **data) + end + end +end diff --git a/spec/lib/gitlab/jira_import/labels_importer_spec.rb b/spec/lib/gitlab/jira_import/labels_importer_spec.rb index 2d0e2bc6b53..3eb4666a74f 100644 --- a/spec/lib/gitlab/jira_import/labels_importer_spec.rb +++ b/spec/lib/gitlab/jira_import/labels_importer_spec.rb @@ -5,7 +5,6 @@ require 'spec_helper' describe Gitlab::JiraImport::LabelsImporter do let_it_be(:user) { create(:user) } let_it_be(:project) { create(:project) } - let_it_be(:jira_import) { create(:jira_import_state, project: project) } let_it_be(:jira_service) { create(:jira_service, project: project) } subject { described_class.new(project).execute } @@ -15,29 +14,24 @@ describe Gitlab::JiraImport::LabelsImporter do end describe '#execute', :clean_gitlab_redis_cache do - context 'when label creation failes' do - before do - allow_next_instance_of(Labels::CreateService) do |instance| - allow(instance).to receive(:execute).and_return(nil) - end - end + context 'when label is missing from jira import' do + let_it_be(:no_label_jira_import) { create(:jira_import_state, label: nil, project: project) } it 'raises error' do - expect { subject }.to raise_error(Projects::ImportService::Error, 'Failed to create import label for jira import.') + expect { subject }.to raise_error(Projects::ImportService::Error, 'Failed to find import label for jira import.') end end - context 'when label is created successfully' do - it 'creates import label' do - expect { subject }.to change { Label.count }.by(1) - end + context 'when label exists' do + let_it_be(:label) { create(:label) } + let_it_be(:jira_import_with_label) { create(:jira_import_state, label: label, project: project) } it 'caches import label' do expect(Gitlab::Cache::Import::Caching.read(Gitlab::JiraImport.import_label_cache_key(project.id))).to be nil subject - expect(Gitlab::JiraImport.get_import_label_id(project.id).to_i).to be > 0 + expect(Gitlab::JiraImport.get_import_label_id(project.id).to_i).to eq(label.id) end end end diff --git a/spec/lib/gitlab/legacy_github_import/client_spec.rb b/spec/lib/gitlab/legacy_github_import/client_spec.rb index 8d1786ae49a..d266b39bd81 100644 --- a/spec/lib/gitlab/legacy_github_import/client_spec.rb +++ b/spec/lib/gitlab/legacy_github_import/client_spec.rb @@ -5,8 +5,9 @@ require 'spec_helper' describe Gitlab::LegacyGithubImport::Client do let(:token) { '123456' } let(:github_provider) { Settingslogic.new('app_id' => 'asd123', 'app_secret' => 'asd123', 'name' => 'github', 'args' => { 'client_options' => {} }) } + let(:wait_for_rate_limit_reset) { true } - subject(:client) { described_class.new(token) } + subject(:client) { described_class.new(token, wait_for_rate_limit_reset: wait_for_rate_limit_reset) } before do allow(Gitlab.config.omniauth).to receive(:providers).and_return([github_provider]) @@ -88,10 +89,23 @@ describe Gitlab::LegacyGithubImport::Client do end end - it 'does not raise error when rate limit is disabled' do - stub_request(:get, /api.github.com/) - allow(client.api).to receive(:rate_limit!).and_raise(Octokit::NotFound) + context 'github rate limit' do + it 'does not raise error when rate limit is disabled' do + stub_request(:get, /api.github.com/) + allow(client.api).to receive(:rate_limit!).and_raise(Octokit::NotFound) - expect { client.issues {} }.not_to raise_error + expect { client.repos }.not_to raise_error + end + + context 'when wait for rate limit is disabled' do + let(:wait_for_rate_limit_reset) { false } + + it 'raises the error limit error when requested' do + stub_request(:get, /api.github.com/) + allow(client.api).to receive(:repos).and_raise(Octokit::TooManyRequests) + + expect { client.repos }.to raise_error(Octokit::TooManyRequests) + end + end end end |