This was refactored based on Luke's feedback and a conversation in IRC about tests/code being committed together.
On Thu, Jan 15, 2009 at 11:48 AM, Paul Lathrop <[email protected]> wrote: > > Adds an rspec test which demonstrates #1560 and a custom 'process' > method for the aliases provider to fix it. > > The default processing uses split() to break the line into records on > the separator, which breaks if records can contain the separator. The > custom method I've added uses a 'limited' split() to break the line on > the first separator only. > > This commit fixes #1560 > > Signed-off-by: Paul Lathrop <[email protected]> > --- > lib/puppet/provider/mailalias/aliases.rb | 8 ++++++ > spec/integration/provider/mailalias/aliases.rb | 25 +++++++++++++++++++++ > test/data/providers/mailalias/aliases/test1 | 28 > ++++++++++++++++++++++++ > 3 files changed, 61 insertions(+), 0 deletions(-) > create mode 100755 spec/integration/provider/mailalias/aliases.rb > create mode 100644 test/data/providers/mailalias/aliases/test1 > > diff --git a/lib/puppet/provider/mailalias/aliases.rb > b/lib/puppet/provider/mailalias/aliases.rb > index 8b5c456..f921712 100755 > --- a/lib/puppet/provider/mailalias/aliases.rb > +++ b/lib/puppet/provider/mailalias/aliases.rb > @@ -17,6 +17,14 @@ Puppet::Type.type(:mailalias).provide(:aliases, > record > end > > + def process(line) > + ret = {} > + records = line.split(':',2) > + ret[:name] = records[0].strip() > + ret[:recipient] = records[1].strip() > + ret > + end > + > def to_line(record) > dest = record[:recipient].collect do |d| > # Quote aliases that have non-alpha chars > diff --git a/spec/integration/provider/mailalias/aliases.rb > b/spec/integration/provider/mailalias/aliases.rb > new file mode 100755 > index 0000000..3f28239 > --- /dev/null > +++ b/spec/integration/provider/mailalias/aliases.rb > @@ -0,0 +1,25 @@ > +#!/usr/bin/env ruby > + > +require File.dirname(__FILE__) + '/../../../spec_helper' > + > +require 'puppettest' > +require 'puppettest/support/utils' > +require 'puppettest/fileparsing' > + > +provider_class = Puppet::Type.type(:mailalias).provider(:aliases) > + > +describe provider_class do > + include PuppetTest > + include PuppetTest::FileParsing > + > + before :each do > + @provider = provider_class > + end > + > + # #1560 > + it "should be able to parse each example" do > + fakedata("data/providers/mailalias/aliases").each { |file| > + fakedataparse(file) > + } > + end > +end > diff --git a/test/data/providers/mailalias/aliases/test1 > b/test/data/providers/mailalias/aliases/test1 > new file mode 100644 > index 0000000..20f9098 > --- /dev/null > +++ b/test/data/providers/mailalias/aliases/test1 > @@ -0,0 +1,28 @@ > +# Basic system aliases -- these MUST be present > +MAILER-DAEMON: postmaster > +postmaster: root > + > +# General redirections for pseudo accounts > +bin: root > +daemon: root > +named: root > +nobody: root > +uucp: root > +www: root > +ftp-bugs: root > +postfix: root > + > +# Put your local aliases here. > + > +# Well-known aliases > +manager: root > +dumper: root > +operator: root > +abuse: postmaster > + > +# trap decode to catch security attacks > +decode: root > + > +# Other tests > +anothertest: "|/path/to/rt-mailgate --queue 'another test' --action > correspond --url http://my.com/" > +test: "|/path/to/rt-mailgate --queue 'test' --action correspond --url > http://my.com/" > -- > 1.6.1 > > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en -~----------~----~----~----~------~----~------~--~---
