diff options
| author | Jesse Wolfe <jes5199@gmail.com> | 2009-11-17 15:58:20 -0800 |
|---|---|---|
| committer | James Turnbull <james@lovedthanlost.net> | 2009-11-20 07:34:55 +1100 |
| commit | be7ff82f92a14f4f572d738eeeb2c77437069c49 (patch) | |
| tree | e45f0a28b61ddeeb5369b5786f82f48dc3e2f1e6 | |
| parent | 48beabadb6f234e6486cf32eebc389e8faba13f0 (diff) | |
| download | puppet-be7ff82f92a14f4f572d738eeeb2c77437069c49.tar.gz puppet-be7ff82f92a14f4f572d738eeeb2c77437069c49.tar.xz puppet-be7ff82f92a14f4f572d738eeeb2c77437069c49.zip | |
Fix 2768 maillist resource is broken
Replace deprecated method call. This code was not tested before, so I've
tried to capture what I think the method was trying to do.
This version includes Luke's suggested change to better preserve the
original behavior.
Signed-off-by: Jesse Wolfe <jes5199@gmail.com>
| -rwxr-xr-x | lib/puppet/type/maillist.rb | 11 | ||||
| -rwxr-xr-x | spec/unit/type/maillist.rb | 42 |
2 files changed, 46 insertions, 7 deletions
diff --git a/lib/puppet/type/maillist.rb b/lib/puppet/type/maillist.rb index e2430aa13..4ab9be252 100755 --- a/lib/puppet/type/maillist.rb +++ b/lib/puppet/type/maillist.rb @@ -42,13 +42,10 @@ module Puppet should = :absent end atype = Puppet::Type.type(:mailalias) - return provider.aliases.collect do |name, recipient| - if atype[name] - nil - else - malias = Puppet::Type.type(:mailalias).new(:name => name, :recipient => recipient, :ensure => should) - end - end.compact + + provider.aliases. + reject { |name,recipient| catalog.resource(:mailalias, name) }. + collect { |name,recipient| atype.new(:name => name, :recipient => recipient, :ensure => should) } end end end diff --git a/spec/unit/type/maillist.rb b/spec/unit/type/maillist.rb new file mode 100755 index 000000000..585336665 --- /dev/null +++ b/spec/unit/type/maillist.rb @@ -0,0 +1,42 @@ +#!/usr/bin/env ruby + +Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f) : Dir.chdir("..") { s.call(f) } }).call("spec/spec_helper.rb") } + +maillist = Puppet::Type.type(:maillist) + +describe maillist do + before do + @provider_class = Puppet::Type.type(:maillist).provider(:mailman) + + @provider = stub 'provider', :class => @provider_class, :clear => nil + @provider.stubs(:respond_to).with(:aliases).returns(true) + + @provider_class.stubs(:new).returns(@provider) + + Puppet::Type.type(:maillist).stubs(:defaultprovider).returns(@provider_class) + + @maillist = Puppet::Type.type(:maillist).new( :name => 'test' ) + + @catalog = Puppet::Resource::Catalog.new + @maillist.catalog = @catalog + end + + it "should generate aliases unless they already exist" do + # Mail List aliases are careful not to stomp on managed Mail Alias aliases + + # test1 is an unmanaged alias from /etc/aliases + Puppet::Type.type(:mailalias).provider(:aliases).stubs(:target_object).returns( StringIO.new("test1: root\n") ) + + # test2 is a managed alias from the manifest + dupe = Puppet::Type.type(:mailalias).new( :name => 'test2' ) + @catalog.add_resource dupe + + @provider.stubs(:aliases).returns({"test1" => 'this will get included', "test2" => 'this will dropped', "test3" => 'this will get included'}) + + generated = @maillist.generate + generated.map{ |x| x.name }.sort.should == ['test1', 'test3'] + generated.map{ |x| x.class }.should == [Puppet::Type::Mailalias, Puppet::Type::Mailalias] + + end + +end |
