Commit 2d1a8ead authored by Lin Jen-Shin's avatar Lin Jen-Shin

Fix ee/ directory detection for Danger roulette

parent be656e39
...@@ -7,8 +7,10 @@ require 'danger/plugins/helper' ...@@ -7,8 +7,10 @@ require 'danger/plugins/helper'
require 'gitlab/dangerfiles/spec_helper' require 'gitlab/dangerfiles/spec_helper'
require_relative '../../../danger/plugins/project_helper' require_relative '../../../danger/plugins/project_helper'
require_relative '../../../spec/support/helpers/stub_env'
RSpec.describe Tooling::Danger::ProjectHelper do RSpec.describe Tooling::Danger::ProjectHelper do
include StubENV
include_context "with dangerfile" include_context "with dangerfile"
let(:fake_danger) { DangerSpecHelper.fake_danger.include(described_class) } let(:fake_danger) { DangerSpecHelper.fake_danger.include(described_class) }
...@@ -288,6 +290,70 @@ RSpec.describe Tooling::Danger::ProjectHelper do ...@@ -288,6 +290,70 @@ RSpec.describe Tooling::Danger::ProjectHelper do
end end
end end
describe '#ee?' do
subject { project_helper.__send__(:ee?) }
let(:ee_dir) { File.expand_path('../../../ee', __dir__) }
context 'when ENV["CI_PROJECT_NAME"] is set' do
before do
stub_env('CI_PROJECT_NAME', ci_project_name)
end
context 'when ENV["CI_PROJECT_NAME"] is gitlab' do
let(:ci_project_name) { 'gitlab' }
it 'returns true' do
is_expected.to eq(true)
end
end
context 'when ENV["CI_PROJECT_NAME"] is gitlab-ee' do
let(:ci_project_name) { 'gitlab-ee' }
it 'returns true' do
is_expected.to eq(true)
end
end
context 'when ENV["CI_PROJECT_NAME"] is gitlab-foss' do
let(:ci_project_name) { 'gitlab-foss' }
it 'resolves to Dir.exist?' do
expected = Dir.exist?(ee_dir)
expect(Dir).to receive(:exist?).with(ee_dir).and_call_original
is_expected.to eq(expected)
end
end
end
context 'when ENV["CI_PROJECT_NAME"] is absent' do
before do
stub_env('CI_PROJECT_NAME', nil)
expect(Dir).to receive(:exist?).with(ee_dir).and_return(has_ee_dir)
end
context 'when ee/ directory exists' do
let(:has_ee_dir) { true }
it 'returns true' do
is_expected.to eq(true)
end
end
context 'when ee/ directory does not exist' do
let(:has_ee_dir) { false }
it 'returns false' do
is_expected.to eq(false)
end
end
end
end
describe '#file_lines' do describe '#file_lines' do
let(:filename) { 'spec/foo_spec.rb' } let(:filename) { 'spec/foo_spec.rb' }
let(:file_spy) { spy } let(:file_spy) { spy }
......
...@@ -202,7 +202,7 @@ module Tooling ...@@ -202,7 +202,7 @@ module Tooling
def ee? def ee?
# Support former project name for `dev` and support local Danger run # Support former project name for `dev` and support local Danger run
%w[gitlab gitlab-ee].include?(ENV['CI_PROJECT_NAME']) || Dir.exist?(File.expand_path('../../../ee', __dir__)) %w[gitlab gitlab-ee].include?(ENV['CI_PROJECT_NAME']) || Dir.exist?(File.expand_path('../../ee', __dir__))
end end
end end
end end
......
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