2018-03-29 05:49:08 -04:00
|
|
|
require 'fast_spec_helper'
|
|
|
|
|
|
|
|
require_dependency 'gitlab'
|
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
|
|
|
|
let(:cmd) { %W[#{described_class.config.git.bin_path} log --pretty=format:%h -n 1] }
|
|
|
|
|
|
|
|
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?)
|
|
|
|
.with(described_class.root.join('REVISION'))
|
|
|
|
.and_return(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the actual Git revision' do
|
|
|
|
expect(File).to receive(:read)
|
|
|
|
.with(described_class.root.join('REVISION'))
|
|
|
|
.and_return("abc123\n")
|
|
|
|
|
|
|
|
expect(described_class.revision).to eq('abc123')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'memoizes the revision' do
|
|
|
|
expect(File).to receive(:read)
|
|
|
|
.once
|
|
|
|
.with(described_class.root.join('REVISION'))
|
|
|
|
.and_return("abc123\n")
|
|
|
|
|
|
|
|
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)
|
|
|
|
.with(cmd)
|
|
|
|
.and_return(Gitlab::Popen::Result.new(cmd, 'abc123', '', double(success?: true)))
|
|
|
|
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)
|
|
|
|
.with(cmd)
|
|
|
|
.and_return(Gitlab::Popen::Result.new(cmd, '', 'fatal: Not a git repository', double('Process::Status', success?: false)))
|
|
|
|
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
|
|
|
|
it 'is true when on GitLab.com' do
|
|
|
|
stub_config_setting(url: 'https://gitlab.com')
|
|
|
|
|
|
|
|
expect(described_class.com?).to eq true
|
|
|
|
end
|
|
|
|
|
2016-06-13 17:43:29 -04:00
|
|
|
it 'is true when on staging' do
|
|
|
|
stub_config_setting(url: 'https://staging.gitlab.com')
|
|
|
|
|
|
|
|
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
|
|
|
|
stub_config_setting(url: 'https://example.gitlab.com')
|
|
|
|
|
|
|
|
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
|
|
|
|
stub_config_setting(url: 'http://example.com')
|
|
|
|
|
|
|
|
expect(described_class.com?).to eq false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|