summaryrefslogtreecommitdiff
path: root/spec/tasks
diff options
context:
space:
mode:
Diffstat (limited to 'spec/tasks')
-rw-r--r--spec/tasks/config_lint_spec.rb4
-rw-r--r--spec/tasks/gitlab/backup_rake_spec.rb7
-rw-r--r--spec/tasks/gitlab/gitaly_rake_spec.rb44
-rw-r--r--spec/tasks/gitlab/shell_rake_spec.rb4
-rw-r--r--spec/tasks/gitlab/task_helpers_spec.rb73
-rw-r--r--spec/tasks/gitlab/workhorse_rake_spec.rb12
6 files changed, 87 insertions, 57 deletions
diff --git a/spec/tasks/config_lint_spec.rb b/spec/tasks/config_lint_spec.rb
index c32f9a740b7..ed6c5b09663 100644
--- a/spec/tasks/config_lint_spec.rb
+++ b/spec/tasks/config_lint_spec.rb
@@ -5,11 +5,11 @@ describe ConfigLint do
let(:files){ ['lib/support/fake.sh'] }
it 'errors out if any bash scripts have errors' do
- expect { ConfigLint.run(files){ system('exit 1') } }.to raise_error(SystemExit)
+ expect { described_class.run(files){ system('exit 1') } }.to raise_error(SystemExit)
end
it 'passes if all scripts are fine' do
- expect { ConfigLint.run(files){ system('exit 0') } }.not_to raise_error
+ expect { described_class.run(files){ system('exit 0') } }.not_to raise_error
end
end
diff --git a/spec/tasks/gitlab/backup_rake_spec.rb b/spec/tasks/gitlab/backup_rake_spec.rb
index daea0c6bb37..0ff1a988a9e 100644
--- a/spec/tasks/gitlab/backup_rake_spec.rb
+++ b/spec/tasks/gitlab/backup_rake_spec.rb
@@ -230,9 +230,10 @@ describe 'gitlab:app namespace rake task' do
before do
FileUtils.mkdir('tmp/tests/default_storage')
FileUtils.mkdir('tmp/tests/custom_storage')
+ gitaly_address = Gitlab.config.repositories.storages.default.gitaly_address
storages = {
- 'default' => { 'path' => Settings.absolute('tmp/tests/default_storage') },
- 'custom' => { 'path' => Settings.absolute('tmp/tests/custom_storage') }
+ 'default' => { 'path' => Settings.absolute('tmp/tests/default_storage'), 'gitaly_address' => gitaly_address },
+ 'custom' => { 'path' => Settings.absolute('tmp/tests/custom_storage'), 'gitaly_address' => gitaly_address }
}
allow(Gitlab.config.repositories).to receive(:storages).and_return(storages)
@@ -350,7 +351,7 @@ describe 'gitlab:app namespace rake task' do
end
it 'name has human readable time' do
- expect(@backup_tar).to match(/\d+_\d{4}_\d{2}_\d{2}_gitlab_backup.tar$/)
+ expect(@backup_tar).to match(/\d+_\d{4}_\d{2}_\d{2}_\d+\.\d+\.\d+.*_gitlab_backup.tar$/)
end
end
end # gitlab:app namespace
diff --git a/spec/tasks/gitlab/gitaly_rake_spec.rb b/spec/tasks/gitlab/gitaly_rake_spec.rb
index d95baddf546..4a636decafd 100644
--- a/spec/tasks/gitlab/gitaly_rake_spec.rb
+++ b/spec/tasks/gitlab/gitaly_rake_spec.rb
@@ -8,7 +8,7 @@ describe 'gitlab:gitaly namespace rake task' do
describe 'install' do
let(:repo) { 'https://gitlab.com/gitlab-org/gitaly.git' }
let(:clone_path) { Rails.root.join('tmp/tests/gitaly').to_s }
- let(:tag) { "v#{File.read(Rails.root.join(Gitlab::GitalyClient::SERVER_VERSION_FILE)).chomp}" }
+ let(:version) { File.read(Rails.root.join(Gitlab::GitalyClient::SERVER_VERSION_FILE)).chomp }
context 'no dir given' do
it 'aborts and display a help message' do
@@ -21,7 +21,7 @@ describe 'gitlab:gitaly namespace rake task' do
context 'when an underlying Git command fail' do
it 'aborts and display a help message' do
expect_any_instance_of(Object).
- to receive(:checkout_or_clone_tag).and_raise 'Git error'
+ to receive(:checkout_or_clone_version).and_raise 'Git error'
expect { run_rake_task('gitlab:gitaly:install', clone_path) }.to raise_error 'Git error'
end
@@ -32,9 +32,9 @@ describe 'gitlab:gitaly namespace rake task' do
expect(Dir).to receive(:chdir).with(clone_path)
end
- it 'calls checkout_or_clone_tag with the right arguments' do
+ it 'calls checkout_or_clone_version with the right arguments' do
expect_any_instance_of(Object).
- to receive(:checkout_or_clone_tag).with(tag: tag, repo: repo, target_dir: clone_path)
+ to receive(:checkout_or_clone_version).with(version: version, repo: repo, target_dir: clone_path)
run_rake_task('gitlab:gitaly:install', clone_path)
end
@@ -48,7 +48,7 @@ describe 'gitlab:gitaly namespace rake task' do
context 'gmake is available' do
before do
- expect_any_instance_of(Object).to receive(:checkout_or_clone_tag)
+ expect_any_instance_of(Object).to receive(:checkout_or_clone_version)
allow_any_instance_of(Object).to receive(:run_command!).with(['gmake']).and_return(true)
end
@@ -62,7 +62,7 @@ describe 'gitlab:gitaly namespace rake task' do
context 'gmake is not available' do
before do
- expect_any_instance_of(Object).to receive(:checkout_or_clone_tag)
+ expect_any_instance_of(Object).to receive(:checkout_or_clone_version)
allow_any_instance_of(Object).to receive(:run_command!).with(['make']).and_return(true)
end
@@ -75,4 +75,36 @@ describe 'gitlab:gitaly namespace rake task' do
end
end
end
+
+ describe 'storage_config' do
+ it 'prints storage configuration in a TOML format' do
+ config = {
+ 'default' => { 'path' => '/path/to/default' },
+ 'nfs_01' => { 'path' => '/path/to/nfs_01' }
+ }
+ allow(Gitlab.config.repositories).to receive(:storages).and_return(config)
+
+ expected_output = ''
+ Timecop.freeze do
+ expected_output = <<~TOML
+ # Gitaly storage configuration generated from #{Gitlab.config.source} on #{Time.current.to_s(:long)}
+ # This is in TOML format suitable for use in Gitaly's config.toml file.
+ [[storage]]
+ name = "default"
+ path = "/path/to/default"
+ [[storage]]
+ name = "nfs_01"
+ path = "/path/to/nfs_01"
+ TOML
+ end
+
+ expect { run_rake_task('gitlab:gitaly:storage_config')}.
+ to output(expected_output).to_stdout
+
+ parsed_output = TOML.parse(expected_output)
+ config.each do |name, params|
+ expect(parsed_output['storage']).to include({ 'name' => name, 'path' => params['path'] })
+ end
+ end
+ end
end
diff --git a/spec/tasks/gitlab/shell_rake_spec.rb b/spec/tasks/gitlab/shell_rake_spec.rb
index 226d34fe2c9..ee3614c50f6 100644
--- a/spec/tasks/gitlab/shell_rake_spec.rb
+++ b/spec/tasks/gitlab/shell_rake_spec.rb
@@ -11,6 +11,10 @@ describe 'gitlab:shell rake tasks' do
it 'invokes create_hooks task' do
expect(Rake::Task['gitlab:shell:create_hooks']).to receive(:invoke)
+ storages = Gitlab.config.repositories.storages.values.map { |rs| rs['path'] }
+ expect(Kernel).to receive(:system).with('bin/install', *storages).and_call_original
+ expect(Kernel).to receive(:system).with('bin/compile').and_call_original
+
run_rake_task('gitlab:shell:install')
end
end
diff --git a/spec/tasks/gitlab/task_helpers_spec.rb b/spec/tasks/gitlab/task_helpers_spec.rb
index 86e42d845ce..3d9ba7cdc6f 100644
--- a/spec/tasks/gitlab/task_helpers_spec.rb
+++ b/spec/tasks/gitlab/task_helpers_spec.rb
@@ -10,19 +10,38 @@ describe Gitlab::TaskHelpers do
let(:repo) { 'https://gitlab.com/gitlab-org/gitlab-test.git' }
let(:clone_path) { Rails.root.join('tmp/tests/task_helpers_tests').to_s }
+ let(:version) { '1.1.0' }
let(:tag) { 'v1.1.0' }
- describe '#checkout_or_clone_tag' do
+ describe '#checkout_or_clone_version' do
before do
allow(subject).to receive(:run_command!)
- expect(subject).to receive(:reset_to_tag).with(tag, clone_path)
end
- context 'target_dir does not exist' do
- it 'clones the repo, retrieve the tag from origin, and checkout the tag' do
+ it 'checkout the version and reset to it' do
+ expect(subject).to receive(:checkout_version).with(tag, clone_path)
+ expect(subject).to receive(:reset_to_version).with(tag, clone_path)
+
+ subject.checkout_or_clone_version(version: version, repo: repo, target_dir: clone_path)
+ end
+
+ context 'with a branch version' do
+ let(:version) { '=branch_name' }
+ let(:branch) { 'branch_name' }
+
+ it 'checkout the version and reset to it with a branch name' do
+ expect(subject).to receive(:checkout_version).with(branch, clone_path)
+ expect(subject).to receive(:reset_to_version).with(branch, clone_path)
+
+ subject.checkout_or_clone_version(version: version, repo: repo, target_dir: clone_path)
+ end
+ end
+
+ context "target_dir doesn't exist" do
+ it 'clones the repo' do
expect(subject).to receive(:clone_repo).with(repo, clone_path)
- subject.checkout_or_clone_tag(tag: tag, repo: repo, target_dir: clone_path)
+ subject.checkout_or_clone_version(version: version, repo: repo, target_dir: clone_path)
end
end
@@ -31,10 +50,10 @@ describe Gitlab::TaskHelpers do
expect(Dir).to receive(:exist?).and_return(true)
end
- it 'fetch and checkout the tag' do
- expect(subject).to receive(:checkout_tag).with(tag, clone_path)
+ it "doesn't clone the repository" do
+ expect(subject).not_to receive(:clone_repo)
- subject.checkout_or_clone_tag(tag: tag, repo: repo, target_dir: clone_path)
+ subject.checkout_or_clone_version(version: version, repo: repo, target_dir: clone_path)
end
end
end
@@ -48,49 +67,23 @@ describe Gitlab::TaskHelpers do
end
end
- describe '#checkout_tag' do
+ describe '#checkout_version' do
it 'clones the repo in the target dir' do
expect(subject).
- to receive(:run_command!).with(%W[#{Gitlab.config.git.bin_path} -C #{clone_path} fetch --tags --quiet])
+ to receive(:run_command!).with(%W[#{Gitlab.config.git.bin_path} -C #{clone_path} fetch --quiet])
expect(subject).
to receive(:run_command!).with(%W[#{Gitlab.config.git.bin_path} -C #{clone_path} checkout --quiet #{tag}])
- subject.checkout_tag(tag, clone_path)
+ subject.checkout_version(tag, clone_path)
end
end
- describe '#reset_to_tag' do
- let(:tag) { 'v1.1.0' }
- before do
+ describe '#reset_to_version' do
+ it 'resets --hard to the given version' do
expect(subject).
to receive(:run_command!).with(%W[#{Gitlab.config.git.bin_path} -C #{clone_path} reset --hard #{tag}])
- end
- context 'when the tag is not checked out locally' do
- before do
- expect(subject).
- to receive(:run_command!).with(%W[#{Gitlab.config.git.bin_path} -C #{clone_path} describe -- #{tag}]).and_raise(Gitlab::TaskFailedError)
- end
-
- it 'fetch origin, ensure the tag exists, and resets --hard to the given tag' do
- expect(subject).
- to receive(:run_command!).with(%W[#{Gitlab.config.git.bin_path} -C #{clone_path} fetch origin])
- expect(subject).
- to receive(:run_command!).with(%W[#{Gitlab.config.git.bin_path} -C #{clone_path} describe -- origin/#{tag}]).and_return(tag)
-
- subject.reset_to_tag(tag, clone_path)
- end
- end
-
- context 'when the tag is checked out locally' do
- before do
- expect(subject).
- to receive(:run_command!).with(%W[#{Gitlab.config.git.bin_path} -C #{clone_path} describe -- #{tag}]).and_return(tag)
- end
-
- it 'resets --hard to the given tag' do
- subject.reset_to_tag(tag, clone_path)
- end
+ subject.reset_to_version(tag, clone_path)
end
end
end
diff --git a/spec/tasks/gitlab/workhorse_rake_spec.rb b/spec/tasks/gitlab/workhorse_rake_spec.rb
index 8a66a4aa047..63d1cf2bbe5 100644
--- a/spec/tasks/gitlab/workhorse_rake_spec.rb
+++ b/spec/tasks/gitlab/workhorse_rake_spec.rb
@@ -8,7 +8,7 @@ describe 'gitlab:workhorse namespace rake task' do
describe 'install' do
let(:repo) { 'https://gitlab.com/gitlab-org/gitlab-workhorse.git' }
let(:clone_path) { Rails.root.join('tmp/tests/gitlab-workhorse').to_s }
- let(:tag) { "v#{File.read(Rails.root.join(Gitlab::Workhorse::VERSION_FILE)).chomp}" }
+ let(:version) { File.read(Rails.root.join(Gitlab::Workhorse::VERSION_FILE)).chomp }
context 'no dir given' do
it 'aborts and display a help message' do
@@ -21,7 +21,7 @@ describe 'gitlab:workhorse namespace rake task' do
context 'when an underlying Git command fail' do
it 'aborts and display a help message' do
expect_any_instance_of(Object).
- to receive(:checkout_or_clone_tag).and_raise 'Git error'
+ to receive(:checkout_or_clone_version).and_raise 'Git error'
expect { run_rake_task('gitlab:workhorse:install', clone_path) }.to raise_error 'Git error'
end
@@ -32,9 +32,9 @@ describe 'gitlab:workhorse namespace rake task' do
expect(Dir).to receive(:chdir).with(clone_path)
end
- it 'calls checkout_or_clone_tag with the right arguments' do
+ it 'calls checkout_or_clone_version with the right arguments' do
expect_any_instance_of(Object).
- to receive(:checkout_or_clone_tag).with(tag: tag, repo: repo, target_dir: clone_path)
+ to receive(:checkout_or_clone_version).with(version: version, repo: repo, target_dir: clone_path)
run_rake_task('gitlab:workhorse:install', clone_path)
end
@@ -48,7 +48,7 @@ describe 'gitlab:workhorse namespace rake task' do
context 'gmake is available' do
before do
- expect_any_instance_of(Object).to receive(:checkout_or_clone_tag)
+ expect_any_instance_of(Object).to receive(:checkout_or_clone_version)
allow_any_instance_of(Object).to receive(:run_command!).with(['gmake']).and_return(true)
end
@@ -62,7 +62,7 @@ describe 'gitlab:workhorse namespace rake task' do
context 'gmake is not available' do
before do
- expect_any_instance_of(Object).to receive(:checkout_or_clone_tag)
+ expect_any_instance_of(Object).to receive(:checkout_or_clone_version)
allow_any_instance_of(Object).to receive(:run_command!).with(['make']).and_return(true)
end