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>2021-06-11 06:10:14 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-06-11 06:10:14 +0300
commitfb8d6a526f0ef2da9fb247e15f9ff19279dba3d6 (patch)
tree11c6697e314baf4d0e18f0aab10552109633946b /spec
parent9ae44f98c841d785b52087348de2e8cba9a13a2d (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/features/issues/user_resets_their_incoming_email_token_spec.rb2
-rw-r--r--spec/features/profile_spec.rb4
-rw-r--r--spec/features/profiles/personal_access_tokens_spec.rb11
-rw-r--r--spec/fixtures/lib/generators/gitlab/usage_metric_generator/sample_metric.rb14
-rw-r--r--spec/fixtures/lib/generators/gitlab/usage_metric_generator/sample_metric_test.rb7
-rw-r--r--spec/lib/generators/gitlab/usage_metric_generator_spec.rb70
-rw-r--r--spec/models/application_setting_spec.rb79
-rw-r--r--spec/services/submit_usage_ping_service_spec.rb8
8 files changed, 189 insertions, 6 deletions
diff --git a/spec/features/issues/user_resets_their_incoming_email_token_spec.rb b/spec/features/issues/user_resets_their_incoming_email_token_spec.rb
index 9e47639d80f..4580378dc8a 100644
--- a/spec/features/issues/user_resets_their_incoming_email_token_spec.rb
+++ b/spec/features/issues/user_resets_their_incoming_email_token_spec.rb
@@ -20,7 +20,7 @@ RSpec.describe 'Issues > User resets their incoming email token' do
page.within '#issuable-email-modal' do
previous_token = page.find('input[type="text"]').value
- click_button 'reset it'
+ find('[data-testid="reset_email_token_link"]').click
wait_for_requests
diff --git a/spec/features/profile_spec.rb b/spec/features/profile_spec.rb
index 84ea9495f08..0f453f1c1e5 100644
--- a/spec/features/profile_spec.rb
+++ b/spec/features/profile_spec.rb
@@ -70,7 +70,7 @@ RSpec.describe 'Profile account page', :js do
within('.feed-token-reset') do
previous_token = find("#feed_token").value
- accept_confirm { click_link('reset it') }
+ accept_confirm { find('[data-testid="reset_feed_token_link"]').click }
expect(find('#feed_token').value).not_to eq(previous_token)
end
@@ -89,7 +89,7 @@ RSpec.describe 'Profile account page', :js do
within('.incoming-email-token-reset') do
previous_token = find('#incoming_email_token').value
- accept_confirm { click_link('reset it') }
+ accept_confirm { find('[data-testid="reset_email_token_link"]').click }
expect(find('#incoming_email_token').value).not_to eq(previous_token)
end
diff --git a/spec/features/profiles/personal_access_tokens_spec.rb b/spec/features/profiles/personal_access_tokens_spec.rb
index c85657c89d5..379c25d6002 100644
--- a/spec/features/profiles/personal_access_tokens_spec.rb
+++ b/spec/features/profiles/personal_access_tokens_spec.rb
@@ -22,6 +22,10 @@ RSpec.describe 'Profile > Personal Access Tokens', :js do
find("#feed_token").value
end
+ def feed_token_description
+ "Your feed token authenticates you when your RSS reader loads a personalized RSS feed or when your calendar application loads a personalized calendar. It is visible in those feed URLs."
+ end
+
def disallow_personal_access_token_saves!
allow(PersonalAccessTokens::CreateService).to receive(:new).and_return(pat_create_service)
@@ -123,8 +127,9 @@ RSpec.describe 'Profile > Personal Access Tokens', :js do
allow(Gitlab::CurrentSettings).to receive(:disable_feed_token).and_return(false)
visit profile_personal_access_tokens_path
- expect(page).to have_content("Your feed token is used to authenticate you when your RSS reader loads a personalized RSS feed or when your calendar application loads a personalized calendar, and is included in those feed URLs.")
expect(feed_token).to eq(user.feed_token)
+
+ expect(page).to have_content(feed_token_description)
end
end
@@ -133,8 +138,8 @@ RSpec.describe 'Profile > Personal Access Tokens', :js do
allow(Gitlab::CurrentSettings).to receive(:disable_feed_token).and_return(true)
visit profile_personal_access_tokens_path
- expect(page).not_to have_content("Your feed token is used to authenticate you when your RSS reader loads a personalized RSS feed or when your calendar application loads a personalized calendar, and is included in those feed URLs.")
- expect(page).not_to have_css("#feed_token")
+ expect(page).to have_no_content(feed_token_description)
+ expect(page).to have_no_css("#feed_token")
end
end
end
diff --git a/spec/fixtures/lib/generators/gitlab/usage_metric_generator/sample_metric.rb b/spec/fixtures/lib/generators/gitlab/usage_metric_generator/sample_metric.rb
new file mode 100644
index 00000000000..9816ff7c9eb
--- /dev/null
+++ b/spec/fixtures/lib/generators/gitlab/usage_metric_generator/sample_metric.rb
@@ -0,0 +1,14 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Usage
+ module Metrics
+ module Instrumentations
+ class CountFooMetric < RedisHLLMetric
+ def value
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/spec/fixtures/lib/generators/gitlab/usage_metric_generator/sample_metric_test.rb b/spec/fixtures/lib/generators/gitlab/usage_metric_generator/sample_metric_test.rb
new file mode 100644
index 00000000000..bc7df779a58
--- /dev/null
+++ b/spec/fixtures/lib/generators/gitlab/usage_metric_generator/sample_metric_test.rb
@@ -0,0 +1,7 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::Usage::Metrics::Instrumentations::CountFooMetric do
+ it_behaves_like 'a correct instrumented metric value', {}, 1
+end
diff --git a/spec/lib/generators/gitlab/usage_metric_generator_spec.rb b/spec/lib/generators/gitlab/usage_metric_generator_spec.rb
new file mode 100644
index 00000000000..f38815acca6
--- /dev/null
+++ b/spec/lib/generators/gitlab/usage_metric_generator_spec.rb
@@ -0,0 +1,70 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::UsageMetricGenerator, :silence_stdout do
+ let(:ce_temp_dir) { Dir.mktmpdir }
+ let(:ee_temp_dir) { Dir.mktmpdir }
+ let(:spec_ce_temp_dir) { Dir.mktmpdir }
+ let(:spec_ee_temp_dir) { Dir.mktmpdir }
+ let(:args) { ['CountFoo'] }
+ let(:options) { { 'type' => 'redis_hll' } }
+
+ before do
+ stub_const("#{described_class}::CE_DIR", ce_temp_dir)
+ stub_const("#{described_class}::EE_DIR", ee_temp_dir)
+ stub_const("#{described_class}::SPEC_CE_DIR", spec_ce_temp_dir)
+ stub_const("#{described_class}::SPEC_EE_DIR", spec_ee_temp_dir)
+ end
+
+ after do
+ FileUtils.rm_rf([ce_temp_dir, ee_temp_dir, spec_ce_temp_dir, spec_ee_temp_dir])
+ end
+
+ def expect_generated_file(directory, file_name, content)
+ file_path = File.join(directory, file_name)
+ file = File.read(file_path)
+
+ expect(file).to eq(content)
+ end
+
+ describe 'Creating metric instrumentation files' do
+ let(:sample_metric_dir) { 'lib/generators/gitlab/usage_metric_generator' }
+ let(:sample_metric) { fixture_file(File.join(sample_metric_dir, 'sample_metric.rb')) }
+ let(:sample_spec) { fixture_file(File.join(sample_metric_dir, 'sample_metric_test.rb')) }
+
+ it 'creates CE metric instrumentation files using the template' do
+ described_class.new(args, options).invoke_all
+
+ expect_generated_file(ce_temp_dir, 'count_foo_metric.rb', sample_metric)
+ expect_generated_file(spec_ce_temp_dir, 'count_foo_metric_spec.rb', sample_spec)
+ end
+
+ context 'with EE flag true' do
+ let(:options) { { 'type' => 'redis_hll', 'ee' => true } }
+
+ it 'creates EE metric instrumentation files using the template' do
+ described_class.new(args, options).invoke_all
+
+ expect_generated_file(ee_temp_dir, 'count_foo_metric.rb', sample_metric)
+ expect_generated_file(spec_ee_temp_dir, 'count_foo_metric_spec.rb', sample_spec)
+ end
+ end
+
+ context 'with type option missing' do
+ let(:options) { {} }
+
+ it 'raises an ArgumentError' do
+ expect { described_class.new(args, options).invoke_all }.to raise_error(ArgumentError, /Type is required/)
+ end
+ end
+
+ context 'with type option value not included in approved superclasses' do
+ let(:options) { { 'type' => 'some_other_type' } }
+
+ it 'raises an ArgumentError' do
+ expect { described_class.new(args, options).invoke_all }.to raise_error(ArgumentError, /Unknown type 'some_other_type'/)
+ end
+ end
+ end
+end
diff --git a/spec/models/application_setting_spec.rb b/spec/models/application_setting_spec.rb
index 4b4e7820f7a..c13d83d1685 100644
--- a/spec/models/application_setting_spec.rb
+++ b/spec/models/application_setting_spec.rb
@@ -363,6 +363,85 @@ RSpec.describe ApplicationSetting do
.is_less_than(65536)
end
+ describe 'usage_ping_enabled setting' do
+ shared_examples 'usage ping enabled' do
+ it do
+ expect(setting.usage_ping_enabled).to eq(true)
+ expect(setting.usage_ping_enabled?).to eq(true)
+ end
+ end
+
+ shared_examples 'usage ping disabled' do
+ it do
+ expect(setting.usage_ping_enabled).to eq(false)
+ expect(setting.usage_ping_enabled?).to eq(false)
+ end
+ end
+
+ context 'when setting is in database' do
+ context 'with usage_ping_enabled disabled' do
+ before do
+ setting.update!(usage_ping_enabled: false)
+ end
+
+ it_behaves_like 'usage ping disabled'
+ end
+
+ context 'with usage_ping_enabled enabled' do
+ before do
+ setting.update!(usage_ping_enabled: true)
+ end
+
+ it_behaves_like 'usage ping enabled'
+ end
+ end
+
+ context 'when setting is in GitLab config' do
+ context 'with usage_ping_enabled disabled' do
+ before do
+ allow(Settings.gitlab).to receive(:usage_ping_enabled).and_return(false)
+ end
+
+ it_behaves_like 'usage ping disabled'
+ end
+
+ context 'with usage_ping_enabled enabled' do
+ before do
+ allow(Settings.gitlab).to receive(:usage_ping_enabled).and_return(true)
+ end
+
+ it_behaves_like 'usage ping enabled'
+ end
+ end
+
+ context 'when setting in database false and setting in GitLab config true' do
+ before do
+ setting.update!(usage_ping_enabled: false)
+ allow(Settings.gitlab).to receive(:usage_ping_enabled).and_return(true)
+ end
+
+ it_behaves_like 'usage ping disabled'
+ end
+
+ context 'when setting database true and setting in GitLab config false' do
+ before do
+ setting.update!(usage_ping_enabled: true)
+ allow(Settings.gitlab).to receive(:usage_ping_enabled).and_return(false)
+ end
+
+ it_behaves_like 'usage ping disabled'
+ end
+
+ context 'when setting database true and setting in GitLab config true' do
+ before do
+ setting.update!(usage_ping_enabled: true)
+ allow(Settings.gitlab).to receive(:usage_ping_enabled).and_return(true)
+ end
+
+ it_behaves_like 'usage ping enabled'
+ end
+ end
+
context 'key restrictions' do
it 'supports all key types' do
expect(described_class::SUPPORTED_KEY_TYPES).to contain_exactly(:rsa, :dsa, :ecdsa, :ed25519)
diff --git a/spec/services/submit_usage_ping_service_spec.rb b/spec/services/submit_usage_ping_service_spec.rb
index a9f1b2c2b2d..7133dc35fc3 100644
--- a/spec/services/submit_usage_ping_service_spec.rb
+++ b/spec/services/submit_usage_ping_service_spec.rb
@@ -90,6 +90,14 @@ RSpec.describe SubmitUsagePingService do
it_behaves_like 'does not run'
end
+ context 'when usage ping is disabled from GitLab config file' do
+ before do
+ stub_config_setting(usage_ping_enabled: false)
+ end
+
+ it_behaves_like 'does not run'
+ end
+
context 'when usage ping is enabled' do
before do
stub_usage_data_connections