Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-08-17 06:09:39 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-08-17 06:09:39 +0300
commit9faa254d078cfb332e7bab191e6eb362cb67259c (patch)
treef940a6486b889b04d16d70b18d6a4fb6543e4ff3 /spec/models
parentb477368cfec3988a86cde7ac389596041a959af5 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/ci/build_spec.rb70
-rw-r--r--spec/models/integrations/google_play_spec.rb41
2 files changed, 89 insertions, 22 deletions
diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb
index 90edbf530cf..a556244ae00 100644
--- a/spec/models/ci/build_spec.rb
+++ b/spec/models/ci/build_spec.rb
@@ -3216,41 +3216,79 @@ RSpec.describe Ci::Build, feature_category: :continuous_integration, factory_def
end
context 'for the google_play integration' do
- let_it_be(:google_play_integration) { create(:google_play_integration) }
+ before do
+ allow(build.pipeline).to receive(:protected_ref?).and_return(pipeline_protected_ref)
+ end
let(:google_play_variables) do
[
- { key: 'SUPPLY_JSON_KEY_DATA', value: google_play_integration.service_account_key, masked: true, public: false }
+ { key: "SUPPLY_JSON_KEY_DATA", value: google_play_integration.service_account_key, masked: true, public: false },
+ { key: "SUPPLY_PACKAGE_NAME", value: google_play_integration.package_name, masked: false, public: false }
]
end
+ shared_examples 'does not include the google_play_variables' do
+ specify do
+ expect(subject.find { |v| v[:key] == "SUPPLY_JSON_KEY_DATA" }).to be_nil
+ expect(subject.find { |v| v[:key] == "SUPPLY_PACKAGE_NAME" }).to be_nil
+ end
+ end
+
+ shared_examples 'includes google_play_variables' do
+ specify do
+ expect(subject).to include(*google_play_variables)
+ end
+ end
+
context 'when the google_play integration exists' do
- context 'when a build is protected' do
- before do
- allow(build.pipeline).to receive(:protected_ref?).and_return(true)
- build.project.update!(google_play_integration: google_play_integration)
+ let_it_be(:google_play_integration) do
+ create(:google_play_integration, project: project)
+ end
+
+ context 'when google_play_protected_refs is true' do
+ context 'when a build is protected' do
+ let(:pipeline_protected_ref) { true }
+
+ include_examples 'includes google_play_variables'
end
- it 'includes google_play variables' do
- is_expected.to include(*google_play_variables)
+ context 'when a build is not protected' do
+ let(:pipeline_protected_ref) { false }
+
+ include_examples 'does not include the google_play_variables'
end
end
- context 'when a build is not protected' do
+ context 'when google_play_protected_refs is false' do
before do
- allow(build.pipeline).to receive(:protected_ref?).and_return(false)
- build.project.update!(google_play_integration: google_play_integration)
+ google_play_integration.update!(google_play_protected_refs: false)
+ end
+
+ context 'when a build is protected' do
+ let(:pipeline_protected_ref) { true }
+
+ include_examples 'includes google_play_variables'
end
- it 'does not include the google_play variable' do
- expect(subject[:key] == 'SUPPLY_JSON_KEY_DATA').to eq(false)
+ context 'when a build is not protected' do
+ let(:pipeline_protected_ref) { false }
+
+ include_examples 'includes google_play_variables'
end
end
end
- context 'when the googel_play integration does not exist' do
- it 'does not include google_play variable' do
- expect(subject[:key] == 'SUPPLY_JSON_KEY_DATA').to eq(false)
+ context 'when the google_play integration does not exist' do
+ context 'when a build is protected' do
+ let(:pipeline_protected_ref) { true }
+
+ include_examples 'does not include the google_play_variables'
+ end
+
+ context 'when a build is not protected' do
+ let(:pipeline_protected_ref) { false }
+
+ include_examples 'does not include the google_play_variables'
end
end
end
diff --git a/spec/models/integrations/google_play_spec.rb b/spec/models/integrations/google_play_spec.rb
index 8349ac71bc9..a0bc73378d3 100644
--- a/spec/models/integrations/google_play_spec.rb
+++ b/spec/models/integrations/google_play_spec.rb
@@ -20,6 +20,8 @@ RSpec.describe Integrations::GooglePlay, feature_category: :mobile_devops do
it { is_expected.to allow_value('a.a.a').for(:package_name) }
it { is_expected.to allow_value('com.example').for(:package_name) }
it { is_expected.not_to allow_value('com').for(:package_name) }
+ it { is_expected.to allow_value(true, false).for(:google_play_protected_refs) }
+ it { is_expected.not_to allow_value(nil).for(:google_play_protected_refs) }
it { is_expected.not_to allow_value('com.example.my app').for(:package_name) }
it { is_expected.not_to allow_value('1com.example.myapp').for(:package_name) }
it { is_expected.not_to allow_value('com.1example.myapp').for(:package_name) }
@@ -33,7 +35,7 @@ RSpec.describe Integrations::GooglePlay, feature_category: :mobile_devops do
describe '#fields' do
it 'returns custom fields' do
expect(google_play_integration.fields.pluck(:name)).to match_array(%w[package_name service_account_key
- service_account_key_file_name])
+ service_account_key_file_name google_play_protected_refs])
end
end
@@ -67,9 +69,8 @@ RSpec.describe Integrations::GooglePlay, feature_category: :mobile_devops do
describe '#ci_variables' do
let(:google_play_integration) { build_stubbed(:google_play_integration) }
-
- it 'returns vars when the integration is activated' do
- ci_vars = [
+ let(:ci_vars) do
+ [
{
key: 'SUPPLY_PACKAGE_NAME',
value: google_play_integration.package_name,
@@ -83,8 +84,36 @@ RSpec.describe Integrations::GooglePlay, feature_category: :mobile_devops do
public: false
}
]
+ end
+
+ it 'returns the vars for protected branch' do
+ expect(google_play_integration.ci_variables(protected_ref: true)).to match_array(ci_vars)
+ end
+
+ it "doesn't return vars for unproteced branch" do
+ expect(google_play_integration.ci_variables(protected_ref: false)).to be_empty
+ end
+ end
+
+ describe '#initialize_properties' do
+ context 'when google_play_protected_refs is nil' do
+ let(:google_play_integration) { described_class.new(google_play_protected_refs: nil) }
- expect(google_play_integration.ci_variables).to match_array(ci_vars)
+ it 'sets google_play_protected_refs to true' do
+ expect(google_play_integration.google_play_protected_refs).to be(true)
+ end
+ end
+
+ context 'when google_play_protected_refs is false' do
+ let(:google_play_integration) { build(:google_play_integration, google_play_protected_refs: false) }
+
+ it 'sets google_play_protected_refs to false' do
+ expect(google_play_integration.google_play_protected_refs).to be(false)
+ end
+
+ it "returns vars for unprotected ref when google_play_protected_refs is false" do
+ expect(google_play_integration.ci_variables(protected_ref: false)).not_to be_empty
+ end
end
end
end
@@ -94,7 +123,7 @@ RSpec.describe Integrations::GooglePlay, feature_category: :mobile_devops do
describe '#ci_variables' do
it 'returns an empty array' do
- expect(google_play_integration.ci_variables).to match_array([])
+ expect(google_play_integration.ci_variables(protected_ref: true)).to be_empty
end
end
end