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/provider/vcsrepo/git_spec.rb') 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/git_spec.rb | 336 ++++++++++++++------------ 1 file changed, 182 insertions(+), 154 deletions(-) (limited to 'spec/unit/puppet/provider/vcsrepo/git_spec.rb') 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 -- 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/provider/vcsrepo/git_spec.rb') 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/provider/vcsrepo/git_spec.rb') 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/provider/vcsrepo/git_spec.rb') 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/provider/vcsrepo/git_spec.rb') 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/provider/vcsrepo/git_spec.rb') 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/provider/vcsrepo/git_spec.rb') 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/provider/vcsrepo/git_spec.rb') 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/provider/vcsrepo/git_spec.rb') 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/provider/vcsrepo/git_spec.rb') 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/provider/vcsrepo/git_spec.rb') 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/provider/vcsrepo/git_spec.rb') 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/provider/vcsrepo/git_spec.rb') 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/provider/vcsrepo/git_spec.rb') 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/provider/vcsrepo/git_spec.rb') 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 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/provider/vcsrepo/git_spec.rb') 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 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/provider/vcsrepo/git_spec.rb') 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: 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/git_spec.rb | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'spec/unit/puppet/provider/vcsrepo/git_spec.rb') 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 -- 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/provider/vcsrepo/git_spec.rb') 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/provider/vcsrepo/git_spec.rb') 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/provider/vcsrepo/git_spec.rb') 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 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/provider/vcsrepo/git_spec.rb') 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/provider/vcsrepo/git_spec.rb') 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/provider/vcsrepo/git_spec.rb') 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 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/provider/vcsrepo/git_spec.rb') 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