Commit 138eb895 authored by Doug Stull's avatar Doug Stull Committed by Alper Akgun

Enable local env variable to set com likeness in dev

- better handling of self managed vs com in local development
parent 290f6ab2
......@@ -16,6 +16,13 @@ info: To determine the technical writer assigned to the Stage/Group associated w
[EE features list](https://about.gitlab.com/features/).
<!-- markdownlint-enable MD044 -->
## Act as SaaS
When developing locally, there are times when you need your instance to act like the SaaS version of the product.
In those instances, you can simulate SaaS by exporting an environment variable as seen below:
`export GITLAB_SIMULATE_SAAS=1`
## Act as CE when unlicensed
Since the implementation of
......
......@@ -49,9 +49,15 @@ module Gitlab
INSTALLATION_TYPE = File.read(root.join("INSTALLATION_TYPE")).strip.freeze
HTTP_PROXY_ENV_VARS = %w(http_proxy https_proxy HTTP_PROXY HTTPS_PROXY).freeze
def self.simulate_com?
return false unless Rails.env.test? || Rails.env.development?
Gitlab::Utils.to_boolean(ENV['GITLAB_SIMULATE_SAAS'])
end
def self.com?
# Check `gl_subdomain?` as well to keep parity with gitlab.com
Gitlab.config.gitlab.url == Gitlab::Saas.com_url || gl_subdomain?
simulate_com? || Gitlab.config.gitlab.url == Gitlab::Saas.com_url || gl_subdomain?
end
def self.com
......@@ -87,7 +93,7 @@ module Gitlab
end
def self.dev_env_or_com?
Rails.env.development? || com?
com?
end
def self.dev_or_test_env?
......
......@@ -111,6 +111,12 @@ RSpec.describe Gitlab do
expect(described_class.com?).to eq false
end
it 'is true when GITLAB_SIMULATE_SAAS is true' do
stub_env('GITLAB_SIMULATE_SAAS', '1')
expect(described_class.com?).to eq true
end
end
describe '.com' do
......@@ -210,13 +216,6 @@ RSpec.describe Gitlab do
expect(described_class.dev_env_org_or_com?).to eq true
end
it 'is true when dev env' do
allow(described_class).to receive_messages(com?: false, org?: false)
stub_rails_env('development')
expect(described_class.dev_env_org_or_com?).to eq true
end
it 'is false when not dev, org or com' do
allow(described_class).to receive_messages(com?: false, org?: false)
......@@ -225,23 +224,58 @@ RSpec.describe Gitlab do
end
describe '.dev_env_or_com?' do
it 'is true when on .com' do
allow(described_class).to receive(:com?).and_return(true)
it 'is correctly calling com?' do
expect(described_class).to receive(:com?).and_call_original
expect(described_class.dev_env_or_com?).to eq true
expect(described_class.dev_env_or_com?).to eq false
end
end
it 'is true when dev env' do
allow(described_class).to receive(:com?).and_return(false)
allow(Rails).to receive(:env).and_return(ActiveSupport::StringInquirer.new('development'))
describe '.simulate_com?' do
subject { described_class.simulate_com? }
context 'when GITLAB_SIMULATE_SAAS is true' do
before do
stub_env('GITLAB_SIMULATE_SAAS', '1')
end
expect(described_class.dev_env_or_com?).to eq true
it 'is true when test env' do
expect(subject).to eq true
end
it 'is true when dev env' do
stub_rails_env('development')
expect(subject).to eq true
end
it 'is false when env is not dev or test' do
stub_rails_env('production')
expect(subject).to eq false
end
end
it 'is false when not dev or com' do
allow(described_class).to receive(:com?).and_return(false)
context 'when GITLAB_SIMULATE_SAAS is false' do
before do
stub_env('GITLAB_SIMULATE_SAAS', '0')
end
expect(described_class.dev_env_or_com?).to eq false
it 'is false when test env' do
expect(subject).to eq false
end
it 'is false when dev env' do
stub_rails_env('development')
expect(subject).to eq false
end
it 'is false when env is not dev or test' do
stub_rails_env('production')
expect(subject).to eq false
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