diff --git a/lib/gdk/dependencies/checker.rb b/lib/gdk/dependencies/checker.rb index 3306df086406ea1637dec70b9e9c9548cad398e7..ed75ca84e2af44bf6d6a77b5e3e593ad8f47a016 100644 --- a/lib/gdk/dependencies/checker.rb +++ b/lib/gdk/dependencies/checker.rb @@ -35,7 +35,6 @@ def check_all check_runit_installed check_nginx_installed - # FIXME: This duplicates the RubyGems diagnostic check check_ruby_gems_ok end diff --git a/lib/gdk/diagnostic.rb b/lib/gdk/diagnostic.rb index 3d0617b0f966b3eb3d3fbb87d2d4bd3b0f3fa093..bcb102937e9e4b9f0729bd58bc261b0e3850694a 100644 --- a/lib/gdk/diagnostic.rb +++ b/lib/gdk/diagnostic.rb @@ -34,7 +34,6 @@ def self.all Environment RvmAndAsdf MacPorts - RubyGems Bundler Version Configuration diff --git a/lib/gdk/diagnostic/ruby_gems.rb b/lib/gdk/diagnostic/ruby_gems.rb index 4c8daef3e2b365a8ec217dd12443f654662873de..39f3120da04ba30aff73a0b2e466d1ad77d95ca5 100644 --- a/lib/gdk/diagnostic/ruby_gems.rb +++ b/lib/gdk/diagnostic/ruby_gems.rb @@ -6,7 +6,14 @@ module GDK module Diagnostic class RubyGems < Base TITLE = 'Ruby Gems' - GITLAB_GEMS_WITH_C_CODE_TO_CHECK = %w[charlock_holmes ffi gpgme pg oj].freeze + GEM_REQUIRE_MAPPING = { + 'static_holmes' => 'charlock_holmes', + 'ffi' => 'ffi', + 'gpgme' => 'gpgme', + 'pg' => 'pg', + 'oj' => 'oj' + }.freeze + GITLAB_GEMS_WITH_C_CODE_TO_CHECK = GEM_REQUIRE_MAPPING.keys def initialize(allow_gem_not_installed: false) @allow_gem_not_installed = allow_gem_not_installed @@ -15,16 +22,24 @@ def initialize(allow_gem_not_installed: false) end def success? + return false unless bundle_check_ok? + failed_to_load_gitlab_gems.empty? end def detail - gitlab_error_message unless success? + return if success? + + return bundle_check_error_message unless bundle_check_ok? + + gitlab_error_message end private - attr_reader :allow_gem_not_installed + def bundle_check_ok? + exec_cmd("#{bundle_exec_cmd} bundle check") || allow_gem_not_installed? + end def allow_gem_not_installed? @allow_gem_not_installed == true @@ -50,7 +65,8 @@ def gem_installed?(name) end def gem_loads_ok?(name) - command = -> { exec_cmd("#{bundle_exec_cmd} ruby -r #{name} -e 'nil'") } + gem_name = GEM_REQUIRE_MAPPING[name] + command = -> { exec_cmd("#{bundle_exec_cmd} ruby -r #{gem_name} -e 'nil'") } if bundler_available? ::Bundler.with_unbundled_env do @@ -71,6 +87,14 @@ def bundler_available? defined? ::Bundler end + def bundle_check_error_message + <<~MESSAGE + There are Ruby gems missing that need to be installed. Try running the following to fix: + + (cd #{config.gitlab.dir} && bundle install) + MESSAGE + end + def gitlab_error_message <<~MESSAGE The following Ruby Gems appear to have issues: @@ -79,7 +103,7 @@ def gitlab_error_message Try running the following to fix: - cd #{config.gitlab.dir} && bundle pristine #{@failed_to_load_gitlab_gems.join(' ')} + (cd #{config.gitlab.dir} && bundle pristine #{@failed_to_load_gitlab_gems.join(' ')}) MESSAGE end end diff --git a/spec/lib/gdk/diagnostic/ruby_gems_spec.rb b/spec/lib/gdk/diagnostic/ruby_gems_spec.rb index e3a17b32c859c005c115d8e425dcd041f69e021f..990f68b6e40145e4669b4207147a394458e10385 100644 --- a/spec/lib/gdk/diagnostic/ruby_gems_spec.rb +++ b/spec/lib/gdk/diagnostic/ruby_gems_spec.rb @@ -2,51 +2,64 @@ RSpec.describe GDK::Diagnostic::RubyGems do let(:allow_gem_not_installed) { nil } + let(:bundle_check_ok) { nil } subject(:diagnostic) { described_class.new(allow_gem_not_installed: allow_gem_not_installed) } before do + stub_bundle_check(bundle_check_ok) + stub_const('GDK::Diagnostic::RubyGems::GEM_REQUIRE_MAPPING', { 'bad_gem' => 'actual_gem_name' }) stub_const('GDK::Diagnostic::RubyGems::GITLAB_GEMS_WITH_C_CODE_TO_CHECK', %w[bad_gem]) end describe '#success?' do - before do - stub_gem_installed('bad_gem', gem_installed) - end + context 'when bundle check fails' do + let(:bundle_check_ok) { false } - context 'when bad_gem is not installed' do - let(:gem_installed) { false } + it { is_expected.not_to be_success } + end - context 'and allow_gem_not_installed is false' do - let(:allow_gem_not_installed) { false } + context 'when bundle check succeeds' do + let(:bundle_check_ok) { true } - it { is_expected.not_to be_success } + before do + stub_gem_installed('bad_gem', gem_installed) end - context 'and allow_gem_not_installed is true' do - let(:allow_gem_not_installed) { true } + context 'when bad_gem is not installed' do + let(:gem_installed) { false } - it { is_expected.to be_success } - end - end + context 'and allow_gem_not_installed is false' do + let(:allow_gem_not_installed) { false } - context 'when bad_gem is installed' do - let(:gem_installed) { true } + it { is_expected.not_to be_success } + end - before do - stub_gem_loads_ok('bad_gem', gem_loads_ok) + context 'and allow_gem_not_installed is true' do + let(:allow_gem_not_installed) { true } + + it { is_expected.to be_success } + end end - context 'and bad_gem cannot be loaded' do - let(:gem_loads_ok) { false } + context 'when bad_gem is installed' do + let(:gem_installed) { true } - it { is_expected.not_to be_success } - end + before do + stub_gem_loads_ok('bad_gem', gem_loads_ok) + end + + context 'and bad_gem cannot be loaded' do + let(:gem_loads_ok) { false } - context 'and bad_gem is loaded correctly' do - let(:gem_loads_ok) { true } + it { is_expected.not_to be_success } + end - it { is_expected.to be_success } + context 'and bad_gem is loaded correctly' do + let(:gem_loads_ok) { true } + + it { is_expected.to be_success } + end end end end @@ -54,52 +67,67 @@ describe '#detail' do subject(:detail) { diagnostic.detail } - before do - stub_gem_installed('bad_gem', gem_installed) - end + context 'when bundle check fails' do + let(:bundle_check_ok) { false } - context 'when bad_gem is not installed' do - let(:gem_installed) { false } + it { is_expected.to match(/There are Ruby gems missing that need to be installed./) } + end - context 'and allow_gem_not_installed is false' do - let(:allow_gem_not_installed) { false } + context 'when bundle check succeeds' do + let(:bundle_check_ok) { true } - it { is_expected.to match(/bundle pristine bad_gem/) } + before do + stub_gem_installed('bad_gem', gem_installed) end - context 'and allow_gem_not_installed is true' do - let(:allow_gem_not_installed) { true } + context 'when bad_gem is not installed' do + let(:gem_installed) { false } - it { is_expected.to be_nil } - end - end + context 'and allow_gem_not_installed is false' do + let(:allow_gem_not_installed) { false } - context 'when bad_gem is installed' do - let(:gem_installed) { true } + it { is_expected.to match(/bundle pristine bad_gem/) } + end - before do - stub_gem_loads_ok('bad_gem', gem_loads_ok) + context 'and allow_gem_not_installed is true' do + let(:allow_gem_not_installed) { true } + + it { is_expected.to be_nil } + end end - context 'and bad_gem cannot be loaded' do - let(:gem_loads_ok) { false } + context 'when bad_gem is installed' do + let(:gem_installed) { true } - it { is_expected.to match(/bundle pristine bad_gem/) } - end + before do + stub_gem_loads_ok('bad_gem', gem_loads_ok) + end + + context 'and bad_gem cannot be loaded' do + let(:gem_loads_ok) { false } + + it { is_expected.to match(/bundle pristine bad_gem/) } + end - context 'and bad_gem is loaded correctly' do - let(:gem_loads_ok) { true } + context 'and bad_gem is loaded correctly' do + let(:gem_loads_ok) { true } - it { is_expected.to be_nil } + it { is_expected.to be_nil } + end end end end - def stub_gem_installed(gem_name, success) - stub_shellout("/home/git/gdk/support/bundle-exec gem list -i #{gem_name}", success) + def stub_bundle_check(success) + stub_shellout("/home/git/gdk/support/bundle-exec bundle check", success) + end + + def stub_gem_installed(name, success) + stub_shellout("/home/git/gdk/support/bundle-exec gem list -i #{name}", success) end - def stub_gem_loads_ok(gem_name, success) + def stub_gem_loads_ok(name, success) + gem_name = GDK::Diagnostic::RubyGems::GEM_REQUIRE_MAPPING[name] stub_shellout("/home/git/gdk/support/bundle-exec ruby -r #{gem_name} -e 'nil'", success) end diff --git a/spec/lib/gdk/diagnostic_spec.rb b/spec/lib/gdk/diagnostic_spec.rb index 10be327a7ba35625b471c45a78920fa9a7678f3b..95bd03c14d07a1730c07c7f74ab913ddfd6b1e8b 100644 --- a/spec/lib/gdk/diagnostic_spec.rb +++ b/spec/lib/gdk/diagnostic_spec.rb @@ -11,7 +11,6 @@ GDK::Diagnostic::Environment, GDK::Diagnostic::RvmAndAsdf, GDK::Diagnostic::MacPorts, - GDK::Diagnostic::RubyGems, GDK::Diagnostic::Bundler, GDK::Diagnostic::Version, GDK::Diagnostic::Configuration,