From 411111b5ff88b682d7e9cc54a47573bccc3e3edc Mon Sep 17 00:00:00 2001 From: John Iacona Date: Wed, 28 Aug 2013 14:32:05 -0400 Subject: update git provider to handle checking out into an existing (empty) dir --- spec/unit/puppet/provider/vcsrepo/git_spec.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'spec/unit/puppet') diff --git a/spec/unit/puppet/provider/vcsrepo/git_spec.rb b/spec/unit/puppet/provider/vcsrepo/git_spec.rb index 68b6c0a..1a6d008 100644 --- a/spec/unit/puppet/provider/vcsrepo/git_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/git_spec.rb @@ -74,9 +74,10 @@ describe_provider :vcsrepo, :git, :resource => {:path => '/tmp/vcsrepo'} do end end - context "when the path is not a repository" do + context "when the path is not empty and not a repository" do it "should raise an exception" do provider.expects(:path_exists?).returns(true) + provider.expects(:path_empty?).returns(false) proc { provider.create }.should raise_error(Puppet::Error) end end @@ -102,9 +103,10 @@ describe_provider :vcsrepo, :git, :resource => {:path => '/tmp/vcsrepo'} do end end - context "when the path is not a repository" do + context "when the path is not empty and not a repository" do it "should raise an exception" do expects_directory?(true) + provider.expects(:path_empty?).returns(false) proc { provider.create }.should raise_error(Puppet::Error) end end -- cgit v1.2.3 From aeb3ea63ec561440c02f9d4c4d4c0ac3a1d096c9 Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Wed, 18 Sep 2013 15:59:44 -0400 Subject: Overhaul the spec tests to work in rspec2. This work gets rid of the provider_example_group and reworks everything to work properly against rspec2. I don't know if I'd consider the style "better" but it works. --- spec/unit/puppet/provider/vcsrepo/bzr_spec.rb | 73 +++-- spec/unit/puppet/provider/vcsrepo/cvs_spec.rb | 67 +++-- spec/unit/puppet/provider/vcsrepo/dummy_spec.rb | 17 -- spec/unit/puppet/provider/vcsrepo/git_spec.rb | 336 +++++++++++++----------- spec/unit/puppet/provider/vcsrepo/hg_spec.rb | 52 ++-- spec/unit/puppet/provider/vcsrepo/svn_spec.rb | 95 ++++--- 6 files changed, 357 insertions(+), 283 deletions(-) delete mode 100644 spec/unit/puppet/provider/vcsrepo/dummy_spec.rb (limited to 'spec/unit/puppet') diff --git a/spec/unit/puppet/provider/vcsrepo/bzr_spec.rb b/spec/unit/puppet/provider/vcsrepo/bzr_spec.rb index c0231e9..488ddc0 100644 --- a/spec/unit/puppet/provider/vcsrepo/bzr_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/bzr_spec.rb @@ -1,24 +1,41 @@ require 'spec_helper' -describe_provider :vcsrepo, :bzr, :resource => {:path => '/tmp/vcsrepo'} do +describe Puppet::Type.type(:vcsrepo).provider(:bzr_provider) do + + let(:resource) { Puppet::Type.type(:vcsrepo).new({ + :name => 'test', + :ensure => :present, + :provider => :bzr, + :revision => '2634', + :source => 'lp:do', + :path => '/tmp/test', + })} + + let(:provider) { resource.provider } + + before :each do + Puppet::Util.stubs(:which).with('bzr').returns('/usr/bin/bzr') + end describe 'creating' do - resource_with :source do - resource_with :revision do - it "should execute 'bzr clone -r' with the revision" do - provider.expects(:bzr).with('branch', '-r', resource.value(:revision), resource.value(:source), resource.value(:path)) - provider.create - end + context 'with defaults' do + it "should execute 'bzr clone -r' with the revision" do + provider.expects(:bzr).with('branch', '-r', resource.value(:revision), resource.value(:source), resource.value(:path)) + provider.create end - resource_without :revision do - it "should just execute 'bzr clone' without a revision" do - provider.expects(:bzr).with('branch', resource.value(:source), resource.value(:path)) - provider.create - end + end + + context 'without revision' do + it "should just execute 'bzr clone' without a revision" do + resource.delete(:revision) + provider.expects(:bzr).with('branch', resource.value(:source), resource.value(:path)) + provider.create end end - resource_without :source do + + context 'without source' do it "should execute 'bzr init'" do + resource.delete(:source) provider.expects(:bzr).with('init', resource.value(:path)) provider.create end @@ -27,14 +44,13 @@ describe_provider :vcsrepo, :bzr, :resource => {:path => '/tmp/vcsrepo'} do describe 'destroying' do it "it should remove the directory" do - expects_rm_rf provider.destroy end end describe "checking existence" do it "should check for the directory" do - expects_directory?(true, File.join(resource.value(:path), '.bzr')) + File.expects(:directory?).with(File.join(resource.value(:path), '.bzr')).returns(true) provider.exists? end end @@ -42,46 +58,49 @@ describe_provider :vcsrepo, :bzr, :resource => {:path => '/tmp/vcsrepo'} do describe "checking the revision property" do before do expects_chdir - provider.expects(:bzr).with('version-info').returns(fixture(:bzr_version_info)) + provider.expects(:bzr).with('version-info').returns(File.read(fixtures('bzr_version_info.txt'))) @current_revid = 'menesis@pov.lt-20100309191856-4wmfqzc803fj300x' end - context "when given a non-revid as the resource revision", :resource => {:revision => '2634'} do + + context "when given a non-revid as the resource revision" do context "when its revid is not different than the current revid" do - before do - provider.expects(:bzr).with('revision-info', resource.value(:revision)).returns("#{resource.value(:revision)} menesis@pov.lt-20100309191856-4wmfqzc803fj300x\n") - end it "should return the ref" do + resource[:revision] = '2634' + provider.expects(:bzr).with('revision-info', '2634').returns("2634 menesis@pov.lt-20100309191856-4wmfqzc803fj300x\n") provider.revision.should == resource.value(:revision) end end - context "when its revid is different than the current revid", :resource => {:revision => '2636'} do + context "when its revid is different than the current revid" do it "should return the current revid" do + resource[:revision] = '2636' provider.expects(:bzr).with('revision-info', resource.value(:revision)).returns("2635 foo\n") provider.revision.should == @current_revid end end end + context "when given a revid as the resource revision" do - context "when it is the same as the current revid", :resource => {:revision => 'menesis@pov.lt-20100309191856-4wmfqzc803fj300x'} do - before do - provider.expects(:bzr).with('revision-info', resource.value(:revision)).returns("1234 #{resource.value(:revision)}\n") - end + context "when it is the same as the current revid" do it "should return it" do + resource[:revision] = 'menesis@pov.lt-20100309191856-4wmfqzc803fj300x' + provider.expects(:bzr).with('revision-info', resource.value(:revision)).returns("1234 #{resource.value(:revision)}\n") provider.revision.should == resource.value(:revision) end end - context "when it is not the same as the current revid", :resource => {:revision => 'menesis@pov.lt-20100309191856-4wmfqzc803fj300y'} do + context "when it is not the same as the current revid" do it "should return the current revid" do + resource[:revision] = 'menesis@pov.lt-20100309191856-4wmfqzc803fj300y' provider.expects(:bzr).with('revision-info', resource.value(:revision)).returns("2636 foo\n") provider.revision.should == @current_revid end end + end end describe "setting the revision property" do it "should use 'bzr update -r' with the revision" do - expects_chdir + Dir.expects(:chdir).with('/tmp/test').at_least_once.yields provider.expects(:bzr).with('update', '-r', 'somerev') provider.revision = 'somerev' end diff --git a/spec/unit/puppet/provider/vcsrepo/cvs_spec.rb b/spec/unit/puppet/provider/vcsrepo/cvs_spec.rb index aad54cc..efa4b33 100644 --- a/spec/unit/puppet/provider/vcsrepo/cvs_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/cvs_spec.rb @@ -1,27 +1,44 @@ require 'spec_helper' -describe_provider :vcsrepo, :cvs, :resource => {:path => '/tmp/vcsrepo'} do +describe Puppet::Type.type(:vcsrepo).provider(:cvs_provider) do + + let(:resource) { Puppet::Type.type(:vcsrepo).new({ + :name => 'test', + :ensure => :present, + :provider => :cvs, + :revision => '2634', + :source => 'lp:do', + :path => '/tmp/test', + })} + + let(:provider) { resource.provider } + + before :each do + Puppet::Util.stubs(:which).with('cvs').returns('/usr/bin/cvs') + end describe 'creating' do - context "with a source", :resource => {:source => ':ext:source@example.com:/foo/bar'} do - resource_with :revision do - it "should execute 'cvs checkout' and 'cvs update -r'" do - provider.expects(:cvs).with('-d', resource.value(:source), 'checkout', '-r', 'an-unimportant-value', '-d', 'vcsrepo', 'bar') - expects_chdir(File.dirname(resource.value(:path))) - #provider.expects(:cvs).with('update', '-r', resource.value(:revision), '.') - provider.create - end + context "with a source" do + it "should execute 'cvs checkout'" do + resource[:source] = ':ext:source@example.com:/foo/bar' + resource[:revision] = 'an-unimportant-value' + expects_chdir('/tmp') + provider.expects(:cvs).with('-d', resource.value(:source), 'checkout', '-r', 'an-unimportant-value', '-d', 'test', 'bar') + provider.create end - resource_without :revision do - it "should just execute 'cvs checkout' without a revision" do - provider.expects(:cvs).with('-d', resource.value(:source), 'checkout', '-d', File.basename(resource.value(:path)), File.basename(resource.value(:source))) - provider.create - end + it "should just execute 'cvs checkout' without a revision" do + resource[:source] = ':ext:source@example.com:/foo/bar' + resource.delete(:revision) + provider.expects(:cvs).with('-d', resource.value(:source), 'checkout', '-d', File.basename(resource.value(:path)), File.basename(resource.value(:source))) + provider.create end - context "with a compression", :resource => {:compression => '3'} do + context "with a compression" do it "should just execute 'cvs checkout' without a revision" do + resource[:source] = ':ext:source@example.com:/foo/bar' + resource[:compression] = '3' + resource.delete(:revision) provider.expects(:cvs).with('-d', resource.value(:source), '-z', '3', 'checkout', '-d', File.basename(resource.value(:path)), File.basename(resource.value(:source))) provider.create end @@ -30,6 +47,7 @@ describe_provider :vcsrepo, :cvs, :resource => {:path => '/tmp/vcsrepo'} do context "when a source is not given" do it "should execute 'cvs init'" do + resource.delete(:source) provider.expects(:cvs).with('-d', resource.value(:path), 'init') provider.create end @@ -38,24 +56,21 @@ describe_provider :vcsrepo, :cvs, :resource => {:path => '/tmp/vcsrepo'} do describe 'destroying' do it "it should remove the directory" do - expects_rm_rf provider.destroy end end describe "checking existence" do - resource_with :source do - it "should check for the CVS directory" do - File.expects(:directory?).with(File.join(resource.value(:path), 'CVS')) - provider.exists? - end + it "should check for the CVS directory with source" do + resource[:source] = ':ext:source@example.com:/foo/bar' + File.expects(:directory?).with(File.join(resource.value(:path), 'CVS')) + provider.exists? end - resource_without :source do - it "should check for the CVSROOT directory" do - File.expects(:directory?).with(File.join(resource.value(:path), 'CVSROOT')) - provider.exists? - end + it "should check for the CVSROOT directory without source" do + resource.delete(:source) + File.expects(:directory?).with(File.join(resource.value(:path), 'CVSROOT')) + provider.exists? end end diff --git a/spec/unit/puppet/provider/vcsrepo/dummy_spec.rb b/spec/unit/puppet/provider/vcsrepo/dummy_spec.rb deleted file mode 100644 index a945888..0000000 --- a/spec/unit/puppet/provider/vcsrepo/dummy_spec.rb +++ /dev/null @@ -1,17 +0,0 @@ -require 'spec_helper' - -describe_provider :vcsrepo, :dummy, :resource => {:path => '/tmp/vcsrepo'} do - - context 'dummy' do - resource_with :source do - resource_with :ensure => :present do - context "with nothing doing", :resource => {:revision => 'foo'} do - it "should raise an exception" do - proc { provider.working_copy_exists? }.should raise_error(RuntimeError) - end - end - end - end - end - -end diff --git a/spec/unit/puppet/provider/vcsrepo/git_spec.rb b/spec/unit/puppet/provider/vcsrepo/git_spec.rb index 1a6d008..d2769ae 100644 --- a/spec/unit/puppet/provider/vcsrepo/git_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/git_spec.rb @@ -1,192 +1,212 @@ require 'spec_helper' -describe_provider :vcsrepo, :git, :resource => {:path => '/tmp/vcsrepo'} do +describe Puppet::Type.type(:vcsrepo).provider(:git_provider) do + + let(:resource) { Puppet::Type.type(:vcsrepo).new({ + :name => 'test', + :ensure => :present, + :provider => :git, + :revision => '2634', + :source => 'git@repo', + :path => '/tmp/test', + })} + + let(:provider) { resource.provider } + + before :each do + Puppet::Util.stubs(:which).with('git').returns('/usr/bin/git') + end context 'creating' do - resource_with :source do - resource_with :ensure => :present do - context "with a revision that is a remote branch", :resource => {:revision => 'only/remote'} do - it "should execute 'git clone' and 'git checkout -b'" do - provider.expects(:git).with('clone', resource.value(:source), resource.value(:path)) - expects_chdir('/') - expects_chdir - provider.expects(:update_submodules) - provider.expects(:git).with('branch', '-a').returns(resource.value(:revision)) - provider.expects(:git).with('checkout', '--force', resource.value(:revision)) - provider.create - end - end - context "with a revision that is not a remote branch", :resource => {:revision => 'a-commit-or-tag'} do - it "should execute 'git clone' and 'git reset --hard'" do - provider.expects(:git).with('clone', resource.value(:source), resource.value(:path)) - expects_chdir('/') - expects_chdir - provider.expects(:update_submodules) - provider.expects(:git).with('branch', '-a').returns(resource.value(:revision)) - provider.expects(:git).with('checkout', '--force', resource.value(:revision)) - provider.create - end - end - resource_without :revision do - it "should execute 'git clone' and submodule commands" do - provider.expects(:git).with('clone', resource.value(:source), resource.value(:path)) - provider.expects(:update_submodules) - provider.create - end - end + context "with a revision that is a remote branch" do + it "should execute 'git clone' and 'git checkout -b'" do + resource[:revision] = 'only/remote' + Dir.expects(:chdir).with('/').at_least_once.yields + 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(:git).with('branch', '-a').returns(resource.value(:revision)) + provider.expects(:git).with('checkout', '--force', resource.value(:revision)) + provider.create end + end - resource_with :ensure => :bare do - resource_with :revision do - it "should just execute 'git clone --bare'" do - provider.expects(:git).with('clone', '--bare', resource.value(:source), resource.value(:path)) - provider.create - end - end + context "with a revision that is not a remote branch" do + it "should execute 'git clone' and 'git reset --hard'" do + resource[:revision] = 'a-commit-or-tag' + Dir.expects(:chdir).with('/').at_least_once.yields + 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(:git).with('branch', '-a').returns(resource.value(:revision)) + provider.expects(:git).with('checkout', '--force', resource.value(:revision)) + provider.create + end + + it "should execute 'git clone' and submodule commands" do + resource.delete(:revision) + provider.expects(:git).with('clone', resource.value(:source), resource.value(:path)) + provider.expects(:update_submodules) + provider.create + end + end - resource_without :revision do - it "should just execute 'git clone --bare'" do - provider.expects(:git).with('clone', '--bare', resource.value(:source), resource.value(:path)) - provider.create - end + context "with an ensure of bare" do + context "with revision" do + it "should just execute 'git clone --bare'" do + resource[:ensure] = :bare + provider.expects(:git).with('clone', '--bare', resource.value(:source), resource.value(:path)) + provider.create + end + end + context "without revision" do + it "should just execute 'git clone --bare'" do + resource[:ensure] = :bare + resource.delete(:revision) + provider.expects(:git).with('clone', '--bare', resource.value(:source), resource.value(:path)) + provider.create end end end context "when a source is not given" do - resource_with :ensure => :present do - context "when the path does not exist" do - it "should execute 'git init'" do - expects_mkdir - expects_chdir - expects_directory?(false) - provider.expects(:bare_exists?).returns(false) - provider.expects(:git).with('init') - provider.create - end - end + context "when the path does not exist" do + it "should execute 'git init'" do + resource[:ensure] = :present + resource.delete(:source) + expects_mkdir + expects_chdir + expects_directory?(false) - context "when the path is a bare repository" do - it "should convert it to a working copy" do - provider.expects(:bare_exists?).returns(true) - provider.expects(:convert_bare_to_working_copy) - provider.create - end + provider.expects(:bare_exists?).returns(false) + provider.expects(:git).with('init') + provider.create end + end - context "when the path is not empty and not a repository" do - it "should raise an exception" do - provider.expects(:path_exists?).returns(true) - provider.expects(:path_empty?).returns(false) - proc { provider.create }.should raise_error(Puppet::Error) - end + context "when the path is a bare repository" do + it "should convert it to a working copy" do + resource[:ensure] = :present + resource.delete(:source) + provider.expects(:bare_exists?).returns(true) + provider.expects(:convert_bare_to_working_copy) + provider.create end end - resource_with :ensure => :bare do - context "when the path does not exist" do - it "should execute 'git init --bare'" do - expects_chdir - expects_mkdir - expects_directory?(false) - provider.expects(:working_copy_exists?).returns(false) - provider.expects(:git).with('init', '--bare') - provider.create - end + context "when the path is not empty and not a repository" do + it "should raise an exception" do + provider.expects(:path_exists?).returns(true) + provider.expects(:path_empty?).returns(false) + proc { provider.create }.should raise_error(Puppet::Error) end + end + end - context "when the path is a working copy repository" do - it "should convert it to a bare repository" do - provider.expects(:working_copy_exists?).returns(true) - provider.expects(:convert_working_copy_to_bare) - provider.create - end - end + context "when the path does not exist" do + it "should execute 'git init --bare'" do + resource[:ensure] = :bare + resource.delete(:source) + expects_chdir + expects_mkdir + expects_directory?(false) + provider.expects(:working_copy_exists?).returns(false) + provider.expects(:git).with('init', '--bare') + provider.create + end + end - context "when the path is not empty and not a repository" do - it "should raise an exception" do - expects_directory?(true) - provider.expects(:path_empty?).returns(false) - proc { provider.create }.should raise_error(Puppet::Error) - end - end + context "when the path is a working copy repository" do + it "should convert it to a bare repository" do + resource[:ensure] = :bare + resource.delete(:source) + provider.expects(:working_copy_exists?).returns(true) + provider.expects(:convert_working_copy_to_bare) + provider.create end end + context "when the path is not empty and not a repository" do + it "should raise an exception" do + expects_directory?(true) + provider.expects(:path_empty?).returns(false) + proc { provider.create }.should raise_error(Puppet::Error) + end + end end + context 'destroying' do it "it should remove the directory" do - expects_rm_rf + #expects_rm_rf provider.destroy end end context "checking the revision property" do - resource_with :revision do - before do - expects_chdir - provider.expects(:git).with('rev-parse', 'HEAD').returns('currentsha') - end + before do + expects_chdir('/tmp/test') + resource[:revision] = 'currentsha' + resource.delete(:source) + provider.expects(:git).with('rev-parse', 'HEAD').returns('currentsha') + end - context "when its SHA is not different than the current SHA" do - it "should return the ref" do - provider.expects(:git).with('config', 'remote.origin.url').returns('') - provider.expects(:git).with('fetch', 'origin') # FIXME - provider.expects(:git).with('fetch', '--tags', 'origin') - provider.expects(:git).with('rev-parse', '--revs-only', resource.value(:revision)).returns('currentsha') - provider.expects(:git).with('tag', '-l').returns("Hello") - provider.revision.should == resource.value(:revision) - end + context "when its SHA is not different than the current SHA" do + it "should return the ref" do + provider.expects(:git).with('config', 'remote.origin.url').returns('') + provider.expects(:git).with('fetch', 'origin') # FIXME + provider.expects(:git).with('fetch', '--tags', 'origin') + provider.expects(:git).with('rev-parse', '--revs-only', resource.value(:revision)).returns('currentsha') + provider.expects(:git).with('tag', '-l').returns("Hello") + provider.revision.should == resource.value(:revision) end + end - context "when its SHA is different than the current SHA" do - it "should return the current SHA" do - provider.expects(:git).with('config', 'remote.origin.url').returns('') - provider.expects(:git).with('fetch', 'origin') # FIXME - provider.expects(:git).with('fetch', '--tags', 'origin') - provider.expects(:git).with('rev-parse', '--revs-only', resource.value(:revision)).returns('othersha') - provider.expects(:git).with('tag', '-l').returns("Hello") - provider.revision.should == 'currentsha' - end + context "when its SHA is different than the current SHA" do + it "should return the current SHA" do + provider.expects(:git).with('config', 'remote.origin.url').returns('') + provider.expects(:git).with('fetch', 'origin') # FIXME + provider.expects(:git).with('fetch', '--tags', 'origin') + provider.expects(:git).with('rev-parse', '--revs-only', resource.value(:revision)).returns('othersha') + provider.expects(:git).with('tag', '-l').returns("Hello") + provider.revision.should == 'currentsha' end + end - context "when its a ref to a remote head" do - it "should return the revision" do - provider.expects(:git).with('config', 'remote.origin.url').returns('') - provider.expects(:git).with('fetch', 'origin') # FIXME - provider.expects(:git).with('fetch', '--tags', 'origin') - provider.expects(:git).with('tag', '-l').returns("Hello") - provider.expects(:git).with('rev-parse', '--revs-only', resource.value(:revision)).returns('') - provider.expects(:git).with('ls-remote', '--heads', '--tags', 'origin', resource.value(:revision)).returns("newsha refs/heads/#{resource.value(:revision)}") - provider.revision.should == 'currentsha' - end + context "when its a ref to a remote head" do + it "should return the revision" do + provider.expects(:git).with('config', 'remote.origin.url').returns('') + provider.expects(:git).with('fetch', 'origin') # FIXME + provider.expects(:git).with('fetch', '--tags', 'origin') + provider.expects(:git).with('tag', '-l').returns("Hello") + provider.expects(:git).with('rev-parse', '--revs-only', resource.value(:revision)).returns('') + provider.expects(:git).with('ls-remote', '--heads', '--tags', 'origin', resource.value(:revision)).returns("newsha refs/heads/#{resource.value(:revision)}") + provider.revision.should == 'currentsha' end + end - context "when its a ref to non existant remote head" do - it "should fail" do - provider.expects(:git).with('config', 'remote.origin.url').returns('') - provider.expects(:git).with('fetch', 'origin') # FIXME - provider.expects(:git).with('fetch', '--tags', 'origin') - provider.expects(:git).with('tag', '-l').returns("Hello") - provider.expects(:git).with('rev-parse', '--revs-only', resource.value(:revision)).returns('') - provider.expects(:git).with('ls-remote', '--heads', '--tags', 'origin', resource.value(:revision)).returns('') - expect { provider.revision }.should raise_error(Puppet::Error, /not a local or remote ref$/) - end + context "when its a ref to non existant remote head" do + it "should fail" do + provider.expects(:git).with('config', 'remote.origin.url').returns('') + provider.expects(:git).with('fetch', 'origin') # FIXME + provider.expects(:git).with('fetch', '--tags', 'origin') + provider.expects(:git).with('tag', '-l').returns("Hello") + provider.expects(:git).with('rev-parse', '--revs-only', resource.value(:revision)).returns('') + provider.expects(:git).with('ls-remote', '--heads', '--tags', 'origin', resource.value(:revision)).returns('') + expect { provider.revision }.to raise_error(Puppet::Error, /not a local or remote ref$/) end + end - context "when the source is modified" do - resource_with :source => 'git://git@foo.com/bar.git' do - it "should update the origin url" do - 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('fetch', 'origin') # FIXME - provider.expects(:git).with('fetch', '--tags', 'origin') - provider.expects(:git).with('rev-parse', '--revs-only', resource.value(:revision)).returns('currentsha') - provider.expects(:git).with('tag', '-l').returns("Hello") - provider.revision.should == resource.value(:revision) - end - end + 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('fetch', 'origin') # FIXME + provider.expects(:git).with('fetch', '--tags', 'origin') + provider.expects(:git).with('rev-parse', '--revs-only', resource.value(:revision)).returns('currentsha') + provider.expects(:git).with('tag', '-l').returns("Hello") + provider.revision.should == resource.value(:revision) end end end @@ -195,8 +215,9 @@ describe_provider :vcsrepo, :git, :resource => {:path => '/tmp/vcsrepo'} do before do expects_chdir end - context "when it's an existing local branch", :resource => {:revision => 'feature/foo'} do + context "when it's an existing local branch" do it "should use 'git fetch' and 'git reset'" do + resource[:revision] = 'feature/foo' provider.expects(:update_submodules) provider.expects(:git).with('branch', '-a').returns(resource.value(:revision)) provider.expects(:git).with('checkout', '--force', resource.value(:revision)) @@ -205,8 +226,9 @@ describe_provider :vcsrepo, :git, :resource => {:path => '/tmp/vcsrepo'} do provider.revision = resource.value(:revision) end end - context "when it's a remote branch", :resource => {:revision => 'only/remote'} do + context "when it's a remote branch" do it "should use 'git fetch' and 'git reset'" do + resource[:revision] = 'only/remote' provider.expects(:update_submodules) provider.expects(:git).with('branch', '-a').returns(resource.value(:revision)) provider.expects(:git).with('checkout', '--force', resource.value(:revision)) @@ -215,8 +237,9 @@ describe_provider :vcsrepo, :git, :resource => {:path => '/tmp/vcsrepo'} do provider.revision = resource.value(:revision) end end - context "when it's a commit or tag", :resource => {:revision => 'a-commit-or-tag'} do + context "when it's a commit or tag" do it "should use 'git fetch' and 'git reset'" do + resource[:revision] = 'a-commit-or-tag' provider.expects(:git).with('branch', '-a').returns(fixture(:git_branch_a)) provider.expects(:git).with('checkout', '--force', resource.value(:revision)) provider.expects(:git).with('branch', '-a').returns(fixture(:git_branch_a)) @@ -229,6 +252,7 @@ describe_provider :vcsrepo, :git, :resource => {:path => '/tmp/vcsrepo'} do context "updating references" do 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('fetch', 'origin') @@ -243,25 +267,29 @@ describe_provider :vcsrepo, :git, :resource => {:path => '/tmp/vcsrepo'} do provider.expects(:git).with('branch', '-a').returns(fixture(:git_branch_a)) end context "is a local branch" do - context "when it's listed in 'git branch -a'", :resource => {:revision => 'feature/foo'} do + context "when it's listed in 'git branch -a'" do it "should return true" do + resource[:revision] = 'feature/foo' provider.should be_local_branch_revision end end - context "when it's not listed in 'git branch -a'" , :resource => {:revision => 'feature/notexist'}do + context "when it's not listed in 'git branch -a'" do it "should return false" do + resource[:revision] = 'feature/notexist' provider.should_not be_local_branch_revision end end end context "is a remote branch" do - context "when it's listed in 'git branch -a' with an 'origin/' prefix", :resource => {:revision => 'only/remote'} do + context "when it's listed in 'git branch -a' with an 'origin/' prefix" do it "should return true" do + resource[:revision] = 'only/remote' provider.should be_remote_branch_revision end end - context "when it's not listed in 'git branch -a' with an 'origin/' prefix" , :resource => {:revision => 'only/local'}do + context "when it's not listed in 'git branch -a' with an 'origin/' prefix" do it "should return false" do + resource[:revision] = 'only/local' provider.should_not be_remote_branch_revision end end diff --git a/spec/unit/puppet/provider/vcsrepo/hg_spec.rb b/spec/unit/puppet/provider/vcsrepo/hg_spec.rb index f17aa2f..7fd5348 100644 --- a/spec/unit/puppet/provider/vcsrepo/hg_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/hg_spec.rb @@ -1,24 +1,38 @@ require 'spec_helper' -describe_provider :vcsrepo, :hg, :resource => {:path => '/tmp/vcsrepo'} do +describe Puppet::Type.type(:vcsrepo).provider(:hg) do + + let(:resource) { Puppet::Type.type(:vcsrepo).new({ + :name => 'test', + :ensure => :present, + :provider => :hg, + :path => '/tmp/vcsrepo', + })} + + let(:provider) { resource.provider } + + before :each do + Puppet::Util.stubs(:which).with('hg').returns('/usr/bin/hg') + end describe 'creating' do - resource_with :source do - resource_with :revision do - it "should execute 'hg clone -u' with the revision" do - provider.expects(:hg).with('clone', '-u', - resource.value(:revision), - resource.value(:source), - resource.value(:path)) - provider.create - end + context 'with source and revision' do + it "should execute 'hg clone -u' with the revision" do + resource[:source] = 'something' + resource[:revision] = '1' + provider.expects(:hg).with('clone', '-u', + resource.value(:revision), + resource.value(:source), + resource.value(:path)) + provider.create end + end - resource_without :revision do - it "should just execute 'hg clone' without a revision" do - provider.expects(:hg).with('clone', resource.value(:source), resource.value(:path)) - provider.create - end + context 'without revision' do + it "should just execute 'hg clone' without a revision" do + resource[:source] = 'something' + provider.expects(:hg).with('clone', resource.value(:source), resource.value(:path)) + provider.create end end @@ -55,14 +69,16 @@ describe_provider :vcsrepo, :hg, :resource => {:path => '/tmp/vcsrepo'} do provider.expects(:hg).with('tags').returns(fixture(:hg_tags)) end - context "when its SHA is not different than the current SHA", :resource => {:revision => '0.6'} do + context "when its SHA is not different than the current SHA" do it "should return the ref" do + resource[:revision] = '0.6' provider.revision.should == '0.6' end end - context "when its SHA is different than the current SHA", :resource => {:revision => '0.5.3'} do + context "when its SHA is different than the current SHA" do it "should return the current SHA" do + resource[:revision] = '0.5.3' provider.revision.should == '34e6012c783a' end end @@ -74,6 +90,7 @@ describe_provider :vcsrepo, :hg, :resource => {:path => '/tmp/vcsrepo'} do context "when it is the same as the current SHA", :resource => {:revision => '34e6012c783a'} do it "should return it" do + resource[:revision] = '34e6012c783a' provider.expects(:hg).with('tags').returns(fixture(:hg_tags)) provider.revision.should == resource.value(:revision) end @@ -81,6 +98,7 @@ describe_provider :vcsrepo, :hg, :resource => {:path => '/tmp/vcsrepo'} do context "when it is not the same as the current SHA", :resource => {:revision => 'not-the-same'} do it "should return the current SHA" do + resource[:revision] = 'not-the-same' provider.expects(:hg).with('tags').returns(fixture(:hg_tags)) provider.revision.should == '34e6012c783a' end diff --git a/spec/unit/puppet/provider/vcsrepo/svn_spec.rb b/spec/unit/puppet/provider/vcsrepo/svn_spec.rb index 5c03327..f44e314 100644 --- a/spec/unit/puppet/provider/vcsrepo/svn_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/svn_spec.rb @@ -1,41 +1,55 @@ require 'spec_helper' -describe_provider :vcsrepo, :svn, :resource => {:path => '/tmp/vcsrepo'} do +describe Puppet::Type.type(:vcsrepo).provider(:svn) do + + let(:resource) { Puppet::Type.type(:vcsrepo).new({ + :name => 'test', + :ensure => :present, + :provider => :svn, + :path => '/tmp/vcsrepo', + })} + + let(:provider) { resource.provider } + + before :each do + Puppet::Util.stubs(:which).with('git').returns('/usr/bin/git') + end describe 'creating' do - resource_with :source do - resource_with :revision do - it "should execute 'svn checkout' with a revision" do - provider.expects(:svn).with('--non-interactive', 'checkout', '-r', - resource.value(:revision), - resource.value(:source), - resource.value(:path)) - provider.create - end + context 'with source and revision' do + it "should execute 'svn checkout' with a revision" do + resource[:source] = 'exists' + resource[:revision] = '1' + provider.expects(:svn).with('--non-interactive', 'checkout', '-r', + resource.value(:revision), + resource.value(:source), + resource.value(:path)) + provider.create end - resource_without :revision do - it "should just execute 'svn checkout' without a revision" do - provider.expects(:svn).with('--non-interactive', 'checkout', - resource.value(:source), - resource.value(:path)) - provider.create - end + end + context 'with source' do + it "should just execute 'svn checkout' without a revision" do + resource[:source] = 'exists' + provider.expects(:svn).with('--non-interactive', 'checkout', + resource.value(:source), + resource.value(:path)) + provider.create end end - resource_without :source do - resource_with :fstype do - it "should execute 'svnadmin create' with an '--fs-type' option" do - provider.expects(:svnadmin).with('create', '--fs-type', - resource.value(:fstype), - resource.value(:path)) - provider.create - end + + context 'with fstype' do + it "should execute 'svnadmin create' with an '--fs-type' option" do + resource[:fstype] = 'ext4' + provider.expects(:svnadmin).with('create', '--fs-type', + resource.value(:fstype), + resource.value(:path)) + provider.create end - resource_without :fstype do - it "should execute 'svnadmin create' without an '--fs-type' option" do - provider.expects(:svnadmin).with('create', resource.value(:path)) - provider.create - end + end + context 'without fstype' do + it "should execute 'svnadmin create' without an '--fs-type' option" do + provider.expects(:svnadmin).with('create', resource.value(:path)) + provider.create end end end @@ -69,12 +83,10 @@ describe_provider :vcsrepo, :svn, :resource => {:path => '/tmp/vcsrepo'} do before do @revision = '30' end - resource_without :source do - it "should use 'svn update'" do - expects_chdir - provider.expects(:svn).with('--non-interactive', 'update', '-r', @revision) - provider.revision = @revision - end + it "should use 'svn update'" do + expects_chdir + provider.expects(:svn).with('--non-interactive', 'update', '-r', @revision) + provider.revision = @revision end end @@ -82,12 +94,11 @@ describe_provider :vcsrepo, :svn, :resource => {:path => '/tmp/vcsrepo'} do before do @revision = '30' end - resource_with :source do - it "should use 'svn switch'" do - expects_chdir - provider.expects(:svn).with('--non-interactive', 'switch', '-r', @revision, 'an-unimportant-value') - provider.revision = @revision - 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 end end -- cgit v1.2.3 From c92ede74bedda8b43df17abfe7528d3ddffe951a Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Wed, 18 Sep 2013 18:01:13 -0400 Subject: Add test for latest? Also add some fixtures for previous tests. --- spec/unit/puppet/provider/vcsrepo/git_spec.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'spec/unit/puppet') diff --git a/spec/unit/puppet/provider/vcsrepo/git_spec.rb b/spec/unit/puppet/provider/vcsrepo/git_spec.rb index d2769ae..cc369d9 100644 --- a/spec/unit/puppet/provider/vcsrepo/git_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/git_spec.rb @@ -296,4 +296,25 @@ describe Puppet::Type.type(:vcsrepo).provider(:git_provider) do end end + describe 'latest?' do + before do + expects_chdir('/tmp/test') + end + context 'when true' do + it do + provider.expects(:revision).returns('testrev') + provider.expects(:latest).returns('testrev') + provider.latest?.should be_true + end + end + context 'when false' do + it do + provider.expects(:revision).returns('master') + provider.expects(:latest).returns('testrev') + provider.latest?.should be_false + end + end + end + + end -- cgit v1.2.3 From a3d888f1fdd0a4cbd423b8b47f546c2d1decead7 Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Wed, 18 Sep 2013 18:16:39 -0400 Subject: Add latest tests. --- spec/unit/puppet/provider/vcsrepo/git_spec.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'spec/unit/puppet') diff --git a/spec/unit/puppet/provider/vcsrepo/git_spec.rb b/spec/unit/puppet/provider/vcsrepo/git_spec.rb index cc369d9..1e4704f 100644 --- a/spec/unit/puppet/provider/vcsrepo/git_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/git_spec.rb @@ -316,5 +316,30 @@ describe Puppet::Type.type(:vcsrepo).provider(:git_provider) do end end + describe 'latest' do + before do + provider.expects(:get_revision).returns('master') + expects_chdir + end + context 'on master' do + it do + provider.expects(:git).with('branch', '-a').returns(fixture(:git_branch_a)) + provider.latest.should == 'master' + end + end + context 'no branch' do + it do + provider.expects(:git).with('branch', '-a').returns(fixture(:git_branch_none)) + provider.latest.should == 'master' + end + end + context 'feature/bar' do + it do + provider.expects(:git).with('branch', '-a').returns(fixture(:git_branch_feature_bar)) + provider.latest.should == 'master' + end + end + end + end -- cgit v1.2.3 From 33c492e0e6b04c6829b8ce4650f5e45012b770dc Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Wed, 18 Sep 2013 18:20:29 -0400 Subject: Add tests for convert_working_copy_to_bare and convert_bare_to_working_copy --- spec/unit/puppet/provider/vcsrepo/git_spec.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'spec/unit/puppet') diff --git a/spec/unit/puppet/provider/vcsrepo/git_spec.rb b/spec/unit/puppet/provider/vcsrepo/git_spec.rb index 1e4704f..33117f2 100644 --- a/spec/unit/puppet/provider/vcsrepo/git_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/git_spec.rb @@ -341,5 +341,26 @@ describe Puppet::Type.type(:vcsrepo).provider(:git_provider) do end end + describe 'convert_working_copy_to_bare' do + it do + FileUtils.expects(:mv) + FileUtils.expects(:rm_rf) + FileUtils.expects(:mv) + + provider.instance_eval { convert_working_copy_to_bare } + end + end + + describe 'convert_bare_to_working_copy' do + it do + FileUtils.expects(:mv) + FileUtils.expects(:mkdir) + FileUtils.expects(:mv) + provider.expects(:commits_in?).returns(true) + expects_chdir + + provider.instance_eval { convert_bare_to_working_copy } + end + end end -- cgit v1.2.3 From d163d5059b910de9d2c086a29c72e7a228090465 Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Wed, 18 Sep 2013 18:48:47 -0400 Subject: Add convert_working_copy_to_bear and convert_bare_to_working_copy tests. --- spec/unit/puppet/provider/vcsrepo/git_spec.rb | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'spec/unit/puppet') diff --git a/spec/unit/puppet/provider/vcsrepo/git_spec.rb b/spec/unit/puppet/provider/vcsrepo/git_spec.rb index 33117f2..15fee53 100644 --- a/spec/unit/puppet/provider/vcsrepo/git_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/git_spec.rb @@ -343,9 +343,9 @@ describe Puppet::Type.type(:vcsrepo).provider(:git_provider) do describe 'convert_working_copy_to_bare' do it do - FileUtils.expects(:mv) - FileUtils.expects(:rm_rf) - FileUtils.expects(:mv) + FileUtils.expects(:mv).returns(true) + FileUtils.expects(:rm_rf).returns(true) + FileUtils.expects(:mv).returns(true) provider.instance_eval { convert_working_copy_to_bare } end @@ -353,11 +353,14 @@ describe Puppet::Type.type(:vcsrepo).provider(:git_provider) do describe 'convert_bare_to_working_copy' do it do - FileUtils.expects(:mv) - FileUtils.expects(:mkdir) - FileUtils.expects(:mv) + FileUtils.expects(:mv).returns(true) + FileUtils.expects(:mkdir).returns(true) + FileUtils.expects(:mv).returns(true) provider.expects(:commits_in?).returns(true) - expects_chdir + # If you forget to stub these out you lose 3 hours of rspec work. + provider.expects(:reset).with('HEAD').returns(true) + provider.expects(:git_with_identity).returns(true) + provider.expects(:update_owner_and_excludes).returns(true) provider.instance_eval { convert_bare_to_working_copy } end -- cgit v1.2.3 From 8837be29ff114228f86d67c59337119120690e44 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Mon, 2 Dec 2013 11:38:56 -0500 Subject: Using rev-parse to determine branch name of HEAD for on_branch? method --- spec/unit/puppet/provider/vcsrepo/git_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'spec/unit/puppet') diff --git a/spec/unit/puppet/provider/vcsrepo/git_spec.rb b/spec/unit/puppet/provider/vcsrepo/git_spec.rb index 15fee53..f3d9dd3 100644 --- a/spec/unit/puppet/provider/vcsrepo/git_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/git_spec.rb @@ -323,19 +323,19 @@ describe Puppet::Type.type(:vcsrepo).provider(:git_provider) do end context 'on master' do it do - provider.expects(:git).with('branch', '-a').returns(fixture(:git_branch_a)) + provider.expects(:git).with('rev-parse', '--abbrev-ref', 'HEAD').returns(fixture(:git_branch_a)) provider.latest.should == 'master' end end context 'no branch' do it do - provider.expects(:git).with('branch', '-a').returns(fixture(:git_branch_none)) + provider.expects(:git).with('rev-parse', '--abbrev-ref', 'HEAD').returns(fixture(:git_branch_none)) provider.latest.should == 'master' end end context 'feature/bar' do it do - provider.expects(:git).with('branch', '-a').returns(fixture(:git_branch_feature_bar)) + provider.expects(:git).with('rev-parse', '--abbrev-ref', 'HEAD').returns(fixture(:git_branch_feature_bar)) provider.latest.should == 'master' end end -- cgit v1.2.3 From 69b93cefcdcd4a80d241dc71d5e6de90842faf11 Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Tue, 3 Dec 2013 09:54:21 -0500 Subject: Stripping git on_branch? return value; contains trailing newline This commit also contains git provider `latest' method formatting changes; squashed by request. --- spec/unit/puppet/provider/vcsrepo/git_spec.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'spec/unit/puppet') diff --git a/spec/unit/puppet/provider/vcsrepo/git_spec.rb b/spec/unit/puppet/provider/vcsrepo/git_spec.rb index f3d9dd3..554645b 100644 --- a/spec/unit/puppet/provider/vcsrepo/git_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/git_spec.rb @@ -296,6 +296,18 @@ describe Puppet::Type.type(:vcsrepo).provider(:git_provider) do end end + context "retrieving the current revision" do + before do + expects_chdir + provider.expects(:git).with('rev-parse', '--abbrev-ref', 'HEAD').returns("foo\n") + end + + it "will strip trailing newlines" do + provider.expects(:get_revision).with('origin/foo') + provider.latest + end + end + describe 'latest?' do before do expects_chdir('/tmp/test') -- cgit v1.2.3 From 0ea16bba47cf177dc17fa14f20d54d0091a09865 Mon Sep 17 00:00:00 2001 From: Felipe Reyes Date: Thu, 2 Jan 2014 18:13:40 -0300 Subject: Add the option to shallow clones with git The new parameter used to indicate that you want a shallow clone is `:depth` --- spec/unit/puppet/provider/vcsrepo/git_spec.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'spec/unit/puppet') diff --git a/spec/unit/puppet/provider/vcsrepo/git_spec.rb b/spec/unit/puppet/provider/vcsrepo/git_spec.rb index 554645b..c40388f 100644 --- a/spec/unit/puppet/provider/vcsrepo/git_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/git_spec.rb @@ -31,6 +31,20 @@ describe Puppet::Type.type(:vcsrepo).provider(:git_provider) do end end + context "with shallow clone enable" do + it "should execute 'git clone --depth 1'" do + resource[:revision] = 'only/remote' + resource[:depth] = 1 + Dir.expects(:chdir).with('/').at_least_once.yields + Dir.expects(:chdir).with('/tmp/test').at_least_once.yields + provider.expects(:git).with('clone', '--depth', '1', resource.value(:source), resource.value(:path)) + provider.expects(:update_submodules) + provider.expects(:git).with('branch', '-a').returns(resource.value(:revision)) + provider.expects(:git).with('checkout', '--force', resource.value(:revision)) + provider.create + end + end + context "with a revision that is not a remote branch" do it "should execute 'git clone' and 'git reset --hard'" do resource[:revision] = 'a-commit-or-tag' -- cgit v1.2.3 From 7845ea132b0b40a83d3e9284723cbf63e2b61a82 Mon Sep 17 00:00:00 2001 From: Miguel Di Ciurcio Filho Date: Sat, 11 Jan 2014 15:25:28 -0200 Subject: git: actually use the remote parameter When using the following sample, the provider does not use the value of remote when cloning a repository: vcsrepo {'/path/to/repo': ensure => 'present', provider => 'git', remote => 'test', source => 'git@somerepo:repo.git', } $ git remote origin This commit makes sure that the new repository has a remote with the supplied value. Closes #MODULES-430 --- spec/unit/puppet/provider/vcsrepo/git_spec.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'spec/unit/puppet') diff --git a/spec/unit/puppet/provider/vcsrepo/git_spec.rb b/spec/unit/puppet/provider/vcsrepo/git_spec.rb index c40388f..96c4f19 100644 --- a/spec/unit/puppet/provider/vcsrepo/git_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/git_spec.rb @@ -31,6 +31,19 @@ describe Puppet::Type.type(:vcsrepo).provider(:git_provider) do end end + context "with a remote not named 'origin'" do + it "should execute 'git clone --origin not_origin" do + resource[:remote] = 'not_origin' + Dir.expects(:chdir).with('/').at_least_once.yields + 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(:git).with('branch', '-a').returns(resource.value(:revision)) + provider.expects(:git).with('checkout', '--force', resource.value(:revision)) + provider.create + end + end + context "with shallow clone enable" do it "should execute 'git clone --depth 1'" do resource[:revision] = 'only/remote' -- cgit v1.2.3 From 51063851095f3482c644f699ba57ffab3f830263 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Gali=C4=87?= Date: Thu, 3 Apr 2014 14:28:33 +0200 Subject: fix tabbing in vcsrepo test --- spec/unit/puppet/provider/vcsrepo/git_spec.rb | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'spec/unit/puppet') diff --git a/spec/unit/puppet/provider/vcsrepo/git_spec.rb b/spec/unit/puppet/provider/vcsrepo/git_spec.rb index 96c4f19..ba726fa 100644 --- a/spec/unit/puppet/provider/vcsrepo/git_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/git_spec.rb @@ -32,16 +32,16 @@ describe Puppet::Type.type(:vcsrepo).provider(:git_provider) do end context "with a remote not named 'origin'" do - it "should execute 'git clone --origin not_origin" do - resource[:remote] = 'not_origin' - Dir.expects(:chdir).with('/').at_least_once.yields - 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(:git).with('branch', '-a').returns(resource.value(:revision)) - provider.expects(:git).with('checkout', '--force', resource.value(:revision)) - provider.create - end + it "should execute 'git clone --origin not_origin" do + resource[:remote] = 'not_origin' + Dir.expects(:chdir).with('/').at_least_once.yields + 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(:git).with('branch', '-a').returns(resource.value(:revision)) + provider.expects(:git).with('checkout', '--force', resource.value(:revision)) + provider.create + end end context "with shallow clone enable" do -- cgit v1.2.3 From cfcd03a7c59eaa6b81de8c767bbd91e6d278c0f2 Mon Sep 17 00:00:00 2001 From: Travis Fields Date: Tue, 13 May 2014 11:27:02 -0700 Subject: Fix issue where force=>true was not destroying repository then recreating --- spec/unit/puppet/provider/vcsrepo/git_spec.rb | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'spec/unit/puppet') diff --git a/spec/unit/puppet/provider/vcsrepo/git_spec.rb b/spec/unit/puppet/provider/vcsrepo/git_spec.rb index ba726fa..ad6ed08 100644 --- a/spec/unit/puppet/provider/vcsrepo/git_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/git_spec.rb @@ -9,6 +9,7 @@ describe Puppet::Type.type(:vcsrepo).provider(:git_provider) do :revision => '2634', :source => 'git@repo', :path => '/tmp/test', + :force => false })} let(:provider) { resource.provider } @@ -151,12 +152,26 @@ describe Puppet::Type.type(:vcsrepo).provider(:git_provider) do provider.expects(:convert_working_copy_to_bare) provider.create end + it "should clone overtop it using force" do + resource[:force] = true + Dir.expects(:chdir).with('/').at_least_once.yields + Dir.expects(:chdir).with('/tmp/test').at_least_once.yields + provider.expects(:path_exists?).returns(true) + provider.expects(:path_empty?).returns(false) + provider.destroy + provider.expects(:git).with('clone',resource.value(:source), resource.value(:path)) + provider.expects(:update_submodules) + provider.expects(:git).with('branch', '-a').returns(resource.value(:revision)) + provider.expects(:git).with('checkout', '--force', resource.value(:revision)) + provider.create + end end context "when the path is not empty and not a repository" do it "should raise an exception" do - expects_directory?(true) + provider.expects(:path_exists?).returns(true) provider.expects(:path_empty?).returns(false) + provider.expects(:working_copy_exists?).returns(false) proc { provider.create }.should raise_error(Puppet::Error) end end @@ -390,7 +405,7 @@ describe Puppet::Type.type(:vcsrepo).provider(:git_provider) do end end - describe 'convert_bare_to_working_copy' do + describe 'convert_bare_to_working_copy' do it do FileUtils.expects(:mv).returns(true) FileUtils.expects(:mkdir).returns(true) -- cgit v1.2.3 From a213d71ec8d3e75bef909cc5c3f11aaea8b4e94d Mon Sep 17 00:00:00 2001 From: Travis Fields Date: Thu, 15 May 2014 16:47:24 -0700 Subject: Fix detached head state --- spec/unit/puppet/provider/vcsrepo/git_spec.rb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'spec/unit/puppet') diff --git a/spec/unit/puppet/provider/vcsrepo/git_spec.rb b/spec/unit/puppet/provider/vcsrepo/git_spec.rb index ad6ed08..20aa084 100644 --- a/spec/unit/puppet/provider/vcsrepo/git_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/git_spec.rb @@ -261,6 +261,7 @@ describe Puppet::Type.type(:vcsrepo).provider(:git_provider) do it "should use 'git fetch' and 'git reset'" do resource[:revision] = 'feature/foo' provider.expects(:update_submodules) + provider.expects(:git).with('branch','--list').returns("* master") provider.expects(:git).with('branch', '-a').returns(resource.value(:revision)) provider.expects(:git).with('checkout', '--force', resource.value(:revision)) provider.expects(:git).with('branch', '-a').returns(resource.value(:revision)) @@ -272,6 +273,7 @@ describe Puppet::Type.type(:vcsrepo).provider(:git_provider) do it "should use 'git fetch' and 'git reset'" do resource[:revision] = 'only/remote' provider.expects(:update_submodules) + provider.expects(:git).with('branch','--list').returns("* master") provider.expects(:git).with('branch', '-a').returns(resource.value(:revision)) provider.expects(:git).with('checkout', '--force', resource.value(:revision)) provider.expects(:git).with('branch', '-a').returns(resource.value(:revision)) @@ -341,7 +343,7 @@ describe Puppet::Type.type(:vcsrepo).provider(:git_provider) do context "retrieving the current revision" do before do expects_chdir - provider.expects(:git).with('rev-parse', '--abbrev-ref', 'HEAD').returns("foo\n") + provider.expects(:git).with('branch','--list').returns("* foo") end it "will strip trailing newlines" do @@ -377,19 +379,20 @@ describe Puppet::Type.type(:vcsrepo).provider(:git_provider) do end context 'on master' do it do - provider.expects(:git).with('rev-parse', '--abbrev-ref', 'HEAD').returns(fixture(:git_branch_a)) + provider.expects(:git).with('branch','--list').returns("* master") provider.latest.should == 'master' end end context 'no branch' do it do - provider.expects(:git).with('rev-parse', '--abbrev-ref', 'HEAD').returns(fixture(:git_branch_none)) + provider.expects(:git).with('branch','--list').returns("* master") + provider.latest.should == 'master' end end context 'feature/bar' do it do - provider.expects(:git).with('rev-parse', '--abbrev-ref', 'HEAD').returns(fixture(:git_branch_feature_bar)) + provider.expects(:git).with('branch','--list').returns("* master") provider.latest.should == 'master' end end -- cgit v1.2.3 From 2458aba1401ad6336137653f87086e7656625bf7 Mon Sep 17 00:00:00 2001 From: Travis Fields Date: Thu, 15 May 2014 22:32:47 -0700 Subject: Fix spec tests --- spec/unit/puppet/provider/vcsrepo/git_spec.rb | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'spec/unit/puppet') diff --git a/spec/unit/puppet/provider/vcsrepo/git_spec.rb b/spec/unit/puppet/provider/vcsrepo/git_spec.rb index 20aa084..8e296ef 100644 --- a/spec/unit/puppet/provider/vcsrepo/git_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/git_spec.rb @@ -261,10 +261,8 @@ describe Puppet::Type.type(:vcsrepo).provider(:git_provider) do it "should use 'git fetch' and 'git reset'" do resource[:revision] = 'feature/foo' provider.expects(:update_submodules) - provider.expects(:git).with('branch','--list').returns("* master") - provider.expects(:git).with('branch', '-a').returns(resource.value(:revision)) + provider.expects(:git).with('branch', '-a').at_least_once.returns(resource.value(:revision)) provider.expects(:git).with('checkout', '--force', resource.value(:revision)) - provider.expects(:git).with('branch', '-a').returns(resource.value(:revision)) provider.expects(:git).with('reset', '--hard', "origin/#{resource.value(:revision)}") provider.revision = resource.value(:revision) end @@ -273,10 +271,8 @@ describe Puppet::Type.type(:vcsrepo).provider(:git_provider) do it "should use 'git fetch' and 'git reset'" do resource[:revision] = 'only/remote' provider.expects(:update_submodules) - provider.expects(:git).with('branch','--list').returns("* master") - provider.expects(:git).with('branch', '-a').returns(resource.value(:revision)) + provider.expects(:git).with('branch', '-a').at_least_once.returns(resource.value(:revision)) provider.expects(:git).with('checkout', '--force', resource.value(:revision)) - provider.expects(:git).with('branch', '-a').returns(resource.value(:revision)) provider.expects(:git).with('reset', '--hard', "origin/#{resource.value(:revision)}") provider.revision = resource.value(:revision) end @@ -343,7 +339,7 @@ describe Puppet::Type.type(:vcsrepo).provider(:git_provider) do context "retrieving the current revision" do before do expects_chdir - provider.expects(:git).with('branch','--list').returns("* foo") + provider.expects(:git).with('branch','-a').returns("* foo") end it "will strip trailing newlines" do @@ -379,20 +375,20 @@ describe Puppet::Type.type(:vcsrepo).provider(:git_provider) do end context 'on master' do it do - provider.expects(:git).with('branch','--list').returns("* master") + provider.expects(:git).with('branch','-a').returns("* master") provider.latest.should == 'master' end end context 'no branch' do it do - provider.expects(:git).with('branch','--list').returns("* master") + provider.expects(:git).with('branch','-a').returns("* master") provider.latest.should == 'master' end end context 'feature/bar' do it do - provider.expects(:git).with('branch','--list').returns("* master") + provider.expects(:git).with('branch','-a').returns("* master") provider.latest.should == 'master' end end -- cgit v1.2.3 From 4613e93e35551271651bb7b1102d3b97a3f5b40d Mon Sep 17 00:00:00 2001 From: Travis Fields Date: Fri, 16 May 2014 16:30:58 -0700 Subject: Added multiline parsing tests for branch -a --- spec/unit/puppet/provider/vcsrepo/git_spec.rb | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'spec/unit/puppet') diff --git a/spec/unit/puppet/provider/vcsrepo/git_spec.rb b/spec/unit/puppet/provider/vcsrepo/git_spec.rb index 8e296ef..daec038 100644 --- a/spec/unit/puppet/provider/vcsrepo/git_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/git_spec.rb @@ -1,7 +1,16 @@ require 'spec_helper' describe Puppet::Type.type(:vcsrepo).provider(:git_provider) do + def branch_a_list(include_branch) + < 'test', :ensure => :present, @@ -26,7 +35,7 @@ describe Puppet::Type.type(:vcsrepo).provider(:git_provider) do 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(:git).with('branch', '-a').returns(resource.value(:revision)) + provider.expects(:git).with('branch', '-a').returns(branch_a_list(resource.value(:revision))) provider.expects(:git).with('checkout', '--force', resource.value(:revision)) provider.create end @@ -39,7 +48,7 @@ describe Puppet::Type.type(:vcsrepo).provider(:git_provider) do 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(:git).with('branch', '-a').returns(resource.value(:revision)) + provider.expects(:git).with('branch', '-a').returns(branch_a_list(resource.value(:revision))) provider.expects(:git).with('checkout', '--force', resource.value(:revision)) provider.create end @@ -53,7 +62,7 @@ describe Puppet::Type.type(:vcsrepo).provider(:git_provider) do Dir.expects(:chdir).with('/tmp/test').at_least_once.yields provider.expects(:git).with('clone', '--depth', '1', resource.value(:source), resource.value(:path)) provider.expects(:update_submodules) - provider.expects(:git).with('branch', '-a').returns(resource.value(:revision)) + provider.expects(:git).with('branch', '-a').returns(branch_a_list(resource.value(:revision))) provider.expects(:git).with('checkout', '--force', resource.value(:revision)) provider.create end @@ -66,7 +75,7 @@ describe Puppet::Type.type(:vcsrepo).provider(:git_provider) do 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(:git).with('branch', '-a').returns(resource.value(:revision)) + provider.expects(:git).with('branch', '-a').returns(branch_a_list(resource.value(:revision))) provider.expects(:git).with('checkout', '--force', resource.value(:revision)) provider.create end @@ -161,7 +170,7 @@ describe Puppet::Type.type(:vcsrepo).provider(:git_provider) do provider.destroy provider.expects(:git).with('clone',resource.value(:source), resource.value(:path)) provider.expects(:update_submodules) - provider.expects(:git).with('branch', '-a').returns(resource.value(:revision)) + provider.expects(:git).with('branch', '-a').returns(branch_a_list(resource.value(:revision))) provider.expects(:git).with('checkout', '--force', resource.value(:revision)) provider.create end @@ -261,7 +270,7 @@ describe Puppet::Type.type(:vcsrepo).provider(:git_provider) do it "should use 'git fetch' and 'git reset'" do resource[:revision] = 'feature/foo' provider.expects(:update_submodules) - provider.expects(:git).with('branch', '-a').at_least_once.returns(resource.value(:revision)) + provider.expects(:git).with('branch', '-a').at_least_once.returns(branch_a_list(resource.value(:revision))) provider.expects(:git).with('checkout', '--force', resource.value(:revision)) provider.expects(:git).with('reset', '--hard', "origin/#{resource.value(:revision)}") provider.revision = resource.value(:revision) @@ -280,7 +289,7 @@ describe Puppet::Type.type(:vcsrepo).provider(:git_provider) do context "when it's a commit or tag" do it "should use 'git fetch' and 'git reset'" do resource[:revision] = 'a-commit-or-tag' - provider.expects(:git).with('branch', '-a').returns(fixture(:git_branch_a)) + provider.expects(:git).with('branch', '-a').at_least_once.returns(fixture(:git_branch_a)) provider.expects(:git).with('checkout', '--force', resource.value(:revision)) provider.expects(:git).with('branch', '-a').returns(fixture(:git_branch_a)) provider.expects(:git).with('branch', '-a').returns(fixture(:git_branch_a)) -- cgit v1.2.3 From 0d9e938e92a25673c3712866e2d2108a255b67d5 Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Tue, 20 May 2014 18:15:03 -0700 Subject: Update specs and fix FM-1361 - Add install.rb for pre-suite - Add catches for failures/changes to manifest application - Correct root ssh key copying - Add sleeps for killing processes releasing ports - Fix FM-1361 --- spec/unit/puppet/provider/vcsrepo/git_spec.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'spec/unit/puppet') diff --git a/spec/unit/puppet/provider/vcsrepo/git_spec.rb b/spec/unit/puppet/provider/vcsrepo/git_spec.rb index daec038..a753610 100644 --- a/spec/unit/puppet/provider/vcsrepo/git_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/git_spec.rb @@ -90,10 +90,9 @@ branches context "with an ensure of bare" do context "with revision" do - it "should just execute 'git clone --bare'" do + it "should raise an error" do resource[:ensure] = :bare - provider.expects(:git).with('clone', '--bare', resource.value(:source), resource.value(:path)) - provider.create + expect { provider.create }.to raise_error Puppet::Error, /cannot set a revision.+bare/i end end context "without revision" do @@ -144,6 +143,7 @@ branches it "should execute 'git init --bare'" do resource[:ensure] = :bare resource.delete(:source) + resource.delete(:revision) expects_chdir expects_mkdir expects_directory?(false) @@ -157,6 +157,7 @@ branches it "should convert it to a bare repository" do resource[:ensure] = :bare resource.delete(:source) + resource.delete(:revision) provider.expects(:working_copy_exists?).returns(true) provider.expects(:convert_working_copy_to_bare) provider.create -- cgit v1.2.3 From 58f9cb20657a7be01777c920a37279f30dc1fce6 Mon Sep 17 00:00:00 2001 From: Paul Allen Date: Thu, 12 Jun 2014 17:50:55 +0100 Subject: Spec tests for p4 provider Test create, destroy and exists? access points. --- spec/unit/puppet/provider/vcsrepo/p4_spec.rb | 73 ++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 spec/unit/puppet/provider/vcsrepo/p4_spec.rb (limited to 'spec/unit/puppet') diff --git a/spec/unit/puppet/provider/vcsrepo/p4_spec.rb b/spec/unit/puppet/provider/vcsrepo/p4_spec.rb new file mode 100644 index 0000000..822106d --- /dev/null +++ b/spec/unit/puppet/provider/vcsrepo/p4_spec.rb @@ -0,0 +1,73 @@ +require 'spec_helper' + +describe Puppet::Type.type(:vcsrepo).provider(:p4) do + + let(:resource) { Puppet::Type.type(:vcsrepo).new({ + :name => 'test', + :ensure => :present, + :provider => :p4, + :path => '/tmp/vcsrepo', + })} + + let(:provider) { resource.provider } + + before :each do + Puppet::Util.stubs(:which).with('p4').returns('/usr/local/bin/p4') + end + + spec = { + :input => "Root: /tmp/vcsrepo\nDescription: Generated by Puppet VCSrepo\n\nView:\n", + :marshal => false + } + + describe 'creating' do + context 'with source and revision' do + it "should execute 'p4 sync' with the revision" do + resource[:source] = 'something' + resource[:p4client] = 'client_ws' + resource[:revision] = '1' + provider.expects(:p4).with(['client', '-o', resource.value(:p4client)]).returns({}) + provider.expects(:p4).with(['client', '-i'], spec) + provider.expects(:p4).with(['sync', resource.value(:source) + "@" + resource.value(:revision)]) + provider.create + end + end + + context 'without revision' do + it "should just execute 'p4 sync' without a revision" do + resource[:source] = 'something' + resource[:p4client] = 'client_ws' + provider.expects(:p4).with(['client', '-o', resource.value(:p4client)]).returns({}) + provider.expects(:p4).with(['client', '-i'], spec) + provider.expects(:p4).with(['sync', resource.value(:source)]) + provider.create + end + end + + context "when a client and source are not given" do + it "should execute 'p4 client'" do + provider.expects(:p4).with(['client', '-o', "puppet-51f0a4b45dbfc10614df94f0a189c16f"]).returns({}) + provider.expects(:p4).with(['client', '-i'], spec) + provider.create + end + end + end + + describe 'destroying' do + it "it should remove the directory" do + resource[:p4client] = 'test_client' + provider.expects(:p4).with(['client', '-d', '-f', resource.value(:p4client)]) + expects_rm_rf + provider.destroy + end + end + + describe "checking existence" do + it "should check for the directory" do + provider.expects(:p4).with(['info'], {:marshal => false}).returns({}) + provider.expects(:p4).with(['where', resource.value(:path) + "..."], {:raise => false}).returns({}) + provider.exists? + end + end + +end -- cgit v1.2.3 From 24e2f91ffb0091bc6f67b4d90f9702690bc1179f Mon Sep 17 00:00:00 2001 From: Paul Allen Date: Fri, 20 Jun 2014 09:59:42 +0100 Subject: Detab to 2 spaces. --- spec/unit/puppet/provider/vcsrepo/p4_spec.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'spec/unit/puppet') diff --git a/spec/unit/puppet/provider/vcsrepo/p4_spec.rb b/spec/unit/puppet/provider/vcsrepo/p4_spec.rb index 822106d..2c202f2 100644 --- a/spec/unit/puppet/provider/vcsrepo/p4_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/p4_spec.rb @@ -15,7 +15,7 @@ describe Puppet::Type.type(:vcsrepo).provider(:p4) do Puppet::Util.stubs(:which).with('p4').returns('/usr/local/bin/p4') end - spec = { + spec = { :input => "Root: /tmp/vcsrepo\nDescription: Generated by Puppet VCSrepo\n\nView:\n", :marshal => false } @@ -46,17 +46,17 @@ describe Puppet::Type.type(:vcsrepo).provider(:p4) do context "when a client and source are not given" do it "should execute 'p4 client'" do - provider.expects(:p4).with(['client', '-o', "puppet-51f0a4b45dbfc10614df94f0a189c16f"]).returns({}) - provider.expects(:p4).with(['client', '-i'], spec) - provider.create + provider.expects(:p4).with(['client', '-o', "puppet-51f0a4b45dbfc10614df94f0a189c16f"]).returns({}) + provider.expects(:p4).with(['client', '-i'], spec) + provider.create end end end describe 'destroying' do it "it should remove the directory" do - resource[:p4client] = 'test_client' - provider.expects(:p4).with(['client', '-d', '-f', resource.value(:p4client)]) + resource[:p4client] = 'test_client' + provider.expects(:p4).with(['client', '-d', '-f', resource.value(:p4client)]) expects_rm_rf provider.destroy end -- cgit v1.2.3 From 319f9fbe1954fd172da638f3ccd76e58c3ec8c7f Mon Sep 17 00:00:00 2001 From: Paul Allen Date: Mon, 23 Jun 2014 15:51:28 +0100 Subject: Added support for p4config. - Removed p4port, p4client, p4user to keep name space clean. - Changed notify to Puppet.debug - Updated markdown and examples - Updated unit tests --- spec/unit/puppet/provider/vcsrepo/p4_spec.rb | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'spec/unit/puppet') diff --git a/spec/unit/puppet/provider/vcsrepo/p4_spec.rb b/spec/unit/puppet/provider/vcsrepo/p4_spec.rb index 2c202f2..2bb81c8 100644 --- a/spec/unit/puppet/provider/vcsrepo/p4_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/p4_spec.rb @@ -24,9 +24,10 @@ describe Puppet::Type.type(:vcsrepo).provider(:p4) do context 'with source and revision' do it "should execute 'p4 sync' with the revision" do resource[:source] = 'something' - resource[:p4client] = 'client_ws' resource[:revision] = '1' - provider.expects(:p4).with(['client', '-o', resource.value(:p4client)]).returns({}) + ENV['P4CLIENT'] = 'client_ws1' + + provider.expects(:p4).with(['client', '-o', 'client_ws1']).returns({}) provider.expects(:p4).with(['client', '-i'], spec) provider.expects(:p4).with(['sync', resource.value(:source) + "@" + resource.value(:revision)]) provider.create @@ -36,8 +37,9 @@ describe Puppet::Type.type(:vcsrepo).provider(:p4) do context 'without revision' do it "should just execute 'p4 sync' without a revision" do resource[:source] = 'something' - resource[:p4client] = 'client_ws' - provider.expects(:p4).with(['client', '-o', resource.value(:p4client)]).returns({}) + ENV['P4CLIENT'] = 'client_ws2' + + provider.expects(:p4).with(['client', '-o', 'client_ws2']).returns({}) provider.expects(:p4).with(['client', '-i'], spec) provider.expects(:p4).with(['sync', resource.value(:source)]) provider.create @@ -55,8 +57,9 @@ describe Puppet::Type.type(:vcsrepo).provider(:p4) do describe 'destroying' do it "it should remove the directory" do - resource[:p4client] = 'test_client' - provider.expects(:p4).with(['client', '-d', '-f', resource.value(:p4client)]) + ENV['P4CLIENT'] = 'test_client' + + provider.expects(:p4).with(['client', '-d', '-f', 'test_client']) expects_rm_rf provider.destroy end -- cgit v1.2.3 From 457035ec1c15df0d53abf7232dad63b2722b1720 Mon Sep 17 00:00:00 2001 From: Paul Allen Date: Mon, 23 Jun 2014 16:22:35 +0100 Subject: Add hostname to Digest for default client name. --- spec/unit/puppet/provider/vcsrepo/p4_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/unit/puppet') diff --git a/spec/unit/puppet/provider/vcsrepo/p4_spec.rb b/spec/unit/puppet/provider/vcsrepo/p4_spec.rb index 2bb81c8..e45650a 100644 --- a/spec/unit/puppet/provider/vcsrepo/p4_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/p4_spec.rb @@ -48,7 +48,7 @@ describe Puppet::Type.type(:vcsrepo).provider(:p4) do context "when a client and source are not given" do it "should execute 'p4 client'" do - provider.expects(:p4).with(['client', '-o', "puppet-51f0a4b45dbfc10614df94f0a189c16f"]).returns({}) + provider.expects(:p4).with(['client', '-o', "puppet-1c5e7a8e4f702e5091dfba173bc0e7c0"]).returns({}) provider.expects(:p4).with(['client', '-i'], spec) provider.create end -- cgit v1.2.3 From 2ff03cff1795d3e43c922f7bceb235ce69175013 Mon Sep 17 00:00:00 2001 From: Stuart Whelan Date: Sat, 21 Jun 2014 17:26:14 +1200 Subject: Added support for basic authentication to hg provider Updated unit tests Updated hg readme and added examples --- spec/unit/puppet/provider/vcsrepo/hg_spec.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'spec/unit/puppet') diff --git a/spec/unit/puppet/provider/vcsrepo/hg_spec.rb b/spec/unit/puppet/provider/vcsrepo/hg_spec.rb index 7fd5348..6b21c1c 100644 --- a/spec/unit/puppet/provider/vcsrepo/hg_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/hg_spec.rb @@ -42,6 +42,22 @@ describe Puppet::Type.type(:vcsrepo).provider(:hg) do provider.create end end + + context "when basic auth is used" do + it "should execute 'hg clone'" do + resource[:source] = 'something' + resource[:basic_auth_username] = 'user' + resource[:basic_auth_password] = 'pass' + provider.expects(:hg).with('clone', + resource.value(:source), + resource.value(:path), + "--config","\"auth.x.prefix=" + resource.value(:source) + "\"", + "--config","\"auth.x.username=" + resource.value(:basic_auth_username) + "\"", + "--config","\"auth.x.password=" + resource.value(:basic_auth_password) + "\"", + "--config","\"auth.x.schemes=http https" + "\"") + provider.create + end + end end describe 'destroying' do -- cgit v1.2.3 From f88ae5fd6c746de3b454e38a8616f016ada8cff9 Mon Sep 17 00:00:00 2001 From: Paul Allen Date: Tue, 24 Jun 2014 14:16:05 +0100 Subject: Sort keys on hash generate same test result. Keys in the Client spec were processed out of order and failing tests. --- spec/unit/puppet/provider/vcsrepo/p4_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/unit/puppet') diff --git a/spec/unit/puppet/provider/vcsrepo/p4_spec.rb b/spec/unit/puppet/provider/vcsrepo/p4_spec.rb index e45650a..1261915 100644 --- a/spec/unit/puppet/provider/vcsrepo/p4_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/p4_spec.rb @@ -16,7 +16,7 @@ describe Puppet::Type.type(:vcsrepo).provider(:p4) do end spec = { - :input => "Root: /tmp/vcsrepo\nDescription: Generated by Puppet VCSrepo\n\nView:\n", + :input => "Description: Generated by Puppet VCSrepo\nRoot: /tmp/vcsrepo\n\nView:\n", :marshal => false } -- cgit v1.2.3 From 818f5298b6be3b1a25e997ba84eae237d9051be9 Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Fri, 20 Jun 2014 13:48:02 -0700 Subject: Update noop to work --- spec/unit/puppet/provider/vcsrepo/git_spec.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'spec/unit/puppet') diff --git a/spec/unit/puppet/provider/vcsrepo/git_spec.rb b/spec/unit/puppet/provider/vcsrepo/git_spec.rb index a753610..2fd63f0 100644 --- a/spec/unit/puppet/provider/vcsrepo/git_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/git_spec.rb @@ -175,6 +175,28 @@ branches provider.expects(:git).with('checkout', '--force', resource.value(:revision)) provider.create end + it "should warn about destroying it using force and noop attribute" do + resource[:force] = true + resource[:noop] = true + resource.delete(:revision) + provider.expects(:working_copy_exists?).returns(true) + + provider.expects(:destroy).never + provider.expects(:create).never + Puppet::Type::Vcsrepo::Ensure.any_instance.expects(:send_log).with(:notice, "Noop Mode - Would have deleted repository and re-created from latest") + provider.resource.retrieve + end + it "should warn about destroying it using force and global noop" do + resource[:force] = true + Puppet[:noop] = true + resource.delete(:revision) + provider.expects(:working_copy_exists?).returns(true) + + provider.expects(:destroy).never + provider.expects(:create).never + Puppet::Type::Vcsrepo::Ensure.any_instance.expects(:send_log).with(:notice, "Noop Mode - Would have deleted repository and re-created from latest") + provider.resource.retrieve + end end context "when the path is not empty and not a repository" do -- cgit v1.2.3 From 0435f81a3b8821a36dedc038982c3efdab90a3b1 Mon Sep 17 00:00:00 2001 From: Paul Allen Date: Fri, 27 Jun 2014 14:14:47 +0100 Subject: Clear P4CLIENT Environment before test --- spec/unit/puppet/provider/vcsrepo/p4_spec.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'spec/unit/puppet') diff --git a/spec/unit/puppet/provider/vcsrepo/p4_spec.rb b/spec/unit/puppet/provider/vcsrepo/p4_spec.rb index 1261915..3a4605b 100644 --- a/spec/unit/puppet/provider/vcsrepo/p4_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/p4_spec.rb @@ -48,6 +48,8 @@ describe Puppet::Type.type(:vcsrepo).provider(:p4) do context "when a client and source are not given" do it "should execute 'p4 client'" do + ENV['P4CLIENT'] = nil + provider.expects(:p4).with(['client', '-o', "puppet-1c5e7a8e4f702e5091dfba173bc0e7c0"]).returns({}) provider.expects(:p4).with(['client', '-i'], spec) provider.create -- cgit v1.2.3 From b5b2dd296eb30df25ea3d4ca125ca451b162393c Mon Sep 17 00:00:00 2001 From: Paul Allen Date: Fri, 27 Jun 2014 17:44:27 +0100 Subject: Calculate client workspace name for test case (The value of host will be different) --- spec/unit/puppet/provider/vcsrepo/p4_spec.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'spec/unit/puppet') diff --git a/spec/unit/puppet/provider/vcsrepo/p4_spec.rb b/spec/unit/puppet/provider/vcsrepo/p4_spec.rb index 3a4605b..2d382da 100644 --- a/spec/unit/puppet/provider/vcsrepo/p4_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/p4_spec.rb @@ -50,7 +50,11 @@ describe Puppet::Type.type(:vcsrepo).provider(:p4) do it "should execute 'p4 client'" do ENV['P4CLIENT'] = nil - provider.expects(:p4).with(['client', '-o', "puppet-1c5e7a8e4f702e5091dfba173bc0e7c0"]).returns({}) + path = resource.value(:path) + host = Facter.value('hostname') + default = "puppet-" + Digest::MD5.hexdigest(path + host) + + provider.expects(:p4).with(['client', '-o', default]).returns({}) provider.expects(:p4).with(['client', '-i'], spec) provider.create end -- cgit v1.2.3 From 34cc0c0d4e35fdc5a7b8381033886d160927d501 Mon Sep 17 00:00:00 2001 From: Paul Allen Date: Wed, 2 Jul 2014 12:05:35 +0100 Subject: Update Markdown with missing Perforce details. Fix tabs/spaces in p4.rb --- spec/unit/puppet/provider/vcsrepo/p4_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/unit/puppet') diff --git a/spec/unit/puppet/provider/vcsrepo/p4_spec.rb b/spec/unit/puppet/provider/vcsrepo/p4_spec.rb index 2d382da..abbd9ec 100644 --- a/spec/unit/puppet/provider/vcsrepo/p4_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/p4_spec.rb @@ -51,7 +51,7 @@ describe Puppet::Type.type(:vcsrepo).provider(:p4) do ENV['P4CLIENT'] = nil path = resource.value(:path) - host = Facter.value('hostname') + host = Facter.value('hostname') default = "puppet-" + Digest::MD5.hexdigest(path + host) provider.expects(:p4).with(['client', '-o', default]).returns({}) -- cgit v1.2.3 From 6624f40651f44e184878a9fbb862bda886d899e8 Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Wed, 18 Jun 2014 13:54:51 -0700 Subject: (MODULES-660) Correct detached HEAD on latest Previously vcsrepo detached HEAD on checkout which caused further branch revisions to fail. This corrects the behavior, and works on git 1.7, 1.8, 1.9, and 2.0 --- spec/unit/puppet/provider/vcsrepo/git_spec.rb | 94 ++++++--------------------- 1 file changed, 20 insertions(+), 74 deletions(-) (limited to 'spec/unit/puppet') diff --git a/spec/unit/puppet/provider/vcsrepo/git_spec.rb b/spec/unit/puppet/provider/vcsrepo/git_spec.rb index 2fd63f0..3f81cc8 100644 --- a/spec/unit/puppet/provider/vcsrepo/git_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/git_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe Puppet::Type.type(:vcsrepo).provider(:git_provider) do - def branch_a_list(include_branch) + def branch_a_list(include_branch = nil?) < Date: Sat, 13 Sep 2014 22:48:18 -0700 Subject: Remove excess whitespace --- spec/unit/puppet/provider/vcsrepo/p4_spec.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'spec/unit/puppet') diff --git a/spec/unit/puppet/provider/vcsrepo/p4_spec.rb b/spec/unit/puppet/provider/vcsrepo/p4_spec.rb index abbd9ec..e331cae 100644 --- a/spec/unit/puppet/provider/vcsrepo/p4_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/p4_spec.rb @@ -26,7 +26,7 @@ describe Puppet::Type.type(:vcsrepo).provider(:p4) do resource[:source] = 'something' resource[:revision] = '1' ENV['P4CLIENT'] = 'client_ws1' - + provider.expects(:p4).with(['client', '-o', 'client_ws1']).returns({}) provider.expects(:p4).with(['client', '-i'], spec) provider.expects(:p4).with(['sync', resource.value(:source) + "@" + resource.value(:revision)]) @@ -38,7 +38,7 @@ describe Puppet::Type.type(:vcsrepo).provider(:p4) do it "should just execute 'p4 sync' without a revision" do resource[:source] = 'something' ENV['P4CLIENT'] = 'client_ws2' - + provider.expects(:p4).with(['client', '-o', 'client_ws2']).returns({}) provider.expects(:p4).with(['client', '-i'], spec) provider.expects(:p4).with(['sync', resource.value(:source)]) @@ -49,11 +49,11 @@ describe Puppet::Type.type(:vcsrepo).provider(:p4) do context "when a client and source are not given" do it "should execute 'p4 client'" do ENV['P4CLIENT'] = nil - + path = resource.value(:path) host = Facter.value('hostname') default = "puppet-" + Digest::MD5.hexdigest(path + host) - + provider.expects(:p4).with(['client', '-o', default]).returns({}) provider.expects(:p4).with(['client', '-i'], spec) provider.create @@ -64,7 +64,7 @@ describe Puppet::Type.type(:vcsrepo).provider(:p4) do describe 'destroying' do it "it should remove the directory" do ENV['P4CLIENT'] = 'test_client' - + provider.expects(:p4).with(['client', '-d', '-f', 'test_client']) expects_rm_rf provider.destroy -- cgit v1.2.3 From 1df5570580c1d429a8fed25033a19333fcaffbda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Gali=C4=87?= Date: Mon, 29 Sep 2014 19:19:21 +0200 Subject: Convert specs to RSpec 2.99.2 syntax with Transpec This conversion is done by Transpec 2.3.7 with the following command: transpec * 22 conversions from: it { should ... } to: it { is_expected.to ... } * 19 conversions from: obj.should to: expect(obj).to * 15 conversions from: == expected to: eq(expected) * 5 conversions from: it { should_not ... } to: it { is_expected.not_to ... } * 2 conversions from: its(:attr) { } to: describe '#attr' do subject { super().attr }; it { } end * 2 conversions from: obj.should_not to: expect(obj).not_to * 2 conversions from: proc { }.should to: expect { }.to * 1 conversion from: be_false to: be_falsey * 1 conversion from: be_true to: be_truthy For more details: https://github.com/yujinakayama/transpec#supported-conversions --- spec/unit/puppet/provider/vcsrepo/bzr_spec.rb | 8 ++++---- spec/unit/puppet/provider/vcsrepo/cvs_spec.rb | 4 ++-- spec/unit/puppet/provider/vcsrepo/git_spec.rb | 24 ++++++++++++------------ spec/unit/puppet/provider/vcsrepo/hg_spec.rb | 8 ++++---- spec/unit/puppet/provider/vcsrepo/svn_spec.rb | 2 +- 5 files changed, 23 insertions(+), 23 deletions(-) (limited to 'spec/unit/puppet') diff --git a/spec/unit/puppet/provider/vcsrepo/bzr_spec.rb b/spec/unit/puppet/provider/vcsrepo/bzr_spec.rb index 488ddc0..b5e2f73 100644 --- a/spec/unit/puppet/provider/vcsrepo/bzr_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/bzr_spec.rb @@ -67,14 +67,14 @@ describe Puppet::Type.type(:vcsrepo).provider(:bzr_provider) do it "should return the ref" do resource[:revision] = '2634' provider.expects(:bzr).with('revision-info', '2634').returns("2634 menesis@pov.lt-20100309191856-4wmfqzc803fj300x\n") - provider.revision.should == resource.value(:revision) + expect(provider.revision).to eq(resource.value(:revision)) end end context "when its revid is different than the current revid" do it "should return the current revid" do resource[:revision] = '2636' provider.expects(:bzr).with('revision-info', resource.value(:revision)).returns("2635 foo\n") - provider.revision.should == @current_revid + expect(provider.revision).to eq(@current_revid) end end end @@ -84,14 +84,14 @@ describe Puppet::Type.type(:vcsrepo).provider(:bzr_provider) do it "should return it" do resource[:revision] = 'menesis@pov.lt-20100309191856-4wmfqzc803fj300x' provider.expects(:bzr).with('revision-info', resource.value(:revision)).returns("1234 #{resource.value(:revision)}\n") - provider.revision.should == resource.value(:revision) + expect(provider.revision).to eq(resource.value(:revision)) end end context "when it is not the same as the current revid" do it "should return the current revid" do resource[:revision] = 'menesis@pov.lt-20100309191856-4wmfqzc803fj300y' provider.expects(:bzr).with('revision-info', resource.value(:revision)).returns("2636 foo\n") - provider.revision.should == @current_revid + expect(provider.revision).to eq(@current_revid) end end diff --git a/spec/unit/puppet/provider/vcsrepo/cvs_spec.rb b/spec/unit/puppet/provider/vcsrepo/cvs_spec.rb index efa4b33..f5eebd9 100644 --- a/spec/unit/puppet/provider/vcsrepo/cvs_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/cvs_spec.rb @@ -86,7 +86,7 @@ describe Puppet::Type.type(:vcsrepo).provider(:cvs_provider) do end it "should read CVS/Tag" do File.expects(:read).with(@tag_file).returns("T#{@tag}") - provider.revision.should == @tag + expect(provider.revision).to eq(@tag) end end @@ -95,7 +95,7 @@ describe Puppet::Type.type(:vcsrepo).provider(:cvs_provider) do File.expects(:exist?).with(@tag_file).returns(false) end it "assumes HEAD" do - provider.revision.should == 'HEAD' + expect(provider.revision).to eq('HEAD') end end end diff --git a/spec/unit/puppet/provider/vcsrepo/git_spec.rb b/spec/unit/puppet/provider/vcsrepo/git_spec.rb index 3f81cc8..122eb62 100644 --- a/spec/unit/puppet/provider/vcsrepo/git_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/git_spec.rb @@ -134,7 +134,7 @@ branches it "should raise an exception" do provider.expects(:path_exists?).returns(true) provider.expects(:path_empty?).returns(false) - proc { provider.create }.should raise_error(Puppet::Error) + expect { provider.create }.to raise_error(Puppet::Error) end end end @@ -204,7 +204,7 @@ branches provider.expects(:path_exists?).returns(true) provider.expects(:path_empty?).returns(false) provider.expects(:working_copy_exists?).returns(false) - proc { provider.create }.should raise_error(Puppet::Error) + expect { provider.create }.to raise_error(Puppet::Error) end end end @@ -233,14 +233,14 @@ 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.revision.should == resource.value(:revision) + expect(provider.revision).to eq(resource.value(:revision)) end end 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.revision.should == resource.value(:revision) + expect(provider.revision).to eq(resource.value(:revision)) end end @@ -248,7 +248,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.revision.should == resource.value(:revision) + expect(provider.revision).to eq(resource.value(:revision)) end end @@ -267,7 +267,7 @@ branches 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('rev-parse', resource.value(:revision)).returns('currentsha') - provider.revision.should == resource.value(:revision) + expect(provider.revision).to eq(resource.value(:revision)) end end end @@ -329,13 +329,13 @@ branches context "when it's listed in 'git branch -a'" do it "should return true" do resource[:revision] = 'feature/foo' - provider.should be_local_branch_revision + expect(provider).to be_local_branch_revision end end context "when it's not listed in 'git branch -a'" do it "should return false" do resource[:revision] = 'feature/notexist' - provider.should_not be_local_branch_revision + expect(provider).not_to be_local_branch_revision end end end @@ -343,13 +343,13 @@ branches context "when it's listed in 'git branch -a' with an 'origin/' prefix" do it "should return true" do resource[:revision] = 'only/remote' - provider.should be_remote_branch_revision + expect(provider).to be_remote_branch_revision end end context "when it's not listed in 'git branch -a' with an 'origin/' prefix" do it "should return false" do resource[:revision] = 'only/local' - provider.should_not be_remote_branch_revision + expect(provider).not_to be_remote_branch_revision end end end @@ -360,14 +360,14 @@ branches it do provider.expects(:revision).returns('testrev') provider.expects(:latest_revision).returns('testrev') - provider.latest?.should be_true + expect(provider.latest?).to be_truthy end end context 'when false' do it do provider.expects(:revision).returns('master') provider.expects(:latest_revision).returns('testrev') - provider.latest?.should be_false + expect(provider.latest?).to be_falsey end end end diff --git a/spec/unit/puppet/provider/vcsrepo/hg_spec.rb b/spec/unit/puppet/provider/vcsrepo/hg_spec.rb index 6b21c1c..65d820d 100644 --- a/spec/unit/puppet/provider/vcsrepo/hg_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/hg_spec.rb @@ -88,14 +88,14 @@ describe Puppet::Type.type(:vcsrepo).provider(:hg) do context "when its SHA is not different than the current SHA" do it "should return the ref" do resource[:revision] = '0.6' - provider.revision.should == '0.6' + expect(provider.revision).to eq('0.6') end end context "when its SHA is different than the current SHA" do it "should return the current SHA" do resource[:revision] = '0.5.3' - provider.revision.should == '34e6012c783a' + expect(provider.revision).to eq('34e6012c783a') end end end @@ -108,7 +108,7 @@ describe Puppet::Type.type(:vcsrepo).provider(:hg) do it "should return it" do resource[:revision] = '34e6012c783a' provider.expects(:hg).with('tags').returns(fixture(:hg_tags)) - provider.revision.should == resource.value(:revision) + expect(provider.revision).to eq(resource.value(:revision)) end end @@ -116,7 +116,7 @@ describe Puppet::Type.type(:vcsrepo).provider(:hg) do it "should return the current SHA" do resource[:revision] = 'not-the-same' provider.expects(:hg).with('tags').returns(fixture(:hg_tags)) - provider.revision.should == '34e6012c783a' + expect(provider.revision).to eq('34e6012c783a') end end end diff --git a/spec/unit/puppet/provider/vcsrepo/svn_spec.rb b/spec/unit/puppet/provider/vcsrepo/svn_spec.rb index f44e314..494da52 100644 --- a/spec/unit/puppet/provider/vcsrepo/svn_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/svn_spec.rb @@ -75,7 +75,7 @@ describe Puppet::Type.type(:vcsrepo).provider(:svn) do end it "should use 'svn info'" do expects_chdir - provider.revision.should == '4' # From 'Revision', not 'Last Changed Rev' + expect(provider.revision).to eq('4') # From 'Revision', not 'Last Changed Rev' end end -- cgit v1.2.3 From 9cef7c46c98153affbb3cd02e4a26afb43664e6d Mon Sep 17 00:00:00 2001 From: Jon Fautley Date: Wed, 29 Oct 2014 10:59:58 +0000 Subject: Rework spec tests to support new execution method --- spec/unit/puppet/provider/vcsrepo/cvs_spec.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'spec/unit/puppet') diff --git a/spec/unit/puppet/provider/vcsrepo/cvs_spec.rb b/spec/unit/puppet/provider/vcsrepo/cvs_spec.rb index f5eebd9..b146d70 100644 --- a/spec/unit/puppet/provider/vcsrepo/cvs_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/cvs_spec.rb @@ -23,14 +23,14 @@ describe Puppet::Type.type(:vcsrepo).provider(:cvs_provider) do resource[:source] = ':ext:source@example.com:/foo/bar' resource[:revision] = 'an-unimportant-value' expects_chdir('/tmp') - provider.expects(:cvs).with('-d', resource.value(:source), 'checkout', '-r', 'an-unimportant-value', '-d', 'test', 'bar') + Puppet::Util::Execution.expects(:execute).with([:cvs, '-d', resource.value(:source), 'checkout', '-r', 'an-unimportant-value', '-d', 'test', 'bar'], :custom_environment => {}) provider.create end it "should just execute 'cvs checkout' without a revision" do resource[:source] = ':ext:source@example.com:/foo/bar' resource.delete(:revision) - provider.expects(:cvs).with('-d', resource.value(:source), 'checkout', '-d', File.basename(resource.value(:path)), File.basename(resource.value(:source))) + Puppet::Util::Execution.expects(:execute).with([:cvs, '-d', resource.value(:source), 'checkout', '-d', File.basename(resource.value(:path)), File.basename(resource.value(:source))], :custom_environment => {}) provider.create end @@ -39,7 +39,7 @@ describe Puppet::Type.type(:vcsrepo).provider(:cvs_provider) do resource[:source] = ':ext:source@example.com:/foo/bar' resource[:compression] = '3' resource.delete(:revision) - provider.expects(:cvs).with('-d', resource.value(:source), '-z', '3', 'checkout', '-d', File.basename(resource.value(:path)), File.basename(resource.value(:source))) + Puppet::Util::Execution.expects(:execute).with([:cvs, '-d', resource.value(:source), '-z', '3', 'checkout', '-d', File.basename(resource.value(:path)), File.basename(resource.value(:source))], :custom_environment => {}) provider.create end end @@ -48,7 +48,7 @@ describe Puppet::Type.type(:vcsrepo).provider(:cvs_provider) do context "when a source is not given" do it "should execute 'cvs init'" do resource.delete(:source) - provider.expects(:cvs).with('-d', resource.value(:path), 'init') + Puppet::Util::Execution.expects(:execute).with([:cvs, '-d', resource.value(:path), 'init'], :custom_environment => {}) provider.create end end @@ -107,7 +107,7 @@ describe Puppet::Type.type(:vcsrepo).provider(:cvs_provider) do it "should use 'cvs update -dr'" do expects_chdir - provider.expects(:cvs).with('update', '-dr', @tag, '.') + Puppet::Util::Execution.expects(:execute).with([:cvs, 'update', '-dr', @tag, '.'], :custom_environment => {}) provider.revision = @tag end end -- cgit v1.2.3 From 2b927e514a3d8aef5d35094e84dee3d6b47d6bf2 Mon Sep 17 00:00:00 2001 From: Jon Fautley Date: Wed, 29 Oct 2014 11:00:33 +0000 Subject: Add spec test for invokation as a different user --- spec/unit/puppet/provider/vcsrepo/cvs_spec.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'spec/unit/puppet') diff --git a/spec/unit/puppet/provider/vcsrepo/cvs_spec.rb b/spec/unit/puppet/provider/vcsrepo/cvs_spec.rb index b146d70..2e18149 100644 --- a/spec/unit/puppet/provider/vcsrepo/cvs_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/cvs_spec.rb @@ -27,6 +27,15 @@ describe Puppet::Type.type(:vcsrepo).provider(:cvs_provider) do provider.create end + it "should execute 'cvs checkout' as user 'muppet'" do + resource[:source] = ':ext:source@example.com:/foo/bar' + resource[:revision] = 'an-unimportant-value' + resource[:user] = 'muppet' + expects_chdir('/tmp') + Puppet::Util::Execution.expects(:execute).with([:cvs, '-d', resource.value(:source), 'checkout', '-r', 'an-unimportant-value', '-d', 'test', 'bar'], :uid => 'muppet', :custom_environment => {}) + provider.create + end + it "should just execute 'cvs checkout' without a revision" do resource[:source] = ':ext:source@example.com:/foo/bar' resource.delete(:revision) -- cgit v1.2.3 From 56f25d57dfa26de618416e9bdd4a853296ffcbc1 Mon Sep 17 00:00:00 2001 From: Morgan Haskel Date: Fri, 26 Dec 2014 15:27:20 -0800 Subject: MODULES-1596 - Repository repeatedly destroyed/created with force The `retrieve` method was calling `create` and `destroy` on every run with `force => true`. Retrieve should not be making any changes to the system, so removed that code, and updated `working_copy_exists` to make sure that the directory not only contains a `.git` directory, but also if `source` is specified it also matches `#{path}/.git/config` so that it will overwrite a git repo with a different source. Updated tests to not check for the old broken behavior. Added a regression test. --- spec/unit/puppet/provider/vcsrepo/git_spec.rb | 22 ---------------------- 1 file changed, 22 deletions(-) (limited to 'spec/unit/puppet') diff --git a/spec/unit/puppet/provider/vcsrepo/git_spec.rb b/spec/unit/puppet/provider/vcsrepo/git_spec.rb index 122eb62..edc7202 100644 --- a/spec/unit/puppet/provider/vcsrepo/git_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/git_spec.rb @@ -175,28 +175,6 @@ branches provider.expects(:git).with('checkout', '--force', resource.value(:revision)) provider.create end - it "should warn about destroying it using force and noop attribute" do - resource[:force] = true - resource[:noop] = true - resource.delete(:revision) - provider.expects(:working_copy_exists?).returns(true) - - provider.expects(:destroy).never - provider.expects(:create).never - Puppet::Type::Vcsrepo::Ensure.any_instance.expects(:send_log).with(:notice, "Noop Mode - Would have deleted repository and re-created from latest") - provider.resource.retrieve - end - it "should warn about destroying it using force and global noop" do - resource[:force] = true - Puppet[:noop] = true - resource.delete(:revision) - provider.expects(:working_copy_exists?).returns(true) - - provider.expects(:destroy).never - provider.expects(:create).never - Puppet::Type::Vcsrepo::Ensure.any_instance.expects(:send_log).with(:notice, "Noop Mode - Would have deleted repository and re-created from latest") - provider.resource.retrieve - end end context "when the path is not empty and not a repository" do -- cgit v1.2.3 From 2d4abcd7b92971dba9f00e6422c4f5250a15f716 Mon Sep 17 00:00:00 2001 From: tphoney Date: Tue, 13 Jan 2015 17:06:45 -0800 Subject: removing private tests removing private tests, due to rspec3 not handling private methods --- spec/unit/puppet/provider/vcsrepo/git_spec.rb | 35 --------------------------- 1 file changed, 35 deletions(-) (limited to 'spec/unit/puppet') diff --git a/spec/unit/puppet/provider/vcsrepo/git_spec.rb b/spec/unit/puppet/provider/vcsrepo/git_spec.rb index edc7202..116e357 100644 --- a/spec/unit/puppet/provider/vcsrepo/git_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/git_spec.rb @@ -298,41 +298,6 @@ branches end end - context "checking if revision" do - before do - expects_chdir - provider.expects(:git).with('branch', '-a').returns(fixture(:git_branch_a)) - end - context "is a local branch" do - context "when it's listed in 'git branch -a'" do - it "should return true" do - resource[:revision] = 'feature/foo' - expect(provider).to be_local_branch_revision - end - end - context "when it's not listed in 'git branch -a'" do - it "should return false" do - resource[:revision] = 'feature/notexist' - expect(provider).not_to be_local_branch_revision - end - end - end - context "is a remote branch" do - context "when it's listed in 'git branch -a' with an 'origin/' prefix" do - it "should return true" do - resource[:revision] = 'only/remote' - expect(provider).to be_remote_branch_revision - end - end - context "when it's not listed in 'git branch -a' with an 'origin/' prefix" do - it "should return false" do - resource[:revision] = 'only/local' - expect(provider).not_to be_remote_branch_revision - end - end - end - end - describe 'latest?' do context 'when true' do it do -- cgit v1.2.3 From 5d6ef988af1ff90b4625b0426301cb6fad0268b8 Mon Sep 17 00:00:00 2001 From: Jonathan Tripathy Date: Tue, 20 Jan 2015 23:12:20 -0800 Subject: Implemented multiple remotes feature for git provider. --- spec/unit/puppet/provider/vcsrepo/git_spec.rb | 32 +++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) (limited to 'spec/unit/puppet') diff --git a/spec/unit/puppet/provider/vcsrepo/git_spec.rb b/spec/unit/puppet/provider/vcsrepo/git_spec.rb index 116e357..d0153a1 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', 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/foo.git\n", "remote.origin.url=git://git@foo.com/bar.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 -- cgit v1.2.3 From 7fdfa1b4047e134053f6df95f414cb3fc44796cd Mon Sep 17 00:00:00 2001 From: Daniel DiSisto Date: Fri, 6 Mar 2015 17:01:38 +1100 Subject: (MODULES-1551) Add support for SVN conflict handling --- spec/unit/puppet/provider/vcsrepo/svn_spec.rb | 43 +++++++++++++++++++++------ 1 file changed, 34 insertions(+), 9 deletions(-) (limited to 'spec/unit/puppet') 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 -- cgit v1.2.3 From d27759141ec5592fd5d76861efa77a55d07c90a8 Mon Sep 17 00:00:00 2001 From: Colleen Murphy Date: Wed, 25 Mar 2015 12:04:16 -0700 Subject: Fix remote hash ordering for unit tests Without this commit, the unit tests for the git provider changing multiple remotes mocks the remotes in a particular order. While in practice it doesn't matter which remote the update_remotes method updates first, the unit tests must be able to mock them in the correct order. For ruby 1.8.7, a Hash will not necessarily produce key value pairs in the same order on each run, which causes intermittent failures in the unit tests. This change sorts the :source property values before trying to update them, and updates the unit tests to expect the values in alphabetical order. --- spec/unit/puppet/provider/vcsrepo/git_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/unit/puppet') diff --git a/spec/unit/puppet/provider/vcsrepo/git_spec.rb b/spec/unit/puppet/provider/vcsrepo/git_spec.rb index d0153a1..d33c98a 100644 --- a/spec/unit/puppet/provider/vcsrepo/git_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/git_spec.rb @@ -263,7 +263,7 @@ branches 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/foo.git\n", "remote.origin.url=git://git@foo.com/bar.git\n") + 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') -- cgit v1.2.3 From ae60f5ccb7c00a0e162a06ba05d247688ffbce4b Mon Sep 17 00:00:00 2001 From: Jonathan Tripathy Date: Mon, 22 Jun 2015 15:22:16 +0100 Subject: MODULES-2131 Git provider now takes account of revision property when using depth property. --- spec/unit/puppet/provider/vcsrepo/git_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/unit/puppet') diff --git a/spec/unit/puppet/provider/vcsrepo/git_spec.rb b/spec/unit/puppet/provider/vcsrepo/git_spec.rb index 116e357..29c6b3b 100644 --- a/spec/unit/puppet/provider/vcsrepo/git_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/git_spec.rb @@ -60,7 +60,7 @@ branches resource[:depth] = 1 Dir.expects(:chdir).with('/').at_least_once.yields Dir.expects(:chdir).with('/tmp/test').at_least_once.yields - provider.expects(:git).with('clone', '--depth', '1', resource.value(:source), resource.value(:path)) + provider.expects(:git).with('clone', '--depth', '1', '--branch', resource.value(:revision),resource.value(:source), resource.value(:path)) provider.expects(:update_submodules) provider.expects(:git).with('branch', '-a').returns(branch_a_list(resource.value(:revision))) provider.expects(:git).with('checkout', '--force', resource.value(:revision)) -- cgit v1.2.3 From 14c05f5d6c589bebc9f93eb117105c14ce7be6f1 Mon Sep 17 00:00:00 2001 From: Morgan Haskel Date: Thu, 13 Aug 2015 16:02:22 -0700 Subject: MODULES-2125 - Allow revision to be passed without source Will also work with empty repositories. --- spec/unit/puppet/provider/vcsrepo/git_spec.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'spec/unit/puppet') diff --git a/spec/unit/puppet/provider/vcsrepo/git_spec.rb b/spec/unit/puppet/provider/vcsrepo/git_spec.rb index a240b50..87113fa 100644 --- a/spec/unit/puppet/provider/vcsrepo/git_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/git_spec.rb @@ -206,7 +206,7 @@ branches before do expects_chdir('/tmp/test') resource[:revision] = 'currentsha' - resource.delete(:source) + resource[:source] = 'http://example.com' provider.stubs(:git).with('config', 'remote.origin.url').returns('') provider.stubs(:git).with('fetch', 'origin') # FIXME provider.stubs(:git).with('fetch', '--tags', 'origin') @@ -272,6 +272,14 @@ branches end end + context "when there's no source" do + it 'should return the revision' do + resource.delete(:source) + provider.expects(:git).with('status') + 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 -- cgit v1.2.3 From 7758331f503a9198921362761079cbfd941c625e Mon Sep 17 00:00:00 2001 From: monai Date: Wed, 9 Sep 2015 19:20:58 +0300 Subject: Add feature depth and param trust_server_cert to svn added param trust server cert updated depth feature updated README.markdown trust_server_cert is not feature trust_server_cert default value should be false add test for depth and trust_server_cert --- spec/unit/puppet/provider/vcsrepo/svn_spec.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'spec/unit/puppet') diff --git a/spec/unit/puppet/provider/vcsrepo/svn_spec.rb b/spec/unit/puppet/provider/vcsrepo/svn_spec.rb index 77f0e03..25951bd 100644 --- a/spec/unit/puppet/provider/vcsrepo/svn_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/svn_spec.rb @@ -52,6 +52,28 @@ describe Puppet::Type.type(:vcsrepo).provider(:svn) do provider.create end end + + context "with depth" do + it "should execute 'svn checkout' with a depth" do + resource[:source] = 'exists' + resource[:depth] = 'infinity' + provider.expects(:svn).with('--non-interactive', 'checkout', '--depth', 'infinity', + resource.value(:source), + resource.value(:path)) + provider.create + end + end + + context "with trust_server_cert" do + it "should execute 'svn checkout' with a trust-server-cert" do + resource[:source] = 'exists' + resource[:trust_server_cert] = true + provider.expects(:svn).with('--non-interactive', '--trust-server-cert', 'checkout', + resource.value(:source), + resource.value(:path)) + provider.create + end + end end describe 'destroying' do -- cgit v1.2.3 From bf0f40ae4efa9095ca9a877acefdb781e1fbf1cd Mon Sep 17 00:00:00 2001 From: Hunter Haugen Date: Thu, 15 Oct 2015 10:42:01 -0700 Subject: Fix :false to be default value false is not a valid value; only :false is. --- spec/unit/puppet/provider/vcsrepo/svn_spec.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'spec/unit/puppet') diff --git a/spec/unit/puppet/provider/vcsrepo/svn_spec.rb b/spec/unit/puppet/provider/vcsrepo/svn_spec.rb index 25951bd..6a37c20 100644 --- a/spec/unit/puppet/provider/vcsrepo/svn_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/svn_spec.rb @@ -65,9 +65,17 @@ describe Puppet::Type.type(:vcsrepo).provider(:svn) do end context "with trust_server_cert" do + it "should execute 'svn checkout' without a trust-server-cert" do + resource[:source] = 'exists' + resource[:trust_server_cert] = :false + provider.expects(:svn).with('--non-interactive', 'checkout', + resource.value(:source), + resource.value(:path)) + provider.create + end it "should execute 'svn checkout' with a trust-server-cert" do resource[:source] = 'exists' - resource[:trust_server_cert] = true + resource[:trust_server_cert] = :true provider.expects(:svn).with('--non-interactive', '--trust-server-cert', 'checkout', resource.value(:source), resource.value(:path)) -- cgit v1.2.3 From b8f25cea95317a4b2a622e2799f1aa7ba159bdca Mon Sep 17 00:00:00 2001 From: "Strech (Sergey Fedorov)" Date: Tue, 22 Dec 2015 23:02:26 +0100 Subject: Add mirror option for git cloning Example: vcsrepo { '/path/to/repo': ensure => mirror, provider => git, source => 'git://example.com/repo.git', } --- spec/unit/puppet/provider/vcsrepo/git_spec.rb | 28 ++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'spec/unit/puppet') diff --git a/spec/unit/puppet/provider/vcsrepo/git_spec.rb b/spec/unit/puppet/provider/vcsrepo/git_spec.rb index 87113fa..6a8f58f 100644 --- a/spec/unit/puppet/provider/vcsrepo/git_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/git_spec.rb @@ -10,7 +10,7 @@ end remote/origin/foo branches - end + end let(:resource) { Puppet::Type.type(:vcsrepo).new({ :name => 'test', :ensure => :present, @@ -111,6 +111,24 @@ branches end end + context "with an ensure of mirror" do + context "with revision" do + it "should raise an error" do + resource[:ensure] = :mirror + expect { provider.create }.to raise_error Puppet::Error, /cannot set a revision.+bare/i + end + end + context "without revision" do + it "should just execute 'git clone --mirror'" do + resource[:ensure] = :mirror + resource.delete(:revision) + provider.expects(:git).with('clone', '--mirror', resource.value(:source), resource.value(:path)) + provider.expects(:update_remotes) + provider.create + end + end + end + context "when a source is not given" do context "when the path does not exist" do it "should execute 'git init'" do @@ -157,6 +175,14 @@ branches provider.expects(:git).with('init', '--bare') provider.create end + + it "should raise an exeption" do + resource[:ensure] = :mirror + resource.delete(:source) + resource.delete(:revision) + + expect { provider.create }.to raise_error Puppet::Error, /cannot init repository with mirror.+try bare/i + end end context "when the path is a working copy repository" do -- cgit v1.2.3