diff options
author | varac <varacanero@zeromail.org> | 2016-09-28 11:59:41 +0200 |
---|---|---|
committer | varac <varacanero@zeromail.org> | 2016-09-28 11:59:41 +0200 |
commit | 2558e45a5fe0ff6990eb5b722e1ba867014a9788 (patch) | |
tree | 2b2264a1eb20a9df1f4f3b02c83a970f5911fcef /spec/unit/puppet | |
parent | 4e23209eaccf1ab504d35158f4141b3053327c2f (diff) | |
parent | cd6c3bc87e59bd51191c08515a7807071b3bb7a3 (diff) |
Diffstat (limited to 'spec/unit/puppet')
-rw-r--r-- | spec/unit/puppet/provider/vcsrepo/cvs_spec.rb | 12 | ||||
-rwxr-xr-x | spec/unit/puppet/type/vcsrepo_spec.rb | 116 |
2 files changed, 122 insertions, 6 deletions
diff --git a/spec/unit/puppet/provider/vcsrepo/cvs_spec.rb b/spec/unit/puppet/provider/vcsrepo/cvs_spec.rb index 2e18149..d7edd1d 100644 --- a/spec/unit/puppet/provider/vcsrepo/cvs_spec.rb +++ b/spec/unit/puppet/provider/vcsrepo/cvs_spec.rb @@ -23,7 +23,7 @@ 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') - Puppet::Util::Execution.expects(:execute).with([:cvs, '-d', resource.value(:source), 'checkout', '-r', 'an-unimportant-value', '-d', 'test', 'bar'], :custom_environment => {}) + Puppet::Util::Execution.expects(:execute).with([:cvs, '-d', resource.value(:source), 'checkout', '-r', 'an-unimportant-value', '-d', 'test', 'bar'], :custom_environment => {}, :combine => true) provider.create end @@ -32,14 +32,14 @@ describe Puppet::Type.type(:vcsrepo).provider(:cvs_provider) do 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 => {}) + Puppet::Util::Execution.expects(:execute).with([:cvs, '-d', resource.value(:source), 'checkout', '-r', 'an-unimportant-value', '-d', 'test', 'bar'], :uid => 'muppet', :custom_environment => {}, :combine => true) provider.create end it "should just execute 'cvs checkout' without a revision" do resource[:source] = ':ext:source@example.com:/foo/bar' resource.delete(:revision) - 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 => {}) + 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 => {}, :combine => true) provider.create end @@ -48,7 +48,7 @@ describe Puppet::Type.type(:vcsrepo).provider(:cvs_provider) do resource[:source] = ':ext:source@example.com:/foo/bar' resource[:compression] = '3' resource.delete(:revision) - 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 => {}) + 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 => {}, :combine => true) provider.create end end @@ -57,7 +57,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) - Puppet::Util::Execution.expects(:execute).with([:cvs, '-d', resource.value(:path), 'init'], :custom_environment => {}) + Puppet::Util::Execution.expects(:execute).with([:cvs, '-d', resource.value(:path), 'init'], :custom_environment => {}, :combine => true) provider.create end end @@ -116,7 +116,7 @@ describe Puppet::Type.type(:vcsrepo).provider(:cvs_provider) do it "should use 'cvs update -dr'" do expects_chdir - Puppet::Util::Execution.expects(:execute).with([:cvs, 'update', '-dr', @tag, '.'], :custom_environment => {}) + Puppet::Util::Execution.expects(:execute).with([:cvs, 'update', '-dr', @tag, '.'], :custom_environment => {}, :combine => true) provider.revision = @tag end end diff --git a/spec/unit/puppet/type/vcsrepo_spec.rb b/spec/unit/puppet/type/vcsrepo_spec.rb new file mode 100755 index 0000000..0070f49 --- /dev/null +++ b/spec/unit/puppet/type/vcsrepo_spec.rb @@ -0,0 +1,116 @@ +#! /usr/bin/env ruby +require 'spec_helper' + +describe Puppet::Type.type(:vcsrepo) do + + before :each do + Puppet::Type.type(:vcsrepo).stubs(:defaultprovider).returns(providerclass) + end + + let(:providerclass) do + described_class.provide(:fake_vcsrepo_provider) do + attr_accessor :property_hash + def create; end + def destroy; end + def exists? + get(:ensure) != :absent + end + mk_resource_methods + end + end + + let(:provider) do + providerclass.new(:name => 'fake-vcs') + end + + let(:resource) do + described_class.new(:name => '/repo', + :ensure => :present, + :provider => provider) + end + + let(:ensureprop) do + resource.property(:ensure) + end + + properties = [ :ensure ] + + properties.each do |property| + it "should have a #{property} property" do + expect(described_class.attrclass(property).ancestors).to be_include(Puppet::Property) + end + end + + parameters = [ :ensure ] + + parameters.each do |parameter| + it "should have a #{parameter} parameter" do + expect(described_class.attrclass(parameter).ancestors).to be_include(Puppet::Parameter) + end + end + + describe 'default resource with required params' do + it 'should have a valid name parameter' do + expect(resource[:name]).to eq('/repo') + end + + it 'should have ensure set to present' do + expect(resource[:ensure]).to eq(:present) + end + + it 'should have path set to /repo' do + expect(resource[:path]).to eq('/repo') + end + + defaults = { + :owner => nil, + :group => nil, + :user => nil, + :revision => nil, + } + + defaults.each_pair do |param, value| + it "should have #{param} parameter set to #{value}" do + expect(resource[param]).to eq(value) + end + end + end + + describe 'when changing the ensure' do + it 'should be in sync if it is :absent and should be :absent' do + ensureprop.should = :absent + expect(ensureprop.safe_insync?(:absent)).to eq(true) + end + + it 'should be in sync if it is :present and should be :present' do + ensureprop.should = :present + expect(ensureprop.safe_insync?(:present)).to eq(true) + end + + it 'should be out of sync if it is :absent and should be :present' do + ensureprop.should = :present + expect(ensureprop.safe_insync?(:absent)).not_to eq(true) + end + + it 'should be out of sync if it is :present and should be :absent' do + ensureprop.should = :absent + expect(ensureprop.safe_insync?(:present)).not_to eq(true) + end + end + + describe 'when running the type it should autorequire packages' do + before :each do + @catalog = Puppet::Resource::Catalog.new + ['git', 'git-core', 'mercurial'].each do |pkg| + @catalog.add_resource(Puppet::Type.type(:package).new(:name => pkg)) + end + end + + it 'should require package packages' do + @resource = described_class.new(:name => '/foo', :provider => provider) + @catalog.add_resource(@resource) + req = @resource.autorequire + expect(req.size).to eq(3) + end + end +end |