summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/acceptance/clone_repo_spec.rb24
-rw-r--r--spec/acceptance/modules_753_spec.rb68
-rw-r--r--spec/spec_helper_acceptance.rb22
-rw-r--r--spec/unit/puppet/provider/vcsrepo/git_spec.rb32
-rw-r--r--spec/unit/puppet/provider/vcsrepo/svn_spec.rb43
5 files changed, 156 insertions, 33 deletions
diff --git a/spec/acceptance/clone_repo_spec.rb b/spec/acceptance/clone_repo_spec.rb
index 2cca061..c234550 100644
--- a/spec/acceptance/clone_repo_spec.rb
+++ b/spec/acceptance/clone_repo_spec.rb
@@ -38,6 +38,30 @@ describe 'clones a remote repo' do
end
end
+ context 'using a https source on github' do
+ it 'clones a repo' do
+ pp = <<-EOS
+ vcsrepo { "#{tmpdir}/httpstestrepo":
+ ensure => present,
+ provider => git,
+ source => "https://github.com/puppetlabs/puppetlabs-vcsrepo.git",
+ }
+ EOS
+
+ # Run it twice and test for idempotency
+ apply_manifest(pp, :catch_failures => true)
+ apply_manifest(pp, :catch_changes => true)
+ end
+
+ describe file("#{tmpdir}/httpstestrepo/.git") do
+ it { is_expected.to be_directory }
+ end
+
+ describe file("#{tmpdir}/httpstestrepo/.git/HEAD") do
+ it { is_expected.to contain 'ref: refs/heads/master' }
+ end
+ end
+
context 'using a commit SHA' do
let (:sha) do
shell("git --git-dir=#{tmpdir}/testrepo.git rev-list HEAD | tail -1").stdout.chomp
diff --git a/spec/acceptance/modules_753_spec.rb b/spec/acceptance/modules_753_spec.rb
new file mode 100644
index 0000000..e4e332b
--- /dev/null
+++ b/spec/acceptance/modules_753_spec.rb
@@ -0,0 +1,68 @@
+require 'spec_helper_acceptance'
+
+tmpdir = default.tmpdir('vcsrepo')
+
+describe 'clones a remote repo' do
+ before(:all) do
+ my_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
+ shell("mkdir -p #{tmpdir}") # win test
+ end
+
+ after(:all) do
+ shell("rm -rf #{tmpdir}/vcsrepo")
+ end
+
+ context 'clone with single remote' do
+ it 'clones from default remote' do
+ pp = <<-EOS
+ vcsrepo { "#{tmpdir}/vcsrepo":
+ ensure => present,
+ provider => git,
+ source => "https://github.com/puppetlabs/puppetlabs-vcsrepo.git",
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true)
+
+ end
+
+ it "git config output should contain the remote" do
+ shell("/usr/bin/git config -l -f #{tmpdir}/vcsrepo/.git/config") do |r|
+ expect(r.stdout).to match(/remote.origin.url=https:\/\/github.com\/puppetlabs\/puppetlabs-vcsrepo.git/)
+ end
+ end
+
+ after(:all) do
+ shell("rm -rf #{tmpdir}/vcsrepo")
+ end
+
+ end
+
+ context 'clone with multiple remotes' do
+ it 'clones from default remote and adds 2 remotes to config file' do
+ pp = <<-EOS
+ vcsrepo { "#{tmpdir}/vcsrepo":
+ ensure => present,
+ provider => git,
+ source => {"origin" => "https://github.com/puppetlabs/puppetlabs-vcsrepo.git", "test1" => "https://github.com/puppetlabs/puppetlabs-vcsrepo.git"},
+ }
+ EOS
+
+ apply_manifest(pp, :catch_failures => true)
+
+ end
+
+ it "git config output should contain the remotes" do
+ shell("/usr/bin/git config -l -f #{tmpdir}/vcsrepo/.git/config") do |r|
+ expect(r.stdout).to match(/remote.origin.url=https:\/\/github.com\/puppetlabs\/puppetlabs-vcsrepo.git/)
+ expect(r.stdout).to match(/remote.test1.url=https:\/\/github.com\/puppetlabs\/puppetlabs-vcsrepo.git/)
+ end
+ end
+
+ after(:all) do
+ shell("rm -rf #{tmpdir}/vcsrepo")
+ end
+
+ end
+
+end
diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb
index 9ef826a..97c43e8 100644
--- a/spec/spec_helper_acceptance.rb
+++ b/spec/spec_helper_acceptance.rb
@@ -1,25 +1,7 @@
require 'beaker-rspec'
+require 'beaker/puppet_install_helper'
-unless ENV['RS_PROVISION'] == 'no' or ENV['BEAKER_provision'] == 'no'
- # This will install the latest available package on el and deb based
- # systems fail on windows and osx, and install via gem on other *nixes
- foss_opts = { :default_action => 'gem_install' }
-
- if default.is_pe?; then install_pe; else install_puppet( foss_opts ); end
-
- hosts.each do |host|
- unless host.is_pe?
- on hosts, "mkdir -p #{hosts.first['distmoduledir']}"
- end
-
- # We ask the host to interpolate it's distmoduledir because we don't
- # actually know it on Windows until we've let it redirect us (depending
- # on whether we're running as a 32/64 bit process on 32/64 bit Windows
- moduledir = on(host, "echo #{host['distmoduledir']}").stdout.chomp
- on host, "mkdir -p #{moduledir}"
- end
-end
-
+run_puppet_install_helper
RSpec.configure do |c|
# Project root
diff --git a/spec/unit/puppet/provider/vcsrepo/git_spec.rb b/spec/unit/puppet/provider/vcsrepo/git_spec.rb
index 29c6b3b..a240b50 100644
--- a/spec/unit/puppet/provider/vcsrepo/git_spec.rb
+++ b/spec/unit/puppet/provider/vcsrepo/git_spec.rb
@@ -35,6 +35,7 @@ branches
Dir.expects(:chdir).with('/tmp/test').at_least_once.yields
provider.expects(:git).with('clone', resource.value(:source), resource.value(:path))
provider.expects(:update_submodules)
+ provider.expects(:update_remote_url).with("origin", resource.value(:source)).returns false
provider.expects(:git).with('branch', '-a').returns(branch_a_list(resource.value(:revision)))
provider.expects(:git).with('checkout', '--force', resource.value(:revision))
provider.create
@@ -48,6 +49,7 @@ branches
Dir.expects(:chdir).with('/tmp/test').at_least_once.yields
provider.expects(:git).with('clone', '--origin', 'not_origin', resource.value(:source), resource.value(:path))
provider.expects(:update_submodules)
+ provider.expects(:update_remote_url).with("not_origin", resource.value(:source)).returns false
provider.expects(:git).with('branch', '-a').returns(branch_a_list(resource.value(:revision)))
provider.expects(:git).with('checkout', '--force', resource.value(:revision))
provider.create
@@ -62,6 +64,7 @@ branches
Dir.expects(:chdir).with('/tmp/test').at_least_once.yields
provider.expects(:git).with('clone', '--depth', '1', '--branch', resource.value(:revision),resource.value(:source), resource.value(:path))
provider.expects(:update_submodules)
+ provider.expects(:update_remote_url).with("origin", resource.value(:source)).returns false
provider.expects(:git).with('branch', '-a').returns(branch_a_list(resource.value(:revision)))
provider.expects(:git).with('checkout', '--force', resource.value(:revision))
provider.create
@@ -75,6 +78,7 @@ branches
Dir.expects(:chdir).with('/tmp/test').at_least_once.yields
provider.expects(:git).with('clone', resource.value(:source), resource.value(:path))
provider.expects(:update_submodules)
+ provider.expects(:update_remote_url).with("origin", resource.value(:source)).returns false
provider.expects(:git).with('branch', '-a').returns(branch_a_list(resource.value(:revision)))
provider.expects(:git).with('checkout', '--force', resource.value(:revision))
provider.create
@@ -84,6 +88,7 @@ branches
resource.delete(:revision)
provider.expects(:git).with('clone', resource.value(:source), resource.value(:path))
provider.expects(:update_submodules)
+ provider.expects(:update_remotes)
provider.create
end
end
@@ -100,6 +105,7 @@ branches
resource[:ensure] = :bare
resource.delete(:revision)
provider.expects(:git).with('clone', '--bare', resource.value(:source), resource.value(:path))
+ provider.expects(:update_remotes)
provider.create
end
end
@@ -171,6 +177,7 @@ branches
provider.destroy
provider.expects(:git).with('clone',resource.value(:source), resource.value(:path))
provider.expects(:update_submodules)
+ provider.expects(:update_remote_url).with("origin", resource.value(:source)).returns false
provider.expects(:git).with('branch', '-a').returns(branch_a_list(resource.value(:revision)))
provider.expects(:git).with('checkout', '--force', resource.value(:revision))
provider.create
@@ -211,6 +218,7 @@ branches
context "when its SHA is not different than the current SHA" do
it "should return the ref" do
provider.expects(:git).with('rev-parse', resource.value(:revision)).returns('currentsha')
+ provider.expects(:update_remotes)
expect(provider.revision).to eq(resource.value(:revision))
end
end
@@ -218,6 +226,7 @@ branches
context "when its SHA is different than the current SHA" do
it "should return the current SHA" do
provider.expects(:git).with('rev-parse', resource.value(:revision)).returns('othersha')
+ provider.expects(:update_remotes)
expect(provider.revision).to eq(resource.value(:revision))
end
end
@@ -226,6 +235,7 @@ branches
it "should return the revision" do
provider.stubs(:git).with('branch', '-a').returns(" remotes/origin/#{resource.value(:revision)}")
provider.expects(:git).with('rev-parse', "origin/#{resource.value(:revision)}").returns("newsha")
+ provider.expects(:update_remotes)
expect(provider.revision).to eq(resource.value(:revision))
end
end
@@ -234,7 +244,7 @@ branches
it "should fail" do
provider.expects(:git).with('branch', '-a').returns(branch_a_list)
provider.expects(:git).with('rev-parse', '--revs-only', resource.value(:revision)).returns('')
-
+ provider.expects(:update_remotes)
expect { provider.revision }.to raise_error(Puppet::Error, /not a local or remote ref$/)
end
end
@@ -242,12 +252,26 @@ branches
context "when the source is modified" do
it "should update the origin url" do
resource[:source] = 'git://git@foo.com/bar.git'
- provider.expects(:git).with('config', 'remote.origin.url').returns('old')
- provider.expects(:git).with('config', 'remote.origin.url', 'git://git@foo.com/bar.git')
+ provider.expects(:git).with('config', '-l').returns("remote.origin.url=git://git@foo.com/foo.git\n")
+ provider.expects(:git).with('remote', 'set-url', 'origin', 'git://git@foo.com/bar.git')
+ provider.expects(:git).with('remote','update')
provider.expects(:git).with('rev-parse', resource.value(:revision)).returns('currentsha')
expect(provider.revision).to eq(resource.value(:revision))
end
end
+
+ context "when multiple sources are modified" do
+ it "should update the urls" do
+ resource[:source] = {"origin" => "git://git@foo.com/bar.git", "new_remote" => "git://git@foo.com/baz.git"}
+ provider.expects(:git).at_least_once.with('config', '-l').returns("remote.origin.url=git://git@foo.com/bar.git\n", "remote.origin.url=git://git@foo.com/foo.git\n")
+ provider.expects(:git).with('remote', 'set-url', 'origin', 'git://git@foo.com/bar.git')
+ provider.expects(:git).with('remote', 'add', 'new_remote', 'git://git@foo.com/baz.git')
+ provider.expects(:git).with('remote','update')
+ provider.expects(:git).with('rev-parse', resource.value(:revision)).returns('currentsha')
+ expect(provider.revision).to eq(resource.value(:revision))
+ end
+ end
+
end
context "setting the revision property" do
@@ -291,7 +315,7 @@ branches
it "should use 'git fetch --tags'" do
resource.delete(:source)
expects_chdir
- provider.expects(:git).with('config', 'remote.origin.url').returns('')
+ provider.expects(:git).with('config', '-l').returns("remote.origin.url=git://git@foo.com/foo.git\n")
provider.expects(:git).with('fetch', 'origin')
provider.expects(:git).with('fetch', '--tags', 'origin')
provider.update_references
diff --git a/spec/unit/puppet/provider/vcsrepo/svn_spec.rb b/spec/unit/puppet/provider/vcsrepo/svn_spec.rb
index 494da52..77f0e03 100644
--- a/spec/unit/puppet/provider/vcsrepo/svn_spec.rb
+++ b/spec/unit/puppet/provider/vcsrepo/svn_spec.rb
@@ -83,10 +83,22 @@ describe Puppet::Type.type(:vcsrepo).provider(:svn) do
before do
@revision = '30'
end
- it "should use 'svn update'" do
- expects_chdir
- provider.expects(:svn).with('--non-interactive', 'update', '-r', @revision)
- provider.revision = @revision
+ context 'with conflict' do
+ it "should use 'svn update'" do
+ resource[:conflict] = 'theirs-full'
+ expects_chdir
+ provider.expects(:svn).with('--non-interactive', 'update',
+ '-r', @revision,
+ '--accept', resource.value(:conflict))
+ provider.revision = @revision
+ end
+ end
+ context 'without conflict' do
+ it "should use 'svn update'" do
+ expects_chdir
+ provider.expects(:svn).with('--non-interactive', 'update', '-r', @revision)
+ provider.revision = @revision
+ end
end
end
@@ -94,11 +106,24 @@ describe Puppet::Type.type(:vcsrepo).provider(:svn) do
before do
@revision = '30'
end
- it "should use 'svn switch'" do
- resource[:source] = 'an-unimportant-value'
- expects_chdir
- provider.expects(:svn).with('--non-interactive', 'switch', '-r', @revision, 'an-unimportant-value')
- provider.revision = @revision
+ context 'with conflict' do
+ it "should use 'svn switch'" do
+ resource[:source] = 'an-unimportant-value'
+ resource[:conflict] = 'theirs-full'
+ expects_chdir
+ provider.expects(:svn).with('--non-interactive', 'switch',
+ '-r', @revision, 'an-unimportant-value',
+ '--accept', resource.value(:conflict))
+ provider.revision = @revision
+ end
+ end
+ context 'without conflict' do
+ it "should use 'svn switch'" do
+ resource[:source] = 'an-unimportant-value'
+ expects_chdir
+ provider.expects(:svn).with('--non-interactive', 'switch', '-r', @revision, 'an-unimportant-value')
+ provider.revision = @revision
+ end
end
end