diff options
author | Daniel Pittman <daniel@puppetlabs.com> | 2011-03-21 14:31:18 -0700 |
---|---|---|
committer | Daniel Pittman <daniel@puppetlabs.com> | 2011-03-21 15:39:25 -0700 |
commit | 072becf6b51cb359d18b30d7eb01391f641dd840 (patch) | |
tree | 96a76e3df09413b2e7b7a442460aa71007c3946b /spec/unit/interface_spec.rb | |
parent | 9f379b641c05d7e25b4ae92ee449ca66512eff90 (diff) | |
download | puppet-072becf6b51cb359d18b30d7eb01391f641dd840.tar.gz puppet-072becf6b51cb359d18b30d7eb01391f641dd840.tar.xz puppet-072becf6b51cb359d18b30d7eb01391f641dd840.zip |
(#6806) Improve error checking and reporting for interface naming.
We didn't do enough input checking and sanitization, and missed some
edge-cases for naming interfaces. This adds testing, and cleans up some edge
cases to handle things better.
Reviewed-By: Pieter van de Bruggen <pieter@puppetlabs.com>
Diffstat (limited to 'spec/unit/interface_spec.rb')
-rwxr-xr-x[-rw-r--r--] | spec/unit/interface_spec.rb | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/spec/unit/interface_spec.rb b/spec/unit/interface_spec.rb index 4b6fd117f..cfa0111f6 100644..100755 --- a/spec/unit/interface_spec.rb +++ b/spec/unit/interface_spec.rb @@ -92,4 +92,31 @@ describe Puppet::Interface do end it "should be able to load all actions in all search paths" + + describe "#constantize" do + faulty = [1, "#foo", "$bar", "sturm und drang", :"sturm und drang"] + valid = { + "foo" => "Foo", + :foo => "Foo", + "foo_bar" => "FooBar", + :foo_bar => "FooBar", + "foo-bar" => "FooBar", + :"foo-bar" => "FooBar", + } + + valid.each do |input, expect| + it "should map '#{input}' to '#{expect}'" do + result = Puppet::Interface.constantize(input) + result.should be_a String + result.to_s.should == expect + end + end + + faulty.each do |input| + it "should fail when presented with #{input.inspect} (#{input.class})" do + expect { Puppet::Interface.constantize(input) }. + should raise_error ArgumentError, /not a valid interface name/ + end + end + end end |