Commit 7141831e authored by Pavel Shutsin's avatar Pavel Shutsin Committed by Thong Kuah

Use default license path in seeds

In dev mode we can use license in
default license path if it exists
parent 4c9f18d1
...@@ -16,15 +16,8 @@ namespace :gitlab do ...@@ -16,15 +16,8 @@ namespace :gitlab do
task :load, [:mode] => :environment do |_, args| task :load, [:mode] => :environment do |_, args|
args.with_defaults(mode: 'default') args.with_defaults(mode: 'default')
verbose = args[:mode] == 'verbose'
flag = 'GITLAB_LICENSE_FILE' flag = 'GITLAB_LICENSE_FILE'
if ENV[flag].blank? && verbose
puts "Skipped. Use the `#{flag}` environment variable to seed the License file of the given path."
next
end
default_license_file = Settings.source.dirname + 'Gitlab.gitlab-license' default_license_file = Settings.source.dirname + 'Gitlab.gitlab-license'
license_file = ENV.fetch(flag, default_license_file) license_file = ENV.fetch(flag, default_license_file)
...@@ -35,9 +28,11 @@ namespace :gitlab do ...@@ -35,9 +28,11 @@ namespace :gitlab do
puts "License Invalid:\n\nFilePath: #{license_file}".color(:red) puts "License Invalid:\n\nFilePath: #{license_file}".color(:red)
raise "License Invalid" raise "License Invalid"
end end
elsif !ENV[flag].blank? elsif ENV[flag].present?
puts "License File Missing:\n\nFilePath: #{license_file}".color(:red) puts "License File Missing:\n\nFilePath: #{license_file}".color(:red)
raise "License File Missing" raise "License File Missing"
elsif args[:mode] == 'verbose'
puts "Skipped. Use the `#{flag}` environment variable to seed the License file of the given path."
end end
end end
end end
......
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
require 'rake_helper' require 'rake_helper'
RSpec.describe 'gitlab:license namespace rake tasks' do RSpec.describe 'gitlab:license namespace rake tasks' do
let(:default_license_path) { Settings.source.dirname + 'Gitlab.gitlab-license' }
before do before do
Rake.application.rake_require 'tasks/gitlab/license' Rake.application.rake_require 'tasks/gitlab/license'
end end
...@@ -56,11 +58,32 @@ RSpec.describe 'gitlab:license namespace rake tasks' do ...@@ -56,11 +58,32 @@ RSpec.describe 'gitlab:license namespace rake tasks' do
end end
end end
context 'when GITLAB_LICENSE_FILE env variable is not set' do
let(:license_file_contents) { 'valid contents' }
context 'when default valid license file does exist' do
before do
allow(File).to receive(:file?).with(default_license_path).and_return(true)
end
it 'succeeds in adding the license' do
expect_file_read(default_license_path, content: license_file_contents)
expect(License).to receive(:create).with(data: license_file_contents).and_return(true)
expect { subject }.not_to raise_error
end
end
end
context 'running in mode verbose' do context 'running in mode verbose' do
let(:mode) { 'verbose' } let(:mode) { 'verbose' }
it 'outputs a the help message' do context 'when default valid license file does not exist' do
expect { subject }.to output(/environment variable to seed the License file of the given path/).to_stdout it 'outputs a the help message' do
allow(File).to receive(:file?).with(default_license_path).and_return(false)
expect { subject }.to output(/environment variable to seed the License file of the given path/).to_stdout
end
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