(#5274) New tests for new hosttype/parsedprovider
Just a few additional tests for the new property "comment" of the host type.
This commit is contained in:
Родитель
ee7d2f92f9
Коммит
2052f3611f
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Загрузка…
Ссылка в новой задаче