diff options
author | Stefan Schulte <stefan.schulte@taunusstein.net> | 2010-11-17 23:28:56 +0100 |
---|---|---|
committer | Nick Lewis <nick@puppetlabs.com> | 2010-11-17 15:55:49 -0800 |
commit | 2052f3611fd18cb93a43f4cfb547c9c9205a8952 (patch) | |
tree | 9705db2303d78da5f79c460178788ed57e02afd6 | |
parent | ee7d2f92f9d3ec45b5c3a9cd3fe2f5832b17f23b (diff) | |
download | puppet-2052f3611fd18cb93a43f4cfb547c9c9205a8952.tar.gz puppet-2052f3611fd18cb93a43f4cfb547c9c9205a8952.tar.xz puppet-2052f3611fd18cb93a43f4cfb547c9c9205a8952.zip |
(#5274) New tests for new hosttype/parsedprovider
Just a few additional tests for the new property "comment" of the
host type.
-rw-r--r--[-rwxr-xr-x] | spec/unit/provider/host/parsed_spec.rb | 44 | ||||
-rwxr-xr-x | spec/unit/type/host_spec.rb | 4 | ||||
-rw-r--r-- | test/data/providers/host/parsed/valid_hosts | 5 |
3 files changed, 50 insertions, 3 deletions
diff --git a/spec/unit/provider/host/parsed_spec.rb b/spec/unit/provider/host/parsed_spec.rb index 08254e608..239e3bd86 100755..100644 --- a/spec/unit/provider/host/parsed_spec.rb +++ b/spec/unit/provider/host/parsed_spec.rb @@ -59,6 +59,10 @@ describe provider_class do @provider.parse_line("::1 localhost")[:name].should == "localhost" end + it "should set an empty comment" do + @provider.parse_line("::1 localhost")[:comment].should == "" + end + end describe "when parsing a line with ip, hostname and comment" do @@ -74,6 +78,10 @@ describe provider_class do @provider.parse_line(@testline)[:name].should == "localhost" end + it "should parse the comment after the first '#' character" do + @provider.parse_line(@testline)[:comment].should == 'A comment with a #-char' + end + end describe "when parsing a line with ip, hostname and aliases" do @@ -109,6 +117,10 @@ describe provider_class do @provider.parse_line(@testline)[:host_aliases].should == ['alias1' ,'alias2', 'alias3'] end + it "should parse the comment after the first '#' character" do + @provider.parse_line(@testline)[:comment].should == 'A comment with a #-char' + end + end describe "when operating on /etc/hosts like files" do @@ -147,6 +159,38 @@ describe provider_class do genhost(host).should == "192.0.0.1\thost\ta1\ta2\ta3\ta4\n" end + it "should be able to generate a simple hostfile entry with comments" do + host = mkhost( + :name => 'localhost', + :ip => '127.0.0.1', + :comment => 'Bazinga!', + :ensure => :present + ) + genhost(host).should == "127.0.0.1\tlocalhost\t# Bazinga!\n" + end + + it "should be able to generate an entry with one alias and a comment" do + host = mkhost( + :name => 'localhost.localdomain', + :ip => '127.0.0.1', + :host_aliases => ['localhost'], + :comment => 'Bazinga!', + :ensure => :present + ) + genhost(host).should == "127.0.0.1\tlocalhost.localdomain\tlocalhost\t# Bazinga!\n" + end + + it "should be able to generate an entry with more than one alias and a comment" do + host = mkhost( + :name => 'host', + :ip => '192.0.0.1', + :host_aliases => [ 'a1','a2','a3','a4' ], + :comment => 'Bazinga!', + :ensure => :present + ) + genhost(host).should == "192.0.0.1\thost\ta1\ta2\ta3\ta4\t# Bazinga!\n" + end + end end diff --git a/spec/unit/type/host_spec.rb b/spec/unit/type/host_spec.rb index 43846b236..12ae2af08 100755 --- a/spec/unit/type/host_spec.rb +++ b/spec/unit/type/host_spec.rb @@ -21,7 +21,7 @@ describe Puppet::Type.type(:host) do end end - [:ip, :target, :host_aliases, :ensure].each do |property| + [:ip, :target, :host_aliases, :comment, :ensure].each do |property| it "should have a #{property} property" do @class.attrtype(property).should == :property end @@ -61,7 +61,6 @@ describe Puppet::Type.type(:host) do end it "should not accept malformed IPv4 addresses like 192.168.0.300" do - pending proc { @class.new(:name => "foo", :ip => '192.168.0.300') }.should raise_error end @@ -78,7 +77,6 @@ describe Puppet::Type.type(:host) do end it "should not accept empty host_aliases" do - pending proc { @class.new(:name => "foo", :host_aliases => ['alias1','']) }.should raise_error end end diff --git a/test/data/providers/host/parsed/valid_hosts b/test/data/providers/host/parsed/valid_hosts index de5caf740..24636295d 100644 --- a/test/data/providers/host/parsed/valid_hosts +++ b/test/data/providers/host/parsed/valid_hosts @@ -12,3 +12,8 @@ # Ok its time to test aliases 2001:252:0:1::2008:8 ipv6host alias1 192.168.0.1 ipv4host alias2 alias3 + +# Testing inlinecomments now +192.168.0.2 host3 # This is host3 +192.168.0.3 host4 alias10 # This is host4 +192.168.0.4 host5 alias11 alias12 # This is host5 |