[PATCH/puppet 1/1] Fix #2671, preferred_serialization_format does not complain about invalid values

16 views
Skip to first unread message

Bruce Williams

unread,
Nov 5, 2009, 9:11:56 PM11/5/09
to puppe...@googlegroups.com
This modifies `supported_formats` to warn when the
`preferred_serialization_format` setting is invalid (and ignored in
favor of the default value).

I built the tests for this behavior alongside the existing
FormatHandler tests for *valid* `preferred_serialization_format` values
(and did some restructuring to extract common setup code to `before`
blocks).

Signed-off-by: Bruce Williams <br...@codefluency.com>
---
lib/puppet/network/format_handler.rb | 2 +
spec/unit/network/format_handler.rb | 36 ++++++++++++++++++++++++++-------
2 files changed, 30 insertions(+), 8 deletions(-)

diff --git a/lib/puppet/network/format_handler.rb b/lib/puppet/network/format_handler.rb
index 2ffbcef..e508a02 100644
--- a/lib/puppet/network/format_handler.rb
+++ b/lib/puppet/network/format_handler.rb
@@ -129,6 +129,8 @@ module Puppet::Network::FormatHandler
if list.include?(preferred_format)
list.delete(preferred_format)
list.unshift(preferred_format)
+ else
+ Puppet.warning "Value of 'preferred_serialization_format' ('#{preferred_format}') is invalid, using default ('#{list.first}')"
end
list
end
diff --git a/spec/unit/network/format_handler.rb b/spec/unit/network/format_handler.rb
index 8a79a58..110effe 100755
--- a/spec/unit/network/format_handler.rb
+++ b/spec/unit/network/format_handler.rb
@@ -49,15 +49,35 @@ describe Puppet::Network::FormatHandler do
FormatTester.supported_formats.should == [:four, :two, :three, :one]
end

- it "should always put the preferred serialization format first if it is supported" do
- one = stub 'supported', :supported? => true, :name => :one, :weight => 1
- two = stub 'supported', :supported? => true, :name => :two, :weight => 6

- Puppet.settings.expects(:value).with(:preferred_serialization_format).returns :one
- Puppet::Network::FormatHandler.stubs(:formats).returns [:one, :two]
- Puppet::Network::FormatHandler.stubs(:format).with(:one).returns one
- Puppet::Network::FormatHandler.stubs(:format).with(:two).returns two
- FormatTester.supported_formats.should == [:one, :two]
+ describe "with a preferred serialization format setting" do
+ before do
+ one = stub 'supported', :supported? => true, :name => :one, :weight => 1
+ two = stub 'supported', :supported? => true, :name => :two, :weight => 6
+ Puppet::Network::FormatHandler.stubs(:formats).returns [:one, :two]
+ Puppet::Network::FormatHandler.stubs(:format).with(:one).returns one
+ Puppet::Network::FormatHandler.stubs(:format).with(:two).returns two
+ end
+ describe "that is supported" do
+ before do
+ Puppet.settings.expects(:value).with(:preferred_serialization_format).returns :one
+ end
+ it "should return the preferred serialization format first" do
+ FormatTester.supported_formats.should == [:one, :two]
+ end
+ end
+ describe "that is not supported" do
+ before do
+ Puppet.settings.expects(:value).with(:preferred_serialization_format).returns :unsupported
+ end
+ it "should still return the default format first" do
+ FormatTester.supported_formats.should == [:two, :one]
+ end
+ it "should log a warning" do
+ Puppet.expects(:warning)
+ FormatTester.supported_formats
+ end
+ end
end

it "should return the first format as the default format" do
--
1.6.0.4

Markus Roberts

unread,
Nov 6, 2009, 1:19:32 AM11/6/09
to puppe...@googlegroups.com
+1

Luke Kanies

unread,
Nov 6, 2009, 8:37:54 PM11/6/09
to puppe...@googlegroups.com
+1
--
Ninety-eight percent of the adults in this country are decent,
hard-working, honest Americans. It's the other lousy two percent that
get all the publicity. But then--we elected them. --Lily Tomlin
---------------------------------------------------------------------
Luke Kanies | http://reductivelabs.com | http://madstop.com

Reply all
Reply to author
Forward
0 new messages