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
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-05-18 03:08:13 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-05-18 03:08:13 +0300
commitc65a2b8a6ce8e1147b738bca02be68f6401bee70 (patch)
tree868652e846467969d7cf9a068f61ab4f7574803f /spec
parent0da9e7b27aef7c9bc3e67ccc65e32cb591b40224 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/graphql/gitlab_schema_spec.rb16
-rw-r--r--spec/helpers/visibility_level_helper_spec.rb26
-rw-r--r--spec/initializers/secret_token_spec.rb9
-rw-r--r--spec/lib/declarative_policy_spec.rb6
-rw-r--r--spec/lib/gitlab/background_migration/migrate_issue_trackers_sensitive_data_spec.rb61
-rw-r--r--spec/lib/gitlab/ci/templates/auto_devops_gitlab_ci_yaml_spec.rb94
-rw-r--r--spec/views/projects/settings/ci_cd/_autodevops_form.html.haml_spec.rb2
7 files changed, 151 insertions, 63 deletions
diff --git a/spec/graphql/gitlab_schema_spec.rb b/spec/graphql/gitlab_schema_spec.rb
index 0f21a55f7e9..8960ad91543 100644
--- a/spec/graphql/gitlab_schema_spec.rb
+++ b/spec/graphql/gitlab_schema_spec.rb
@@ -191,13 +191,17 @@ describe GitlabSchema do
context 'for other classes' do
# We cannot use an anonymous class here as `GlobalID` expects `.name` not
# to return `nil`
- class TestGlobalId
- include GlobalID::Identification
- attr_accessor :id
-
- def initialize(id)
- @id = id
+ before do
+ test_global_id = Class.new do
+ include GlobalID::Identification
+ attr_accessor :id
+
+ def initialize(id)
+ @id = id
+ end
end
+
+ stub_const('TestGlobalId', test_global_id)
end
it 'falls back to a regular find' do
diff --git a/spec/helpers/visibility_level_helper_spec.rb b/spec/helpers/visibility_level_helper_spec.rb
index debe4401308..b7a88ee5010 100644
--- a/spec/helpers/visibility_level_helper_spec.rb
+++ b/spec/helpers/visibility_level_helper_spec.rb
@@ -146,22 +146,22 @@ describe VisibilityLevelHelper do
using RSpec::Parameterized::TableSyntax
- PUBLIC = Gitlab::VisibilityLevel::PUBLIC
- INTERNAL = Gitlab::VisibilityLevel::INTERNAL
- PRIVATE = Gitlab::VisibilityLevel::PRIVATE
+ public_vis = Gitlab::VisibilityLevel::PUBLIC
+ internal_vis = Gitlab::VisibilityLevel::INTERNAL
+ private_vis = Gitlab::VisibilityLevel::PRIVATE
# This is a subset of all the permutations
where(:requested_level, :max_allowed, :global_default_level, :restricted_levels, :expected) do
- PUBLIC | PUBLIC | PUBLIC | [] | PUBLIC
- PUBLIC | PUBLIC | PUBLIC | [PUBLIC] | INTERNAL
- INTERNAL | PUBLIC | PUBLIC | [] | INTERNAL
- INTERNAL | PRIVATE | PRIVATE | [] | PRIVATE
- PRIVATE | PUBLIC | PUBLIC | [] | PRIVATE
- PUBLIC | PRIVATE | INTERNAL | [] | PRIVATE
- PUBLIC | INTERNAL | PUBLIC | [] | INTERNAL
- PUBLIC | PRIVATE | PUBLIC | [] | PRIVATE
- PUBLIC | INTERNAL | INTERNAL | [] | INTERNAL
- PUBLIC | PUBLIC | INTERNAL | [] | PUBLIC
+ public_vis | public_vis | public_vis | [] | public_vis
+ public_vis | public_vis | public_vis | [public_vis] | internal_vis
+ internal_vis | public_vis | public_vis | [] | internal_vis
+ internal_vis | private_vis | private_vis | [] | private_vis
+ private_vis | public_vis | public_vis | [] | private_vis
+ public_vis | private_vis | internal_vis | [] | private_vis
+ public_vis | internal_vis | public_vis | [] | internal_vis
+ public_vis | private_vis | public_vis | [] | private_vis
+ public_vis | internal_vis | internal_vis | [] | internal_vis
+ public_vis | public_vis | internal_vis | [] | public_vis
end
before do
diff --git a/spec/initializers/secret_token_spec.rb b/spec/initializers/secret_token_spec.rb
index c29f46e7779..b7979144c72 100644
--- a/spec/initializers/secret_token_spec.rb
+++ b/spec/initializers/secret_token_spec.rb
@@ -7,9 +7,8 @@ describe 'create_tokens' do
include StubENV
let(:secrets) { ActiveSupport::OrderedOptions.new }
-
- HEX_KEY = /\h{128}/.freeze
- RSA_KEY = /\A-----BEGIN RSA PRIVATE KEY-----\n.+\n-----END RSA PRIVATE KEY-----\n\Z/m.freeze
+ let(:hex_key) { /\h{128}/.freeze }
+ let(:rsa_key) { /\A-----BEGIN RSA PRIVATE KEY-----\n.+\n-----END RSA PRIVATE KEY-----\n\Z/m.freeze }
before do
allow(File).to receive(:write)
@@ -35,7 +34,7 @@ describe 'create_tokens' do
keys = secrets.values_at(:secret_key_base, :otp_key_base, :db_key_base)
expect(keys.uniq).to eq(keys)
- expect(keys).to all(match(HEX_KEY))
+ expect(keys).to all(match(hex_key))
end
it 'generates an RSA key for openid_connect_signing_key' do
@@ -44,7 +43,7 @@ describe 'create_tokens' do
keys = secrets.values_at(:openid_connect_signing_key)
expect(keys.uniq).to eq(keys)
- expect(keys).to all(match(RSA_KEY))
+ expect(keys).to all(match(rsa_key))
end
it 'warns about the secrets to add to secrets.yml' do
diff --git a/spec/lib/declarative_policy_spec.rb b/spec/lib/declarative_policy_spec.rb
index 0904b084c57..5fdb3c27738 100644
--- a/spec/lib/declarative_policy_spec.rb
+++ b/spec/lib/declarative_policy_spec.rb
@@ -23,8 +23,10 @@ describe DeclarativePolicy do
end
context 'when found policy class does not inherit base' do
- class Foo; end
- class FooPolicy; end
+ before do
+ stub_const('Foo', Class.new)
+ stub_const('FooPolicy', Class.new)
+ end
it 'raises error if inferred class does not inherit Base' do
instance = Foo.new
diff --git a/spec/lib/gitlab/background_migration/migrate_issue_trackers_sensitive_data_spec.rb b/spec/lib/gitlab/background_migration/migrate_issue_trackers_sensitive_data_spec.rb
index 09a4d4444eb..4411dca3fd9 100644
--- a/spec/lib/gitlab/background_migration/migrate_issue_trackers_sensitive_data_spec.rb
+++ b/spec/lib/gitlab/background_migration/migrate_issue_trackers_sensitive_data_spec.rb
@@ -4,40 +4,45 @@ require 'spec_helper'
describe Gitlab::BackgroundMigration::MigrateIssueTrackersSensitiveData, schema: 20200130145430 do
let(:services) { table(:services) }
- # we need to define the classes due to encryption
- class IssueTrackerData < ApplicationRecord
- self.table_name = 'issue_tracker_data'
-
- def self.encryption_options
- {
- key: Settings.attr_encrypted_db_key_base_32,
- encode: true,
- mode: :per_attribute_iv,
- algorithm: 'aes-256-gcm'
- }
+ before do
+ # we need to define the classes due to encryption
+ issue_tracker_data = Class.new(ApplicationRecord) do
+ self.table_name = 'issue_tracker_data'
+
+ def self.encryption_options
+ {
+ key: Settings.attr_encrypted_db_key_base_32,
+ encode: true,
+ mode: :per_attribute_iv,
+ algorithm: 'aes-256-gcm'
+ }
+ end
+
+ attr_encrypted :project_url, encryption_options
+ attr_encrypted :issues_url, encryption_options
+ attr_encrypted :new_issue_url, encryption_options
end
- attr_encrypted :project_url, encryption_options
- attr_encrypted :issues_url, encryption_options
- attr_encrypted :new_issue_url, encryption_options
- end
+ jira_tracker_data = Class.new(ApplicationRecord) do
+ self.table_name = 'jira_tracker_data'
- class JiraTrackerData < ApplicationRecord
- self.table_name = 'jira_tracker_data'
+ def self.encryption_options
+ {
+ key: Settings.attr_encrypted_db_key_base_32,
+ encode: true,
+ mode: :per_attribute_iv,
+ algorithm: 'aes-256-gcm'
+ }
+ end
- def self.encryption_options
- {
- key: Settings.attr_encrypted_db_key_base_32,
- encode: true,
- mode: :per_attribute_iv,
- algorithm: 'aes-256-gcm'
- }
+ attr_encrypted :url, encryption_options
+ attr_encrypted :api_url, encryption_options
+ attr_encrypted :username, encryption_options
+ attr_encrypted :password, encryption_options
end
- attr_encrypted :url, encryption_options
- attr_encrypted :api_url, encryption_options
- attr_encrypted :username, encryption_options
- attr_encrypted :password, encryption_options
+ stub_const('IssueTrackerData', issue_tracker_data)
+ stub_const('JiraTrackerData', jira_tracker_data)
end
let(:url) { 'http://base-url.tracker.com' }
diff --git a/spec/lib/gitlab/ci/templates/auto_devops_gitlab_ci_yaml_spec.rb b/spec/lib/gitlab/ci/templates/auto_devops_gitlab_ci_yaml_spec.rb
index e98f9fe1b04..af6ec25b9d6 100644
--- a/spec/lib/gitlab/ci/templates/auto_devops_gitlab_ci_yaml_spec.rb
+++ b/spec/lib/gitlab/ci/templates/auto_devops_gitlab_ci_yaml_spec.rb
@@ -20,23 +20,101 @@ describe 'Auto-DevOps.gitlab-ci.yml' do
allow(project).to receive(:default_branch).and_return(default_branch)
end
+ shared_examples 'no Kubernetes deployment job' do
+ it 'does not create any Kubernetes deployment-related builds' do
+ expect(build_names).not_to include('production')
+ expect(build_names).not_to include('production_manual')
+ expect(build_names).not_to include('staging')
+ expect(build_names).not_to include('canary')
+ expect(build_names).not_to include('review')
+ expect(build_names).not_to include(a_string_matching(/rollout \d+%/))
+ end
+ end
+
it 'creates a build and a test job' do
expect(build_names).to include('build', 'test')
end
+ context 'when the project is set for deployment to AWS' do
+ let(:platform_value) { 'ECS' }
+
+ before do
+ create(:ci_variable, project: project, key: 'AUTO_DEVOPS_PLATFORM_TARGET', value: platform_value)
+ end
+
+ shared_examples 'no ECS job when AUTO_DEVOPS_PLATFORM_TARGET is not present' do |job_name|
+ context 'when AUTO_DEVOPS_PLATFORM_TARGET is nil' do
+ let(:platform_value) { nil }
+
+ it 'does not trigger the job' do
+ expect(build_names).not_to include(job_name)
+ end
+ end
+
+ context 'when AUTO_DEVOPS_PLATFORM_TARGET is empty' do
+ let(:platform_value) { '' }
+
+ it 'does not trigger the job' do
+ expect(build_names).not_to include(job_name)
+ end
+ end
+ end
+
+ it_behaves_like 'no Kubernetes deployment job'
+
+ it_behaves_like 'no ECS job when AUTO_DEVOPS_PLATFORM_TARGET is not present' do
+ let(:job_name) { 'production_ecs' }
+ end
+
+ it 'creates an ECS deployment job for production only' do
+ expect(build_names).not_to include('review_ecs')
+ expect(build_names).to include('production_ecs')
+ end
+
+ context 'and we are not on the default branch' do
+ let(:platform_value) { 'ECS' }
+ let(:pipeline_branch) { 'patch-1' }
+
+ before do
+ project.repository.create_branch(pipeline_branch)
+ end
+
+ it_behaves_like 'no ECS job when AUTO_DEVOPS_PLATFORM_TARGET is not present' do
+ let(:job_name) { 'review_ecs' }
+ end
+
+ it 'creates an ECS deployment job for review only' do
+ expect(build_names).to include('review_ecs')
+ expect(build_names).not_to include('production_ecs')
+ expect(build_names).not_to include('review')
+ expect(build_names).not_to include('production')
+ end
+ end
+
+ context 'and when the project has an active cluster' do
+ let(:cluster) { create(:cluster, :project, :provided_by_gcp, projects: [project]) }
+
+ before do
+ allow(cluster).to receive(:active?).and_return(true)
+ end
+
+ context 'on default branch' do
+ it 'triggers the deployment to Kubernetes, not to ECS' do
+ expect(build_names).not_to include('review')
+ expect(build_names).to include('production')
+ expect(build_names).not_to include('production_ecs')
+ expect(build_names).not_to include('review_ecs')
+ end
+ end
+ end
+ end
+
context 'when the project has no active cluster' do
it 'only creates a build and a test stage' do
expect(pipeline.stages_names).to eq(%w(build test))
end
- it 'does not create any deployment-related builds' do
- expect(build_names).not_to include('production')
- expect(build_names).not_to include('production_manual')
- expect(build_names).not_to include('staging')
- expect(build_names).not_to include('canary')
- expect(build_names).not_to include('review')
- expect(build_names).not_to include(a_string_matching(/rollout \d+%/))
- end
+ it_behaves_like 'no Kubernetes deployment job'
end
context 'when the project has an active cluster' do
diff --git a/spec/views/projects/settings/ci_cd/_autodevops_form.html.haml_spec.rb b/spec/views/projects/settings/ci_cd/_autodevops_form.html.haml_spec.rb
index 94a85486cfa..d25860ab301 100644
--- a/spec/views/projects/settings/ci_cd/_autodevops_form.html.haml_spec.rb
+++ b/spec/views/projects/settings/ci_cd/_autodevops_form.html.haml_spec.rb
@@ -13,7 +13,7 @@ describe 'projects/settings/ci_cd/_autodevops_form' do
it 'shows a warning message about Kubernetes cluster' do
render
- expect(rendered).to have_text('You must add a Kubernetes cluster integration to this project with a domain in order for your deployment strategy to work correctly.')
+ expect(rendered).to have_text('Add a Kubernetes cluster integration with a domain or create an AUTO_DEVOPS_PLATFORM_TARGET CI variable')
end
context 'when the project has an available kubernetes cluster' do