diff options
author | Hunter Haugen <hunter@puppetlabs.com> | 2014-06-27 10:11:47 -0700 |
---|---|---|
committer | Hunter Haugen <hunter@puppetlabs.com> | 2014-06-27 10:11:47 -0700 |
commit | 8f8f48a20dae55664e0eef34970881373e362ba2 (patch) | |
tree | 095616ae84bedd8009a71ec80ea0bca8817c646d | |
parent | d99b568a6cb195e5933437924d32e553bd102548 (diff) | |
parent | 818f5298b6be3b1a25e997ba84eae237d9051be9 (diff) |
Merge pull request #176 from hunner/patch_noop
Update noop to work
-rw-r--r-- | lib/puppet/type/vcsrepo.rb | 14 | ||||
-rw-r--r-- | spec/acceptance/clone_repo_spec.rb | 40 | ||||
-rw-r--r-- | spec/unit/puppet/provider/vcsrepo/git_spec.rb | 22 |
3 files changed, 54 insertions, 22 deletions
diff --git a/lib/puppet/type/vcsrepo.rb b/lib/puppet/type/vcsrepo.rb index 0e4450b..42767ab 100644 --- a/lib/puppet/type/vcsrepo.rb +++ b/lib/puppet/type/vcsrepo.rb @@ -98,9 +98,8 @@ Puppet::Type.newtype(:vcsrepo) do if prov if prov.working_copy_exists? if @resource.value(:force) - if noop? - notice "Noop Mode - Would have deleted repository" - notice "Noop Mode - Would have created repository from latest" + if noop + notice "Noop Mode - Would have deleted repository and re-created from latest" else notice "Deleting current repository before recloning" prov.destroy @@ -212,13 +211,4 @@ Puppet::Type.newtype(:vcsrepo) do autorequire(:package) do ['git', 'git-core'] end - - def noop? - if defined?(@noop) - @noop - else - Puppet[:noop] - end - end - end diff --git a/spec/acceptance/clone_repo_spec.rb b/spec/acceptance/clone_repo_spec.rb index a989661..23b0b31 100644 --- a/spec/acceptance/clone_repo_spec.rb +++ b/spec/acceptance/clone_repo_spec.rb @@ -318,6 +318,36 @@ describe 'clones a remote repo' do describe file("#{tmpdir}/testrepo_force/.git") do it { should be_directory } end + + context 'and noop' do + let(:repo_name) do + 'testrepo_already_exists' + end + before(:all) do + shell("mkdir #{tmpdir}/#{repo_name}") + shell("cd #{tmpdir}/#{repo_name} && git init") + shell("cd #{tmpdir}/#{repo_name} && touch a && git add a && git commit -m 'a'") + end + after(:all) do + shell("rm -rf #{tmpdir}/#{repo_name}") + end + + it 'applies the manifest' do + pp = <<-EOS + vcsrepo { "#{tmpdir}/#{repo_name}": + ensure => present, + source => "file://#{tmpdir}/testrepo.git", + provider => git, + force => true, + noop => true, + } + EOS + + apply_manifest_on(host, pp, :catch_changes => true) do |r| + expect(r.stdout).to match(/Noop Mode/) + end + end + end end context 'as a user' do @@ -474,15 +504,5 @@ describe 'clones a remote repo' do apply_manifest(pp, :catch_failures => true) apply_manifest(pp, :catch_changes => true) end - - after(:all) do - pp = <<-EOS - user { 'testuser-ssh': - ensure => absent, - managehome => true, - } - EOS - apply_manifest(pp, :catch_failures => true) - end end end 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 |