diff options
author | Pawel Chojnacki <pawel@chojnacki.ws> | 2017-06-07 11:27:52 +0300 |
---|---|---|
committer | Pawel Chojnacki <pawel@chojnacki.ws> | 2017-06-07 11:27:52 +0300 |
commit | dbb3c28088b63c8cf40a90c599b6eedb4dfbbb66 (patch) | |
tree | 9e6c4d495e45355ef62c56c0c3e102f95220f89f /spec/support | |
parent | a924152219c1367bf494f3f387d050ac3ff2d7d3 (diff) | |
parent | dddc54aa0aea4088e5a233d18a62cb2435590fe9 (diff) |
Merge remote-tracking branch 'upstream/master' into 28717-additional-metrics-review-branch
# Conflicts:
# app/models/project_services/prometheus_service.rb
# app/views/projects/services/_form.html.haml
Diffstat (limited to 'spec/support')
-rw-r--r-- | spec/support/cycle_analytics_helpers.rb | 43 | ||||
-rw-r--r-- | spec/support/git_http_helpers.rb | 22 | ||||
-rw-r--r-- | spec/support/gitaly.rb | 3 | ||||
-rw-r--r-- | spec/support/helpers/key_generator_helper.rb | 41 | ||||
-rw-r--r-- | spec/support/import_spec_helper.rb | 2 | ||||
-rw-r--r-- | spec/support/matchers/execute_check.rb | 23 | ||||
-rw-r--r-- | spec/support/rake_helpers.rb | 5 | ||||
-rw-r--r-- | spec/support/stub_configuration.rb | 4 | ||||
-rw-r--r-- | spec/support/test_env.rb | 18 |
9 files changed, 147 insertions, 14 deletions
diff --git a/spec/support/cycle_analytics_helpers.rb b/spec/support/cycle_analytics_helpers.rb index 66545127a44..6e1eb5c678d 100644 --- a/spec/support/cycle_analytics_helpers.rb +++ b/spec/support/cycle_analytics_helpers.rb @@ -51,12 +51,43 @@ module CycleAnalyticsHelpers end def deploy_master(environment: 'production') - CreateDeploymentService.new(project, user, { - environment: environment, - ref: 'master', - tag: false, - sha: project.repository.commit('master').sha - }).execute + dummy_job = + case environment + when 'production' + dummy_production_job + when 'staging' + dummy_staging_job + else + raise ArgumentError + end + + CreateDeploymentService.new(dummy_job).execute + end + + def dummy_production_job + @dummy_job ||= new_dummy_job('production') + end + + def dummy_staging_job + @dummy_job ||= new_dummy_job('staging') + end + + def dummy_pipeline + @dummy_pipeline ||= + Ci::Pipeline.new(sha: project.repository.commit('master').sha) + end + + def new_dummy_job(environment) + project.environments.find_or_create_by(name: environment) + + Ci::Build.new( + project: project, + user: user, + environment: environment, + ref: 'master', + tag: false, + name: 'dummy', + pipeline: dummy_pipeline) end end diff --git a/spec/support/git_http_helpers.rb b/spec/support/git_http_helpers.rb index 46b686fce94..b8289e6c5f1 100644 --- a/spec/support/git_http_helpers.rb +++ b/spec/support/git_http_helpers.rb @@ -35,9 +35,14 @@ module GitHttpHelpers yield response end + def download_or_upload(*args, &block) + download(*args, &block) + upload(*args, &block) + end + def auth_env(user, password, spnego_request_token) env = workhorse_internal_api_request_header - if user && password + if user env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Basic.encode_credentials(user, password) elsif spnego_request_token env['HTTP_AUTHORIZATION'] = "Negotiate #{::Base64.strict_encode64('opaque_request_token')}" @@ -45,4 +50,19 @@ module GitHttpHelpers env end + + def git_access_error(error_key) + message = Gitlab::GitAccess::ERROR_MESSAGES[error_key] + message || raise("GitAccess error message key '#{error_key}' not found") + end + + def git_access_wiki_error(error_key) + message = Gitlab::GitAccessWiki::ERROR_MESSAGES[error_key] + message || raise("GitAccessWiki error message key '#{error_key}' not found") + end + + def change_access_error(error_key) + message = Gitlab::Checks::ChangeAccess::ERROR_MESSAGES[error_key] + message || raise("ChangeAccess error message key '#{error_key}' not found") + end end diff --git a/spec/support/gitaly.rb b/spec/support/gitaly.rb index 7aca902fc61..2bf159002a0 100644 --- a/spec/support/gitaly.rb +++ b/spec/support/gitaly.rb @@ -1,6 +1,7 @@ if Gitlab::GitalyClient.enabled? RSpec.configure do |config| - config.before(:each) do + config.before(:each) do |example| + next if example.metadata[:skip_gitaly_mock] allow(Gitlab::GitalyClient).to receive(:feature_enabled?).and_return(true) end end diff --git a/spec/support/helpers/key_generator_helper.rb b/spec/support/helpers/key_generator_helper.rb new file mode 100644 index 00000000000..b1c289ffef7 --- /dev/null +++ b/spec/support/helpers/key_generator_helper.rb @@ -0,0 +1,41 @@ +module Spec + module Support + module Helpers + class KeyGeneratorHelper + # The components in a openssh .pub / known_host RSA public key. + RSA_COMPONENTS = ['ssh-rsa', :e, :n].freeze + + attr_reader :size + + def initialize(size = 2048) + @size = size + end + + def generate + key = OpenSSL::PKey::RSA.generate(size) + components = RSA_COMPONENTS.map do |component| + key.respond_to?(component) ? encode_mpi(key.public_send(component)) : component + end + + # Ruby tries to be helpful and adds new lines every 60 bytes :( + 'ssh-rsa ' + [pack_pubkey_components(components)].pack('m').delete("\n") + end + + private + + # Encodes an openssh-mpi-encoded integer. + def encode_mpi(n) + chars, n = [], n.to_i + chars << (n & 0xff) && n >>= 8 while n != 0 + chars << 0 if chars.empty? || chars.last >= 0x80 + chars.reverse.pack('C*') + end + + # Packs string components into an openssh-encoded pubkey. + def pack_pubkey_components(strings) + (strings.map { |s| [s.length].pack('N') }).zip(strings).flatten.join + end + end + end + end +end diff --git a/spec/support/import_spec_helper.rb b/spec/support/import_spec_helper.rb index 6710962f082..d4eced724fa 100644 --- a/spec/support/import_spec_helper.rb +++ b/spec/support/import_spec_helper.rb @@ -28,6 +28,6 @@ module ImportSpecHelper app_id: 'asd123', app_secret: 'asd123' ) - allow(Gitlab.config.omniauth).to receive(:providers).and_return([provider]) + stub_omniauth_setting(providers: [provider]) end end diff --git a/spec/support/matchers/execute_check.rb b/spec/support/matchers/execute_check.rb new file mode 100644 index 00000000000..7232fad52fb --- /dev/null +++ b/spec/support/matchers/execute_check.rb @@ -0,0 +1,23 @@ +RSpec::Matchers.define :execute_check do |expected| + match do |actual| + expect(actual).to eq(SystemCheck) + expect(actual).to receive(:run) do |*args| + expect(args[1]).to include(expected) + end + end + + match_when_negated do |actual| + expect(actual).to eq(SystemCheck) + expect(actual).to receive(:run) do |*args| + expect(args[1]).not_to include(expected) + end + end + + failure_message do |actual| + 'This matcher must be used with SystemCheck' unless actual == SystemCheck + end + + failure_message_when_negated do |actual| + 'This matcher must be used with SystemCheck' unless actual == SystemCheck + end +end diff --git a/spec/support/rake_helpers.rb b/spec/support/rake_helpers.rb index 4a8158ed79b..5cb415111d2 100644 --- a/spec/support/rake_helpers.rb +++ b/spec/support/rake_helpers.rb @@ -7,4 +7,9 @@ module RakeHelpers def stub_warn_user_is_not_gitlab allow_any_instance_of(Object).to receive(:warn_user_is_not_gitlab) end + + def silence_output + allow($stdout).to receive(:puts) + allow($stdout).to receive(:print) + end end diff --git a/spec/support/stub_configuration.rb b/spec/support/stub_configuration.rb index 444adcc1906..b39a23bd18a 100644 --- a/spec/support/stub_configuration.rb +++ b/spec/support/stub_configuration.rb @@ -25,6 +25,10 @@ module StubConfiguration allow(Gitlab.config.mattermost).to receive_messages(messages) end + def stub_omniauth_setting(messages) + allow(Gitlab.config.omniauth).to receive_messages(messages) + end + private # Modifies stubbed messages to also stub possible predicate versions diff --git a/spec/support/test_env.rb b/spec/support/test_env.rb index 3c000feba5d..3f472e59c49 100644 --- a/spec/support/test_env.rb +++ b/spec/support/test_env.rb @@ -40,7 +40,7 @@ module TestEnv 'wip' => 'b9238ee', 'csv' => '3dd0896', 'v1.1.0' => 'b83d6e3', - 'add-ipython-files' => '6d85bb6', + 'add-ipython-files' => '93ee732', 'add-pdf-file' => 'e774ebd' }.freeze @@ -54,6 +54,8 @@ module TestEnv 'conflict-resolvable-fork' => '404fa3f' }.freeze + TMP_TEST_PATH = Rails.root.join('tmp', 'tests', '**') + # Test environment # # See gitlab.yml.example test section for paths @@ -98,9 +100,7 @@ module TestEnv # # Keeps gitlab-shell and gitlab-test def clean_test_path - tmp_test_path = Rails.root.join('tmp', 'tests', '**') - - Dir[tmp_test_path].each do |entry| + Dir[TMP_TEST_PATH].each do |entry| unless File.basename(entry) =~ /\A(gitaly|gitlab-(shell|test|test_bare|test-fork|test-fork_bare))\z/ FileUtils.rm_rf(entry) end @@ -111,6 +111,14 @@ module TestEnv FileUtils.mkdir_p(pages_path) end + def clean_gitlab_test_path + Dir[TMP_TEST_PATH].each do |entry| + if File.basename(entry) =~ /\A(gitlab-(test|test_bare|test-fork|test-fork_bare))\z/ + FileUtils.rm_rf(entry) + end + end + end + def setup_gitlab_shell unless File.directory?(Gitlab.config.gitlab_shell.path) unless system('rake', 'gitlab:shell:install') @@ -249,7 +257,7 @@ module TestEnv # Before we used Git clone's --mirror option, bare repos could end up # with missing refs, clearing them and retrying should fix the issue. - cleanup && init unless reset.call + cleanup && clean_gitlab_test_path && init unless reset.call end end |