2019-08-22 06:57:44 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-08-27 21:53:46 -04:00
|
|
|
require 'spec_helper'
|
2016-04-12 14:39:08 -04:00
|
|
|
|
2017-07-10 10:24:02 -04:00
|
|
|
describe Gitlab do
|
2018-04-10 10:07:47 -04:00
|
|
|
describe '.root' do
|
|
|
|
it 'returns the root path of the app' do
|
|
|
|
expect(described_class.root).to eq(Pathname.new(File.expand_path('../..', __dir__)))
|
|
|
|
end
|
|
|
|
end
|
2019-01-14 11:10:19 -05:00
|
|
|
|
2018-05-24 03:57:54 -04:00
|
|
|
describe '.revision' do
|
2019-03-28 07:05:03 -04:00
|
|
|
let(:cmd) { %W[#{described_class.config.git.bin_path} log --pretty=format:%h --abbrev=11 -n 1] }
|
2018-05-24 03:57:54 -04:00
|
|
|
|
|
|
|
around do |example|
|
|
|
|
described_class.instance_variable_set(:@_revision, nil)
|
|
|
|
example.run
|
|
|
|
described_class.instance_variable_set(:@_revision, nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a REVISION file exists' do
|
|
|
|
before do
|
|
|
|
expect(File).to receive(:exist?)
|
2019-09-13 09:26:31 -04:00
|
|
|
.with(described_class.root.join('REVISION'))
|
|
|
|
.and_return(true)
|
2018-05-24 03:57:54 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the actual Git revision' do
|
|
|
|
expect(File).to receive(:read)
|
2019-09-13 09:26:31 -04:00
|
|
|
.with(described_class.root.join('REVISION'))
|
|
|
|
.and_return("abc123\n")
|
2018-05-24 03:57:54 -04:00
|
|
|
|
|
|
|
expect(described_class.revision).to eq('abc123')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'memoizes the revision' do
|
|
|
|
expect(File).to receive(:read)
|
2019-09-13 09:26:31 -04:00
|
|
|
.once
|
|
|
|
.with(described_class.root.join('REVISION'))
|
|
|
|
.and_return("abc123\n")
|
2018-05-24 03:57:54 -04:00
|
|
|
|
|
|
|
2.times { described_class.revision }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when no REVISION file exist' do
|
|
|
|
context 'when the Git command succeeds' do
|
|
|
|
before do
|
|
|
|
expect(Gitlab::Popen).to receive(:popen_with_detail)
|
2019-09-13 09:26:31 -04:00
|
|
|
.with(cmd)
|
|
|
|
.and_return(Gitlab::Popen::Result.new(cmd, 'abc123', '', double(success?: true)))
|
2018-05-24 03:57:54 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the actual Git revision' do
|
|
|
|
expect(described_class.revision).to eq('abc123')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the Git command fails' do
|
|
|
|
before do
|
|
|
|
expect(Gitlab::Popen).to receive(:popen_with_detail)
|
2019-09-13 09:26:31 -04:00
|
|
|
.with(cmd)
|
|
|
|
.and_return(Gitlab::Popen::Result.new(cmd, '', 'fatal: Not a git repository', double('Process::Status', success?: false)))
|
2018-05-24 03:57:54 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns "Unknown"' do
|
|
|
|
expect(described_class.revision).to eq('Unknown')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-04-10 10:07:47 -04:00
|
|
|
|
2016-04-12 14:39:08 -04:00
|
|
|
describe '.com?' do
|
2019-10-02 20:05:59 -04:00
|
|
|
before do
|
|
|
|
Thread.current[:is_com] = nil
|
|
|
|
end
|
|
|
|
|
2016-04-12 14:39:08 -04:00
|
|
|
it 'is true when on GitLab.com' do
|
2019-10-02 20:05:59 -04:00
|
|
|
allow(LightSettings).to receive(:host).and_return('gitlab.com')
|
2016-04-12 14:39:08 -04:00
|
|
|
|
|
|
|
expect(described_class.com?).to eq true
|
|
|
|
end
|
|
|
|
|
2016-06-13 17:43:29 -04:00
|
|
|
it 'is true when on staging' do
|
2019-10-02 20:05:59 -04:00
|
|
|
allow(LightSettings).to receive(:host).and_return('staging.gitlab.com')
|
2016-06-13 17:43:29 -04:00
|
|
|
|
|
|
|
expect(described_class.com?).to eq true
|
|
|
|
end
|
|
|
|
|
2018-04-13 13:20:29 -04:00
|
|
|
it 'is true when on other gitlab subdomain' do
|
2019-10-02 20:05:59 -04:00
|
|
|
allow(LightSettings).to receive(:host).and_return('example.gitlab.com')
|
2018-04-13 13:20:29 -04:00
|
|
|
|
|
|
|
expect(described_class.com?).to eq true
|
|
|
|
end
|
|
|
|
|
2016-04-12 14:39:08 -04:00
|
|
|
it 'is false when not on GitLab.com' do
|
2019-10-02 20:05:59 -04:00
|
|
|
allow(LightSettings).to receive(:host).and_return('example.com')
|
2016-04-12 14:39:08 -04:00
|
|
|
|
|
|
|
expect(described_class.com?).to eq false
|
|
|
|
end
|
|
|
|
end
|
2019-03-04 03:20:37 -05:00
|
|
|
|
2019-08-27 21:29:52 -04:00
|
|
|
describe '.dev_env_org_or_com?' do
|
|
|
|
it 'is true when on .com' do
|
|
|
|
allow(described_class).to receive_messages(com?: true, org?: false)
|
|
|
|
|
|
|
|
expect(described_class.dev_env_org_or_com?).to eq true
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is true when org' do
|
|
|
|
allow(described_class).to receive_messages(com?: false, org?: true)
|
|
|
|
|
|
|
|
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)
|
2019-08-27 21:53:46 -04:00
|
|
|
stub_rails_env('development')
|
2019-08-27 21:29:52 -04:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
expect(described_class.dev_env_org_or_com?).to eq false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-09-13 09:26:31 -04:00
|
|
|
describe '.dev_env_or_com?' do
|
|
|
|
it 'is true when on .com' do
|
|
|
|
allow(described_class).to receive(:com?).and_return(true)
|
|
|
|
|
|
|
|
expect(described_class.dev_env_or_com?).to eq true
|
|
|
|
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'))
|
|
|
|
|
|
|
|
expect(described_class.dev_env_or_com?).to eq true
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is false when not dev or com' do
|
|
|
|
allow(described_class).to receive(:com?).and_return(false)
|
|
|
|
|
|
|
|
expect(described_class.dev_env_or_com?).to eq false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-03-04 03:20:37 -05:00
|
|
|
describe '.ee?' do
|
2019-06-13 08:18:01 -04:00
|
|
|
before do
|
|
|
|
described_class.instance_variable_set(:@is_ee, nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
described_class.instance_variable_set(:@is_ee, nil)
|
|
|
|
end
|
|
|
|
|
2019-03-04 03:20:37 -05:00
|
|
|
it 'returns true when using Enterprise Edition' do
|
2019-06-13 08:18:01 -04:00
|
|
|
root = Pathname.new('dummy')
|
|
|
|
license_path = double(:path, exist?: true)
|
|
|
|
|
|
|
|
allow(described_class)
|
|
|
|
.to receive(:root)
|
2019-09-13 09:26:31 -04:00
|
|
|
.and_return(root)
|
2019-06-13 08:18:01 -04:00
|
|
|
|
|
|
|
allow(root)
|
|
|
|
.to receive(:join)
|
2019-09-13 09:26:31 -04:00
|
|
|
.with('ee/app/models/license.rb')
|
|
|
|
.and_return(license_path)
|
2019-03-04 03:20:37 -05:00
|
|
|
|
|
|
|
expect(described_class.ee?).to eq(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false when using Community Edition' do
|
2019-06-13 08:18:01 -04:00
|
|
|
root = double(:path)
|
|
|
|
license_path = double(:path, exists?: false)
|
|
|
|
|
|
|
|
allow(described_class)
|
|
|
|
.to receive(:root)
|
2019-09-13 09:26:31 -04:00
|
|
|
.and_return(Pathname.new('dummy'))
|
2019-06-13 08:18:01 -04:00
|
|
|
|
|
|
|
allow(root)
|
|
|
|
.to receive(:join)
|
2019-09-13 09:26:31 -04:00
|
|
|
.with('ee/app/models/license.rb')
|
|
|
|
.and_return(license_path)
|
2019-03-04 03:20:37 -05:00
|
|
|
|
|
|
|
expect(described_class.ee?).to eq(false)
|
|
|
|
end
|
2019-07-22 11:11:50 -04:00
|
|
|
|
|
|
|
it 'returns true when the IS_GITLAB_EE variable is not empty' do
|
|
|
|
stub_env('IS_GITLAB_EE', '1')
|
|
|
|
|
|
|
|
expect(described_class.ee?).to eq(true)
|
|
|
|
end
|
2019-03-04 03:20:37 -05:00
|
|
|
end
|
2019-05-29 12:43:07 -04:00
|
|
|
|
|
|
|
describe '.http_proxy_env?' do
|
|
|
|
it 'returns true when lower case https' do
|
|
|
|
stub_env('https_proxy', 'https://my.proxy')
|
|
|
|
|
|
|
|
expect(described_class.http_proxy_env?).to eq(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns true when upper case https' do
|
|
|
|
stub_env('HTTPS_PROXY', 'https://my.proxy')
|
|
|
|
|
|
|
|
expect(described_class.http_proxy_env?).to eq(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns true when lower case http' do
|
|
|
|
stub_env('http_proxy', 'http://my.proxy')
|
|
|
|
|
|
|
|
expect(described_class.http_proxy_env?).to eq(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns true when upper case http' do
|
|
|
|
stub_env('HTTP_PROXY', 'http://my.proxy')
|
|
|
|
|
|
|
|
expect(described_class.http_proxy_env?).to eq(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false when not set' do
|
|
|
|
expect(described_class.http_proxy_env?).to eq(false)
|
|
|
|
end
|
|
|
|
end
|
2016-04-12 14:39:08 -04:00
|
|
|
end
|