Commit 56d95d9a authored by Thong Kuah's avatar Thong Kuah

Merge branch 'use-default-license-file-in-seeds' into 'master'

Use default license path in seeds

See merge request gitlab-org/gitlab!54212
parents 78c96fd3 7141831e
......@@ -16,15 +16,8 @@ namespace :gitlab do
task :load, [:mode] => :environment do |_, args|
args.with_defaults(mode: 'default')
verbose = args[:mode] == 'verbose'
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'
license_file = ENV.fetch(flag, default_license_file)
......@@ -35,9 +28,11 @@ namespace :gitlab do
puts "License Invalid:\n\nFilePath: #{license_file}".color(:red)
raise "License Invalid"
end
elsif !ENV[flag].blank?
elsif ENV[flag].present?
puts "License File Missing:\n\nFilePath: #{license_file}".color(:red)
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
......
......@@ -3,6 +3,8 @@
require 'rake_helper'
RSpec.describe 'gitlab:license namespace rake tasks' do
let(:default_license_path) { Settings.source.dirname + 'Gitlab.gitlab-license' }
before do
Rake.application.rake_require 'tasks/gitlab/license'
end
......@@ -56,12 +58,33 @@ RSpec.describe 'gitlab:license namespace rake tasks' do
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
let(:mode) { 'verbose' }
context 'when default valid license file does not exist' do
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
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