gitlab-org--gitlab-foss/spec/tasks/gitlab/task_helpers_spec.rb
Alejandro Rodríguez e61325ff43 Expand components version specification format to allow branches
Currently we specify versions for Gitlab-Shell, Workhorse and Gitaly
using version strings, to which we prepend 'v' and assume are tags.
These changes allow branches or tags with other name formats to be
specified by prepending '=' to the version string (á la govendor).

We also simplify the process to reset to the given version (now a
branch or tag): Right now there's a check to supposedly try to avoid
fetching from the remote the version if it already exist locally. But
the previous logic already clones if the directory doesn't exist or
fetches if it does, so this check is pointless. We can safely assume the
version exists once we get to the reset stage.
2017-04-13 17:32:00 -03:00

89 lines
2.7 KiB
Ruby

require 'spec_helper'
require 'tasks/gitlab/task_helpers'
class TestHelpersTest
include Gitlab::TaskHelpers
end
describe Gitlab::TaskHelpers do
subject { TestHelpersTest.new }
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_version' do
before do
allow(subject).to receive(:run_command!)
end
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_version(version: version, repo: repo, target_dir: clone_path)
end
end
context 'target_dir exists' do
before do
expect(Dir).to receive(:exist?).and_return(true)
end
it "doesn't clone the repository" do
expect(subject).not_to receive(:clone_repo)
subject.checkout_or_clone_version(version: version, repo: repo, target_dir: clone_path)
end
end
end
describe '#clone_repo' do
it 'clones the repo in the target dir' do
expect(subject).
to receive(:run_command!).with(%W[#{Gitlab.config.git.bin_path} clone -- #{repo} #{clone_path}])
subject.clone_repo(repo, clone_path)
end
end
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 --quiet])
expect(subject).
to receive(:run_command!).with(%W[#{Gitlab.config.git.bin_path} -C #{clone_path} checkout --quiet #{tag}])
subject.checkout_version(tag, clone_path)
end
end
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}])
subject.reset_to_version(tag, clone_path)
end
end
end