Read about our upcoming Code of Conduct on this issue

Commit 937015ca authored by Tiger Watson's avatar Tiger Watson
Browse files

Merge branch...

Merge branch '1315-bundle_path-somehow-got-incorrectly-set-to-vendor-bundle-in-gitaly-test-directory' into 'main'

Resolve "BUNDLE_PATH somehow got incorrectly set to `vendor/bundle` in Gitaly test directory"

Closes #1315

See merge request gitlab-org/gitlab-development-kit!2201
......@@ -3,6 +3,7 @@
module GDK
module Diagnostic
autoload :Base, 'gdk/diagnostic/base'
autoload :Bundler, 'gdk/diagnostic/bundler'
autoload :Configuration, 'gdk/diagnostic/configuration'
autoload :Dependencies, 'gdk/diagnostic/dependencies'
autoload :Geo, 'gdk/diagnostic/geo'
......@@ -23,6 +24,7 @@ module GDK
klasses = %i[
RvmAndAsdf
RubyGems
Bundler
Version
Configuration
Dependencies
......
# frozen_string_literal: true
module GDK
module Diagnostic
class Bundler < Base
TITLE = 'Bundler'
def diagnose
nil
end
def success?
gitlab_bundle_config.bundle_path_not_set? &&
gitaly_bundle_config.bundle_path_not_set?
end
def detail
return if success?
output = []
output << gitlab_bundle_config.warning_detail
output << gitaly_bundle_config.warning_detail
output.compact.join("\n")
end
private
class BundleConfig
def initialize(path)
@path = path
end
def bundle_path_not_set?
@bundle_path_not_set ||= bundle_path.include?('You have not configured a value for `PATH`')
end
def warning_detail
return if bundle_path_not_set?
<<~WARNING
#{path} appears to have BUNDLE_PATH configured
which can cause issues. For more detail,
visit https://gitlab.com/gitlab-org/gitlab-development-kit/-/issues/1315
#{bundle_path}
WARNING
end
private
attr_reader :path
def bundle_path
@bundle_path ||= Shellout.new('bundle config get PATH', chdir: path)
.execute(display_output: false)
.read_stdout
end
end
def gitlab_bundle_config
@gitlab_bundle_config ||= BundleConfig.new(config.gitlab.dir)
end
def gitaly_bundle_config
@gitaly_bundle_config ||= BundleConfig.new(config.gitaly.ruby_dir)
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe GDK::Diagnostic::Bundler do
let(:gitlab_dir) { Pathname.new('/home/git/gdk/gitlab') }
let(:gitaly_ruby_dir) { Pathname.new('/home/git/gdk/gitaly/ruby') }
describe '#diagnose' do
it 'is a no-op' do
expect(subject.diagnose).to be_nil
end
end
describe '#success?' do
context 'when gitaly has a BUNDLE_PATH configured' do
it 'returns false' do
expect_bundle_path_not_set(gitlab_dir)
expect_bundle_path_set(gitaly_ruby_dir)
expect(subject).not_to be_success
end
end
context "when gitlab and gitaly don't have BUNDLE_PATH configured" do
it 'returns true' do
expect_bundle_path_not_set(gitlab_dir)
expect_bundle_path_not_set(gitaly_ruby_dir)
expect(subject).to be_success
end
end
end
describe '#detail' do
context 'when gitaly has a BUNDLE_PATH configured' do
it 'returns a message' do
expect_bundle_path_not_set(gitlab_dir)
expect_bundle_path_set(gitaly_ruby_dir)
expect(subject.detail).to match(/#{gitaly_ruby_dir} appears to have BUNDLE_PATH configured/)
end
end
context "when gitlab and gitaly don't have BUNDLE_PATH configured" do
it 'returns no message' do
expect_bundle_path_not_set(gitlab_dir)
expect_bundle_path_not_set(gitaly_ruby_dir)
expect(subject.detail).to be_nil
end
end
end
def expect_bundle_path_not_set(chdir)
expect_shellout(chdir, stdout: 'You have not configured a value for `PATH`')
end
def expect_bundle_path_set(chdir)
expect_shellout(chdir, stdout: 'Set for your local app (<path>/.bundle/config): "vendor/bundle"')
end
def expect_shellout(chdir, success: true, stdout: '', stderr: '')
shellout = double('Shellout', try_run: nil, read_stdout: stdout, read_stderr: stderr, success?: success)
expect(Shellout).to receive(:new).with('bundle config get PATH', chdir: chdir).and_return(shellout)
expect(shellout).to receive(:execute).with(display_output: false).and_return(shellout)
end
end
......@@ -12,6 +12,7 @@ RSpec.describe GDK::Diagnostic do
diagnostic_classes = [
GDK::Diagnostic::RvmAndAsdf,
GDK::Diagnostic::RubyGems,
GDK::Diagnostic::Bundler,
GDK::Diagnostic::Version,
GDK::Diagnostic::Configuration,
GDK::Diagnostic::Dependencies,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment