aboutsummaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorJosh Cooper <josh@puppet.com>2018-07-09 19:50:03 -0700
committerJosh Cooper <josh@puppet.com>2018-07-09 19:50:03 -0700
commit59f4a9e49d397556a60f060faffdc14b734856da (patch)
tree8b630a7d02fc4e6e207fc3d84b9d78c1f6637191 /spec
parent34e83e11a5fc344195217d9cd159d022b5d89ec1 (diff)
downloadpuppet-hosts_core-59f4a9e49d397556a60f060faffdc14b734856da.tar.gz
puppet-hosts_core-59f4a9e49d397556a60f060faffdc14b734856da.tar.bz2
Automatic validation updates
Updated rubocop violations using `pdk validate -a`.
Diffstat (limited to 'spec')
-rw-r--r--spec/acceptance/tests/pup_2289_should_not_destroy_data_when_malformed.rb21
-rw-r--r--spec/acceptance/tests/should_create.rb18
-rw-r--r--spec/acceptance/tests/should_create_aliases.rb22
-rw-r--r--spec/acceptance/tests/should_destroy.rb20
-rw-r--r--spec/acceptance/tests/should_modify_alias.rb20
-rw-r--r--spec/acceptance/tests/should_modify_ip.rb20
-rw-r--r--spec/acceptance/tests/should_not_create_existing.rb16
-rw-r--r--spec/acceptance/tests/should_query_all.rb24
-rw-r--r--spec/acceptance/tests/ticket_4131_should_not_create_without_ip.rb22
-rw-r--r--spec/lib/puppet_spec/files.rb32
-rw-r--r--spec/shared_behaviours/all_parsedfile_providers.rb8
-rw-r--r--spec/unit/provider/host/parsed_spec.rb183
-rw-r--r--spec/unit/type/host_spec.rb1020
13 files changed, 705 insertions, 721 deletions
diff --git a/spec/acceptance/tests/pup_2289_should_not_destroy_data_when_malformed.rb b/spec/acceptance/tests/pup_2289_should_not_destroy_data_when_malformed.rb
index 670651d..95cf6ed 100644
--- a/spec/acceptance/tests/pup_2289_should_not_destroy_data_when_malformed.rb
+++ b/spec/acceptance/tests/pup_2289_should_not_destroy_data_when_malformed.rb
@@ -1,32 +1,31 @@
-test_name "should not delete data when existing content is malformed"
+test_name 'should not delete data when existing content is malformed'
tag 'audit:low',
'audit:refactor', # Use block style `test_name`
'audit:acceptance' # Could be done at the integration (or unit) layer though
- # actual changing of resources could irreparably damage a
- # host running this, or require special permissions.
+# actual changing of resources could irreparably damage a
+# host running this, or require special permissions.
agents.each do |agent|
file = agent.tmpfile('host-not-delete-data')
teardown do
- on(agent, "rm -f #{file}", :acceptable_exit_codes => (0..255))
+ on(agent, "rm -f #{file}", acceptable_exit_codes: (0..255))
end
- step "(setup) populate test file with host information"
+ step '(setup) populate test file with host information'
on(agent, "printf '127.0.0.2 existing alias\n' > #{file}")
- step "(setup) populate test file with a malformed line"
+ step '(setup) populate test file with a malformed line'
on(agent, "printf '==\n' >> #{file}")
- step "tell puppet to add another host entry"
+ step 'tell puppet to add another host entry'
on(agent, puppet_resource('host', 'test', "target=#{file}",
- 'ensure=present', 'ip=127.0.0.3', 'host_aliases=foo'))
+ 'ensure=present', 'ip=127.0.0.3', 'host_aliases=foo'))
- step "verify that the initial host entry was not deleted"
+ step 'verify that the initial host entry was not deleted'
on(agent, "cat #{file}") do |res|
- fail_test "existing host data was deleted" unless
+ fail_test 'existing host data was deleted' unless
res.stdout.include? 'existing'
end
-
end
diff --git a/spec/acceptance/tests/should_create.rb b/spec/acceptance/tests/should_create.rb
index b590f85..3ce34e8 100644
--- a/spec/acceptance/tests/should_create.rb
+++ b/spec/acceptance/tests/should_create.rb
@@ -1,23 +1,23 @@
-test_name "host should create"
+test_name 'host should create'
tag 'audit:low',
'audit:refactor', # Use block style `test_name`
'audit:acceptance' # Could be done at the integration (or unit) layer though
- # actual changing of resources could irreparably damage a
- # host running this, or require special permissions.
+# actual changing of resources could irreparably damage a
+# host running this, or require special permissions.
agents.each do |agent|
target = agent.tmpfile('host-create')
- step "clean up for the test"
+ step 'clean up for the test'
on agent, "rm -f #{target}"
- step "create the host record"
- on(agent, puppet_resource("host", "test", "ensure=present",
- "ip=127.0.0.1", "target=#{target}"))
+ step 'create the host record'
+ on(agent, puppet_resource('host', 'test', 'ensure=present',
+ 'ip=127.0.0.1', "target=#{target}"))
- step "verify that the record was created"
+ step 'verify that the record was created'
on(agent, "cat #{target} ; rm -f #{target}") do
- fail_test "record was not present" unless stdout =~ /^127\.0\.0\.1[[:space:]]+test/
+ fail_test 'record was not present' unless stdout =~ %r{^127\.0\.0\.1[[:space:]]+test}
end
end
diff --git a/spec/acceptance/tests/should_create_aliases.rb b/spec/acceptance/tests/should_create_aliases.rb
index be4a134..a76263a 100644
--- a/spec/acceptance/tests/should_create_aliases.rb
+++ b/spec/acceptance/tests/should_create_aliases.rb
@@ -1,24 +1,24 @@
-test_name "host should create aliases"
+test_name 'host should create aliases'
tag 'audit:low',
'audit:refactor', # Use block style `test_name`
'audit:acceptance' # Could be done at the integration (or unit) layer though
- # actual changing of resources could irreparably damage a
- # host running this, or require special permissions.
+# actual changing of resources could irreparably damage a
+# host running this, or require special permissions.
agents.each do |agent|
- target = agent.tmpfile('host-create-aliases')
+ target = agent.tmpfile('host-create-aliases')
- step "clean up the system for testing"
+ step 'clean up the system for testing'
on agent, "rm -f #{target}"
- step "create the record"
- on(agent, puppet_resource('host', 'test', "ensure=present",
- "ip=127.0.0.7", "target=#{target}", "host_aliases=alias"))
+ step 'create the record'
+ on(agent, puppet_resource('host', 'test', 'ensure=present',
+ 'ip=127.0.0.7', "target=#{target}", 'host_aliases=alias'))
- step "verify that the aliases were added"
+ step 'verify that the aliases were added'
on(agent, "cat #{target} ; rm -f #{target}") do
- fail_test "alias was missing" unless
- stdout =~ /^127\.0\.0\.7[[:space:]]+test[[:space:]]alias/
+ fail_test 'alias was missing' unless
+ stdout =~ %r{^127\.0\.0\.7[[:space:]]+test[[:space:]]alias}
end
end
diff --git a/spec/acceptance/tests/should_destroy.rb b/spec/acceptance/tests/should_destroy.rb
index 97f1477..f55c24b 100644
--- a/spec/acceptance/tests/should_destroy.rb
+++ b/spec/acceptance/tests/should_destroy.rb
@@ -1,27 +1,27 @@
-test_name "should be able to remove a host record"
+test_name 'should be able to remove a host record'
tag 'audit:low',
'audit:refactor', # Use block style `test_name`
'audit:acceptance' # Could be done at the integration (or unit) layer though
- # actual changing of resources could irreparably damage a
- # host running this, or require special permissions.
+# actual changing of resources could irreparably damage a
+# host running this, or require special permissions.
agents.each do |agent|
file = agent.tmpfile('host-destroy')
- line = "127.0.0.7 test1"
+ line = '127.0.0.7 test1'
- step "set up files for the test"
+ step 'set up files for the test'
on agent, "printf '#{line}\n' > #{file}"
- step "delete the resource from the file"
+ step 'delete the resource from the file'
on(agent, puppet_resource('host', 'test1', "target=#{file}",
- 'ensure=absent', 'ip=127.0.0.7'))
+ 'ensure=absent', 'ip=127.0.0.7'))
- step "verify that the content was removed"
+ step 'verify that the content was removed'
on(agent, "cat #{file}; rm -f #{file}") do
- fail_test "the content was still present" if stdout.include? line
+ fail_test 'the content was still present' if stdout.include? line
end
- step "clean up after the test"
+ step 'clean up after the test'
on agent, "rm -f #{file}"
end
diff --git a/spec/acceptance/tests/should_modify_alias.rb b/spec/acceptance/tests/should_modify_alias.rb
index 07198b1..f2171f0 100644
--- a/spec/acceptance/tests/should_modify_alias.rb
+++ b/spec/acceptance/tests/should_modify_alias.rb
@@ -1,27 +1,27 @@
-test_name "should be able to modify a host alias"
+test_name 'should be able to modify a host alias'
tag 'audit:low',
'audit:refactor', # Use block style `test_name`
'audit:acceptance' # Could be done at the integration (or unit) layer though
- # actual changing of resources could irreparably damage a
- # host running this, or require special permissions.
+# actual changing of resources could irreparably damage a
+# host running this, or require special permissions.
agents.each do |agent|
file = agent.tmpfile('host-modify-alias')
- step "set up files for the test"
+ step 'set up files for the test'
on agent, "printf '127.0.0.8 test alias\n' > #{file}"
- step "modify the resource"
+ step 'modify the resource'
on(agent, puppet_resource('host', 'test', "target=#{file}",
- 'ensure=present', 'ip=127.0.0.8', 'host_aliases=banzai'))
+ 'ensure=present', 'ip=127.0.0.8', 'host_aliases=banzai'))
- step "verify that the content was updated"
+ step 'verify that the content was updated'
on(agent, "cat #{file}; rm -f #{file}") do
- fail_test "the alias was not updated" unless
- stdout =~ /^127\.0\.0\.8[[:space:]]+test[[:space:]]+banzai[[:space:]]*$/
+ fail_test 'the alias was not updated' unless
+ stdout =~ %r{^127\.0\.0\.8[[:space:]]+test[[:space:]]+banzai[[:space:]]*$}
end
- step "clean up after the test"
+ step 'clean up after the test'
on agent, "rm -f #{file}"
end
diff --git a/spec/acceptance/tests/should_modify_ip.rb b/spec/acceptance/tests/should_modify_ip.rb
index 10c5adf..22019b7 100644
--- a/spec/acceptance/tests/should_modify_ip.rb
+++ b/spec/acceptance/tests/should_modify_ip.rb
@@ -1,27 +1,27 @@
-test_name "should be able to modify a host address"
+test_name 'should be able to modify a host address'
tag 'audit:low',
'audit:refactor', # Use block style `test_name`
'audit:acceptance' # Could be done at the integration (or unit) layer though
- # actual changing of resources could irreparably damage a
- # host running this, or require special permissions.
+# actual changing of resources could irreparably damage a
+# host running this, or require special permissions.
agents.each do |agent|
file = agent.tmpfile('host-modify-ip')
- step "set up files for the test"
+ step 'set up files for the test'
on agent, "printf '127.0.0.9 test alias\n' > #{file}"
- step "modify the resource"
+ step 'modify the resource'
on(agent, puppet_resource('host', 'test', "target=#{file}",
- 'ensure=present', 'ip=127.0.0.10', 'host_aliases=alias'))
+ 'ensure=present', 'ip=127.0.0.10', 'host_aliases=alias'))
- step "verify that the content was updated"
+ step 'verify that the content was updated'
on(agent, "cat #{file}; rm -f #{file}") do
- fail_test "the address was not updated" unless
- stdout =~ /^127\.0\.0\.10[[:space:]]+test[[:space:]]+alias[[:space:]]*$/
+ fail_test 'the address was not updated' unless
+ stdout =~ %r{^127\.0\.0\.10[[:space:]]+test[[:space:]]+alias[[:space:]]*$}
end
- step "clean up after the test"
+ step 'clean up after the test'
on agent, "rm -f #{file}"
end
diff --git a/spec/acceptance/tests/should_not_create_existing.rb b/spec/acceptance/tests/should_not_create_existing.rb
index 0cdc87b..31686bc 100644
--- a/spec/acceptance/tests/should_not_create_existing.rb
+++ b/spec/acceptance/tests/should_not_create_existing.rb
@@ -1,24 +1,24 @@
-test_name "should not create host if it exists"
+test_name 'should not create host if it exists'
tag 'audit:low',
'audit:refactor', # Use block style `test_name`
'audit:acceptance' # Could be done at the integration (or unit) layer though
- # actual changing of resources could irreparably damage a
- # host running this, or require special permissions.
+# actual changing of resources could irreparably damage a
+# host running this, or require special permissions.
agents.each do |agent|
file = agent.tmpfile('host-not-create-existing')
- step "set up the system for the test"
+ step 'set up the system for the test'
on agent, "printf '127.0.0.2 test alias\n' > #{file}"
- step "tell puppet to ensure the host exists"
+ step 'tell puppet to ensure the host exists'
on(agent, puppet_resource('host', 'test', "target=#{file}",
- 'ensure=present', 'ip=127.0.0.2', 'host_aliases=alias')) do
- fail_test "darn, we created the host record" if
+ 'ensure=present', 'ip=127.0.0.2', 'host_aliases=alias')) do
+ fail_test 'darn, we created the host record' if
stdout.include? '/Host[test1]/ensure: created'
end
- step "clean up after we created things"
+ step 'clean up after we created things'
on agent, "rm -f #{file}"
end
diff --git a/spec/acceptance/tests/should_query_all.rb b/spec/acceptance/tests/should_query_all.rb
index e60756d..cc92566 100644
--- a/spec/acceptance/tests/should_query_all.rb
+++ b/spec/acceptance/tests/should_query_all.rb
@@ -1,34 +1,34 @@
-test_name "should query all hosts from hosts file"
+test_name 'should query all hosts from hosts file'
tag 'audit:low',
'audit:refactor', # Use block style `test_name`
'audit:acceptance' # Could be done at the integration (or unit) layer though
- # actual changing of resources could irreparably damage a
- # host running this, or require special permissions.
+# actual changing of resources could irreparably damage a
+# host running this, or require special permissions.
-content = %q{127.0.0.1 test1 test1.local
+content = '127.0.0.1 test1 test1.local
127.0.0.2 test2 test2.local
127.0.0.3 test3 test3.local
127.0.0.4 test4 test4.local
-}
+'
agents.each do |agent|
backup = agent.tmpfile('host-query-all')
- step "configure the system for testing (including file backups)"
+ step 'configure the system for testing (including file backups)'
on agent, "cp /etc/hosts #{backup}"
- on agent, "cat > /etc/hosts", :stdin => content
+ on agent, 'cat > /etc/hosts', stdin: content
- step "query all host records using puppet"
+ step 'query all host records using puppet'
on(agent, puppet_resource('host')) do
- found = stdout.scan(/host \{ '([^']+)'/).flatten.sort
+ found = stdout.scan(%r{host \{ '([^']+)'}).flatten.sort
fail_test "the list of returned hosts was wrong: #{found.join(', ')}" unless
- found == %w{test1 test2 test3 test4}
+ found == ['test1', 'test2', 'test3', 'test4']
- count = stdout.scan(/ensure\s+=>\s+'present'/).length
+ count = stdout.scan(%r{ensure\s+=>\s+'present'}).length
fail_test "found #{count} records, wanted 4" unless count == 4
end
- step "clean up the system afterwards"
+ step 'clean up the system afterwards'
on agent, "cat #{backup} > /etc/hosts && rm -f #{backup}"
end
diff --git a/spec/acceptance/tests/ticket_4131_should_not_create_without_ip.rb b/spec/acceptance/tests/ticket_4131_should_not_create_without_ip.rb
index 867ff6c..a26faee 100644
--- a/spec/acceptance/tests/ticket_4131_should_not_create_without_ip.rb
+++ b/spec/acceptance/tests/ticket_4131_should_not_create_without_ip.rb
@@ -1,29 +1,31 @@
-test_name "#4131: should not create host without IP attribute"
+test_name '#4131: should not create host without IP attribute'
tag 'audit:low',
'audit:refactor', # Use block style `test_name`
'audit:acceptance' # Could be done at the integration (or unit) layer though
- # actual changing of resources could irreparably damage a
- # host running this, or require special permissions.
+# actual changing of resources could irreparably damage a
+# host running this, or require special permissions.
agents.each do |agent|
file = agent.tmpfile('4131-require-ip')
- step "configure the target system for the test"
+ step 'configure the target system for the test'
on agent, "rm -rf #{file} ; touch #{file}"
- step "try to create the host, which should fail"
+ step 'try to create the host, which should fail'
# REVISIT: This step should properly need to handle the non-zero exit code,
# and #5668 has been filed to record that. When it is fixed this test will
# start to fail, and this comment will tell you why. --daniel 2010-12-24
on(agent, puppet_resource('host', 'test', "target=#{file}",
- "host_aliases=alias")) do
- fail_test "puppet didn't complain about the missing attribute" unless
- stderr.include? 'ip is a required attribute for hosts' unless agent['locale'] == 'ja'
+ 'host_aliases=alias')) do
+ unless agent['locale'] == 'ja'
+ fail_test "puppet didn't complain about the missing attribute" unless
+ stderr.include? 'ip is a required attribute for hosts'
+ end
end
- step "verify that the host was not added to the file"
+ step 'verify that the host was not added to the file'
on(agent, "cat #{file} ; rm -f #{file}") do
- fail_test "the host was apparently added to the file" if stdout.include? 'test'
+ fail_test 'the host was apparently added to the file' if stdout.include? 'test'
end
end
diff --git a/spec/lib/puppet_spec/files.rb b/spec/lib/puppet_spec/files.rb
index b34daed..ebbe1a9 100644
--- a/spec/lib/puppet_spec/files.rb
+++ b/spec/lib/puppet_spec/files.rb
@@ -7,10 +7,10 @@ require 'pathname'
module PuppetSpec::Files
def self.cleanup
$global_tempfiles ||= []
- while path = $global_tempfiles.pop do
+ while path = $global_tempfiles.pop
begin
Dir.unstub(:entries)
- FileUtils.rm_rf path, :secure => true
+ FileUtils.rm_rf path, secure: true
rescue Errno::ENOENT
# nothing to do
end
@@ -48,7 +48,7 @@ module PuppetSpec::Files
text = contents[:posix]
end
File.open(file, 'wb') { |f| f.write(text) }
- Puppet::FileSystem.chmod(0755, file)
+ Puppet::FileSystem.chmod(0o755, file)
file
end
@@ -62,12 +62,12 @@ module PuppetSpec::Files
# Copied from ruby 2.4 source
def make_tmpname((prefix, suffix), n)
- prefix = (String.try_convert(prefix) or
- raise ArgumentError, "unexpected prefix: #{prefix.inspect}")
- suffix &&= (String.try_convert(suffix) or
- raise ArgumentError, "unexpected suffix: #{suffix.inspect}")
- t = Time.now.strftime("%Y%m%d")
- path = "#{prefix}#{t}-#{$$}-#{rand(0x100000000).to_s(36)}".dup
+ prefix = (String.try_convert(prefix) ||
+ raise(ArgumentError, "unexpected prefix: #{prefix.inspect}"))
+ suffix &&= (String.try_convert(suffix) ||
+ raise(ArgumentError, "unexpected suffix: #{suffix.inspect}"))
+ t = Time.now.strftime('%Y%m%d')
+ path = "#{prefix}#{t}-#{$PROCESS_ID}-#{rand(0x100000000).to_s(36)}".dup
path << "-#{n}" if n
path << suffix if suffix
path
@@ -78,13 +78,13 @@ module PuppetSpec::Files
end
def dir_contained_in(dir, contents_hash)
- contents_hash.each do |k,v|
+ contents_hash.each do |k, v|
if v.is_a?(Hash)
- Dir.mkdir(tmp = File.join(dir,k))
+ Dir.mkdir(tmp = File.join(dir, k))
dir_contained_in(tmp, v)
else
file = File.join(dir, k)
- File.open(file, 'wb') {|f| f.write(v) }
+ File.open(file, 'wb') { |f| f.write(v) }
end
end
dir
@@ -97,11 +97,11 @@ module PuppetSpec::Files
end
def expect_file_mode(file, mode)
- actual_mode = "%o" % Puppet::FileSystem.stat(file).mode
+ actual_mode = '%o' % Puppet::FileSystem.stat(file).mode
target_mode = if Puppet.features.microsoft_windows?
- mode
- else
- "10" + "%04i" % mode.to_i
+ mode
+ else
+ '10' + '%04i' % mode.to_i
end
expect(actual_mode).to eq(target_mode)
end
diff --git a/spec/shared_behaviours/all_parsedfile_providers.rb b/spec/shared_behaviours/all_parsedfile_providers.rb
index 9fdf54b..d697a14 100644
--- a/spec/shared_behaviours/all_parsedfile_providers.rb
+++ b/spec/shared_behaviours/all_parsedfile_providers.rb
@@ -1,5 +1,5 @@
-shared_examples_for "all parsedfile providers" do |provider, *files|
- if files.empty? then
+shared_examples_for 'all parsedfile providers' do |provider, *files|
+ if files.empty?
files = my_fixtures
end
@@ -9,12 +9,12 @@ shared_examples_for "all parsedfile providers" do |provider, *files|
provider.prefetch
text = provider.to_file(provider.target_records(file))
- text.gsub!(/^# HEADER.+\n/, '')
+ text.gsub!(%r{^# HEADER.+\n}, '')
oldlines = File.readlines(file)
newlines = text.chomp.split "\n"
oldlines.zip(newlines).each do |old, new|
- expect(new.gsub(/\s+/, '')).to eq(old.chomp.gsub(/\s+/, ''))
+ expect(new.gsub(%r{\s+}, '')).to eq(old.chomp.gsub(%r{\s+}, ''))
end
end
end
diff --git a/spec/unit/provider/host/parsed_spec.rb b/spec/unit/provider/host/parsed_spec.rb
index b2cba76..961dc7b 100644
--- a/spec/unit/provider/host/parsed_spec.rb
+++ b/spec/unit/provider/host/parsed_spec.rb
@@ -9,7 +9,7 @@ provider_class = Puppet::Type.type(:host).provider(:parsed)
describe provider_class do
include PuppetSpec::Files
- before do
+ before(:each) do
@host_class = Puppet::Type.type(:host)
@provider = @host_class.provider(:parsed)
@hostfile = tmpfile('hosts')
@@ -21,7 +21,7 @@ describe provider_class do
end
def mkhost(args)
- hostresource = Puppet::Type::Host.new(:name => args[:name])
+ hostresource = Puppet::Type::Host.new(name: args[:name])
hostresource.stubs(:should).with(:target).returns @hostfile
# Using setters of provider to build our testobject
@@ -29,8 +29,8 @@ describe provider_class do
# the provider setter "host_aliases=(value)" will be
# called with the joined array, so we just simulate that
host = @provider.new(hostresource)
- args.each do |property,value|
- value = value.join(" ") if property == :host_aliases and value.is_a?(Array)
+ args.each do |property, value|
+ value = value.join(' ') if property == :host_aliases && value.is_a?(Array)
host.send("#{property}=", value)
end
host
@@ -45,189 +45,178 @@ describe provider_class do
@provider.target_object(@hostfile).read
end
- describe "when parsing on incomplete line" do
-
- it "should work for only ip" do
- expect(@provider.parse_line("127.0.0.1")[:line]).to eq("127.0.0.1")
+ describe 'when parsing on incomplete line' do
+ it 'works for only ip' do
+ expect(@provider.parse_line('127.0.0.1')[:line]).to eq('127.0.0.1')
end
- it "should work for only hostname" do
- expect(@provider.parse_line("www.example.com")[:line]).to eq("www.example.com")
+ it 'works for only hostname' do
+ expect(@provider.parse_line('www.example.com')[:line]).to eq('www.example.com')
end
- it "should work for ip and space" do
- expect(@provider.parse_line("127.0.0.1 ")[:line]).to eq("127.0.0.1 ")
+ it 'works for ip and space' do
+ expect(@provider.parse_line('127.0.0.1 ')[:line]).to eq('127.0.0.1 ')
end
- it "should work for hostname and space" do
- expect(@provider.parse_line("www.example.com ")[:line]).to eq("www.example.com ")
+ it 'works for hostname and space' do
+ expect(@provider.parse_line('www.example.com ')[:line]).to eq('www.example.com ')
end
- it "should work for hostname and host_aliases" do
- expect(@provider.parse_line("www.example.com www xyz")[:line]).to eq("www.example.com www xyz")
+ it 'works for hostname and host_aliases' do
+ expect(@provider.parse_line('www.example.com www xyz')[:line]).to eq('www.example.com www xyz')
end
- it "should work for ip and comment" do
- expect(@provider.parse_line("127.0.0.1 #www xyz")[:line]).to eq("127.0.0.1 #www xyz")
+ it 'works for ip and comment' do
+ expect(@provider.parse_line('127.0.0.1 #www xyz')[:line]).to eq('127.0.0.1 #www xyz')
end
- it "should work for hostname and comment" do
- expect(@provider.parse_line("xyz #www test123")[:line]).to eq("xyz #www test123")
+ it 'works for hostname and comment' do
+ expect(@provider.parse_line('xyz #www test123')[:line]).to eq('xyz #www test123')
end
- it "should work for crazy incomplete lines" do
+ it 'works for crazy incomplete lines' do
expect(@provider.parse_line("%th1s is a\t cr$zy !incompl1t line")[:line]).to eq("%th1s is a\t cr$zy !incompl1t line")
end
-
end
- describe "when parsing a line with ip and hostname" do
-
- it "should parse an ipv4 from the first field" do
- expect(@provider.parse_line("127.0.0.1 localhost")[:ip]).to eq("127.0.0.1")
+ describe 'when parsing a line with ip and hostname' do
+ it 'parses an ipv4 from the first field' do
+ expect(@provider.parse_line('127.0.0.1 localhost')[:ip]).to eq('127.0.0.1')
end
- it "should parse an ipv6 from the first field" do
- expect(@provider.parse_line("::1 localhost")[:ip]).to eq("::1")
+ it 'parses an ipv6 from the first field' do
+ expect(@provider.parse_line('::1 localhost')[:ip]).to eq('::1')
end
- it "should parse the name from the second field" do
- expect(@provider.parse_line("::1 localhost")[:name]).to eq("localhost")
+ it 'parses the name from the second field' do
+ expect(@provider.parse_line('::1 localhost')[:name]).to eq('localhost')
end
- it "should set an empty comment" do
- expect(@provider.parse_line("::1 localhost")[:comment]).to eq("")
+ it 'sets an empty comment' do
+ expect(@provider.parse_line('::1 localhost')[:comment]).to eq('')
end
- it "should set host_aliases to :absent" do
- expect(@provider.parse_line("::1 localhost")[:host_aliases]).to eq(:absent)
+ it 'sets host_aliases to :absent' do
+ expect(@provider.parse_line('::1 localhost')[:host_aliases]).to eq(:absent)
end
-
end
- describe "when parsing a line with ip, hostname and comment" do
- before do
- @testline = "127.0.0.1 localhost # A comment with a #-char"
+ describe 'when parsing a line with ip, hostname and comment' do
+ before(:each) do
+ @testline = '127.0.0.1 localhost # A comment with a #-char'
end
- it "should parse the ip from the first field" do
- expect(@provider.parse_line(@testline)[:ip]).to eq("127.0.0.1")
+ it 'parses the ip from the first field' do
+ expect(@provider.parse_line(@testline)[:ip]).to eq('127.0.0.1')
end
- it "should parse the hostname from the second field" do
- expect(@provider.parse_line(@testline)[:name]).to eq("localhost")
+ it 'parses the hostname from the second field' do
+ expect(@provider.parse_line(@testline)[:name]).to eq('localhost')
end
- it "should parse the comment after the first '#' character" do
+ it "parses the comment after the first '#' character" do
expect(@provider.parse_line(@testline)[:comment]).to eq('A comment with a #-char')
end
-
end
- describe "when parsing a line with ip, hostname and aliases" do
-
- it "should parse alias from the third field" do
- expect(@provider.parse_line("127.0.0.1 localhost localhost.localdomain")[:host_aliases]).to eq("localhost.localdomain")
+ describe 'when parsing a line with ip, hostname and aliases' do
+ it 'parses alias from the third field' do
+ expect(@provider.parse_line('127.0.0.1 localhost localhost.localdomain')[:host_aliases]).to eq('localhost.localdomain')
end
- it "should parse multiple aliases" do
- expect(@provider.parse_line("127.0.0.1 host alias1 alias2")[:host_aliases]).to eq('alias1 alias2')
+ it 'parses multiple aliases' do
+ expect(@provider.parse_line('127.0.0.1 host alias1 alias2')[:host_aliases]).to eq('alias1 alias2')
expect(@provider.parse_line("127.0.0.1 host alias1\talias2")[:host_aliases]).to eq('alias1 alias2')
expect(@provider.parse_line("127.0.0.1 host alias1\talias2 alias3")[:host_aliases]).to eq('alias1 alias2 alias3')
end
-
end
- describe "when parsing a line with ip, hostname, aliases and comment" do
-
- before do
+ describe 'when parsing a line with ip, hostname, aliases and comment' do
+ before(:each) do
# Just playing with a few different delimiters
@testline = "127.0.0.1\t host alias1\talias2 alias3 # A comment with a #-char"
end
- it "should parse the ip from the first field" do
- expect(@provider.parse_line(@testline)[:ip]).to eq("127.0.0.1")
+ it 'parses the ip from the first field' do
+ expect(@provider.parse_line(@testline)[:ip]).to eq('127.0.0.1')
end
- it "should parse the hostname from the second field" do
- expect(@provider.parse_line(@testline)[:name]).to eq("host")
+ it 'parses the hostname from the second field' do
+ expect(@provider.parse_line(@testline)[:name]).to eq('host')
end
- it "should parse all host_aliases from the third field" do
+ it 'parses all host_aliases from the third field' do
expect(@provider.parse_line(@testline)[:host_aliases]).to eq('alias1 alias2 alias3')
end
- it "should parse the comment after the first '#' character" do
+ it "parses the comment after the first '#' character" do
expect(@provider.parse_line(@testline)[:comment]).to eq('A comment with a #-char')
end
-
end
- describe "when operating on /etc/hosts like files" do
- it_should_behave_like "all parsedfile providers",
- provider_class, my_fixtures('valid*')
+ describe 'when operating on /etc/hosts like files' do
+ it_behaves_like 'all parsedfile providers',
+ provider_class, my_fixtures('valid*')
- it "should be able to generate a simple hostfile entry" do
+ it 'is able to generate a simple hostfile entry' do
host = mkhost(
- :name => 'localhost',
- :ip => '127.0.0.1',
- :ensure => :present
+ name: 'localhost',
+ ip: '127.0.0.1',
+ ensure: :present,
)
expect(genhost(host)).to eq("127.0.0.1\tlocalhost\n")
end
- it "should be able to generate an entry with one alias" do
+ it 'is able to generate an entry with one alias' do
host = mkhost(
- :name => 'localhost.localdomain',
- :ip => '127.0.0.1',
- :host_aliases => 'localhost',
- :ensure => :present
+ name: 'localhost.localdomain',
+ ip: '127.0.0.1',
+ host_aliases: 'localhost',
+ ensure: :present,
)
expect(genhost(host)).to eq("127.0.0.1\tlocalhost.localdomain\tlocalhost\n")
end
- it "should be able to generate an entry with more than one alias" do
+ it 'is able to generate an entry with more than one alias' do
host = mkhost(
- :name => 'host',
- :ip => '192.0.0.1',
- :host_aliases => [ 'a1','a2','a3','a4' ],
- :ensure => :present
+ name: 'host',
+ ip: '192.0.0.1',
+ host_aliases: ['a1', 'a2', 'a3', 'a4'],
+ ensure: :present,
)
expect(genhost(host)).to eq("192.0.0.1\thost\ta1 a2 a3 a4\n")
end
- it "should be able to generate a simple hostfile entry with comments" do
+ it 'is able to generate a simple hostfile entry with comments' do
host = mkhost(
- :name => 'localhost',
- :ip => '127.0.0.1',
- :comment => 'Bazinga!',
- :ensure => :present
+ name: 'localhost',
+ ip: '127.0.0.1',
+ comment: 'Bazinga!',
+ ensure: :present,
)
expect(genhost(host)).to eq("127.0.0.1\tlocalhost\t# Bazinga!\n")
end
- it "should be able to generate an entry with one alias and a comment" do
+ it 'is 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
+ name: 'localhost.localdomain',
+ ip: '127.0.0.1',
+ host_aliases: 'localhost',
+ comment: 'Bazinga!',
+ ensure: :present,
)
expect(genhost(host)).to eq("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
+ it 'is 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
+ name: 'host',
+ ip: '192.0.0.1',
+ host_aliases: ['a1', 'a2', 'a3', 'a4'],
+ comment: 'Bazinga!',
+ ensure: :present,
)
expect(genhost(host)).to eq("192.0.0.1\thost\ta1 a2 a3 a4\t# Bazinga!\n")
end
-
end
-
end
diff --git a/spec/unit/type/host_spec.rb b/spec/unit/type/host_spec.rb
index ecce6e2..92138ee 100644
--- a/spec/unit/type/host_spec.rb
+++ b/spec/unit/type/host_spec.rb
@@ -5,19 +5,19 @@ host = Puppet::Type.type(:host)
describe host do
FakeHostProvider = Struct.new(:ip, :host_aliases, :comment)
- before do
+ before(:each) do
@class = host
@catalog = Puppet::Resource::Catalog.new
@provider = FakeHostProvider.new
- @resource = stub 'resource', :resource => nil, :provider => @provider
+ @resource = stub 'resource', resource: nil, provider: @provider
end
- it "should have :name be its namevar" do
+ it 'has :name be its namevar' do
expect(@class.key_attributes).to eq([:name])
end
- describe "when validating attributes" do
- [:name, :provider ].each do |param|
+ describe 'when validating attributes' do
+ [:name, :provider].each do |param|
it "should have a #{param} parameter" do
expect(@class.attrtype(param)).to eq(:param)
end
@@ -29,636 +29,631 @@ describe host do
end
end
- it "should have a list host_aliases" do
+ it 'has a list host_aliases' do
expect(@class.attrclass(:host_aliases).ancestors).to be_include(Puppet::Property::OrderedList)
end
-
end
- describe "when validating values" do
- it "should support present as a value for ensure" do
- expect { @class.new(:name => "foo", :ensure => :present) }.not_to raise_error
+ describe 'when validating values' do
+ it 'supports present as a value for ensure' do
+ expect { @class.new(name: 'foo', ensure: :present) }.not_to raise_error
end
- it "should support absent as a value for ensure" do
- expect { @class.new(:name => "foo", :ensure => :absent) }.not_to raise_error
+ it 'supports absent as a value for ensure' do
+ expect { @class.new(name: 'foo', ensure: :absent) }.not_to raise_error
end
- it "should accept IPv4 addresses" do
- expect { @class.new(:name => "foo", :ip => '10.96.0.1') }.not_to raise_error
+ it 'accepts IPv4 addresses' do
+ expect { @class.new(name: 'foo', ip: '10.96.0.1') }.not_to raise_error
end
- it "should accept long IPv6 addresses" do
+ it 'accepts long IPv6 addresses' do
# Taken from wikipedia article about ipv6
- expect { @class.new(:name => "foo", :ip => '2001:0db8:85a3:08d3:1319:8a2e:0370:7344') }.not_to raise_error
+ expect { @class.new(name: 'foo', ip: '2001:0db8:85a3:08d3:1319:8a2e:0370:7344') }.not_to raise_error
end
- it "should accept one host_alias" do
- expect { @class.new(:name => "foo", :host_aliases => 'alias1') }.not_to raise_error
+ it 'accepts one host_alias' do
+ expect { @class.new(name: 'foo', host_aliases: 'alias1') }.not_to raise_error
end
- it "should accept multiple host_aliases" do
- expect { @class.new(:name => "foo", :host_aliases => [ 'alias1', 'alias2' ]) }.not_to raise_error
+ it 'accepts multiple host_aliases' do
+ expect { @class.new(name: 'foo', host_aliases: ['alias1', 'alias2']) }.not_to raise_error
end
- it "should accept shortened IPv6 addresses" do
- expect { @class.new(:name => "foo", :ip => '2001:db8:0:8d3:0:8a2e:70:7344') }.not_to raise_error
- expect { @class.new(:name => "foo", :ip => '::ffff:192.0.2.128') }.not_to raise_error
- expect { @class.new(:name => "foo", :ip => '::1') }.not_to raise_error
+ it 'accepts shortened IPv6 addresses' do
+ expect { @class.new(name: 'foo', ip: '2001:db8:0:8d3:0:8a2e:70:7344') }.not_to raise_error
+ expect { @class.new(name: 'foo', ip: '::ffff:192.0.2.128') }.not_to raise_error
+ expect { @class.new(name: 'foo', ip: '::1') }.not_to raise_error
end
- it "should not accept malformed IPv4 addresses like 192.168.0.300" do
- expect { @class.new(:name => "foo", :ip => '192.168.0.300') }.to raise_error(Puppet::ResourceError, /Parameter ip failed/)
+ it 'does not accept malformed IPv4 addresses like 192.168.0.300' do
+ expect { @class.new(name: 'foo', ip: '192.168.0.300') }.to raise_error(Puppet::ResourceError, %r{Parameter ip failed})
end
- it "should reject over-long IPv4 addresses" do
- expect { @class.new(:name => "foo", :ip => '10.10.10.10.10') }.to raise_error(Puppet::ResourceError, /Parameter ip failed/)
+ it 'rejects over-long IPv4 addresses' do
+ expect { @class.new(name: 'foo', ip: '10.10.10.10.10') }.to raise_error(Puppet::ResourceError, %r{Parameter ip failed})
end
- it "should not accept malformed IP addresses like 2001:0dg8:85a3:08d3:1319:8a2e:0370:7344" do
- expect { @class.new(:name => "foo", :ip => '2001:0dg8:85a3:08d3:1319:8a2e:0370:7344') }.to raise_error(Puppet::ResourceError, /Parameter ip failed/)
+ it 'does not accept malformed IP addresses like 2001:0dg8:85a3:08d3:1319:8a2e:0370:7344' do
+ expect { @class.new(name: 'foo', ip: '2001:0dg8:85a3:08d3:1319:8a2e:0370:7344') }.to raise_error(Puppet::ResourceError, %r{Parameter ip failed})
end
# Assorted, annotated IPv6 passes.
- ["::1", # loopback, compressed, non-routable
- "::", # unspecified, compressed, non-routable
- "0:0:0:0:0:0:0:1", # loopback, full
- "0:0:0:0:0:0:0:0", # unspecified, full
- "2001:DB8:0:0:8:800:200C:417A", # unicast, full
- "FF01:0:0:0:0:0:0:101", # multicast, full
- "2001:DB8::8:800:200C:417A", # unicast, compressed
- "FF01::101", # multicast, compressed
+ ['::1', # loopback, compressed, non-routable
+ '::', # unspecified, compressed, non-routable
+ '0:0:0:0:0:0:0:1', # loopback, full
+ '0:0:0:0:0:0:0:0', # unspecified, full
+ '2001:DB8:0:0:8:800:200C:417A', # unicast, full
+ 'FF01:0:0:0:0:0:0:101', # multicast, full
+ '2001:DB8::8:800:200C:417A', # unicast, compressed
+ 'FF01::101', # multicast, compressed
# Some more test cases that should pass.
- "2001:0000:1234:0000:0000:C1C0:ABCD:0876",
- "3ffe:0b00:0000:0000:0001:0000:0000:000a",
- "FF02:0000:0000:0000:0000:0000:0000:0001",
- "0000:0000:0000:0000:0000:0000:0000:0001",
- "0000:0000:0000:0000:0000:0000:0000:0000",
+ '2001:0000:1234:0000:0000:C1C0:ABCD:0876',
+ '3ffe:0b00:0000:0000:0001:0000:0000:000a',
+ 'FF02:0000:0000:0000:0000:0000:0000:0001',
+ '0000:0000:0000:0000:0000:0000:0000:0001',
+ '0000:0000:0000:0000:0000:0000:0000:0000',
# Assorted valid, compressed IPv6 addresses.
- "2::10",
- "ff02::1",
- "fe80::",
- "2002::",
- "2001:db8::",
- "2001:0db8:1234::",
- "::ffff:0:0",
- "::1",
- "1:2:3:4:5:6:7:8",
- "1:2:3:4:5:6::8",
- "1:2:3:4:5::8",
- "1:2:3:4::8",
- "1:2:3::8",
- "1:2::8",
- "1::8",
- "1::2:3:4:5:6:7",
- "1::2:3:4:5:6",
- "1::2:3:4:5",
- "1::2:3:4",
- "1::2:3",
- "1::8",
- "::2:3:4:5:6:7:8",
- "::2:3:4:5:6:7",
- "::2:3:4:5:6",
- "::2:3:4:5",
- "::2:3:4",
- "::2:3",
- "::8",
- "1:2:3:4:5:6::",
- "1:2:3:4:5::",
- "1:2:3:4::",
- "1:2:3::",
- "1:2::",
- "1::",
- "1:2:3:4:5::7:8",
- "1:2:3:4::7:8",
- "1:2:3::7:8",
- "1:2::7:8",
- "1::7:8",
+ '2::10',
+ 'ff02::1',
+ 'fe80::',
+ '2002::',
+ '2001:db8::',
+ '2001:0db8:1234::',
+ '::ffff:0:0',
+ '::1',
+ '1:2:3:4:5:6:7:8',
+ '1:2:3:4:5:6::8',
+ '1:2:3:4:5::8',
+ '1:2:3:4::8',
+ '1:2:3::8',
+ '1:2::8',
+ '1::8',
+ '1::2:3:4:5:6:7',
+ '1::2:3:4:5:6',
+ '1::2:3:4:5',
+ '1::2:3:4',
+ '1::2:3',
+ '1::8',
+ '::2:3:4:5:6:7:8',
+ '::2:3:4:5:6:7',
+ '::2:3:4:5:6',
+ '::2:3:4:5',
+ '::2:3:4',
+ '::2:3',
+ '::8',
+ '1:2:3:4:5:6::',
+ '1:2:3:4:5::',
+ '1:2:3:4::',
+ '1:2:3::',
+ '1:2::',
+ '1::',
+ '1:2:3:4:5::7:8',
+ '1:2:3:4::7:8',
+ '1:2:3::7:8',
+ '1:2::7:8',
+ '1::7:8',
# IPv4 addresses as dotted-quads
- "1:2:3:4:5:6:1.2.3.4",
- "1:2:3:4:5::1.2.3.4",
- "1:2:3:4::1.2.3.4",
- "1:2:3::1.2.3.4",
- "1:2::1.2.3.4",
- "1::1.2.3.4",
- "1:2:3:4::5:1.2.3.4",
- "1:2:3::5:1.2.3.4",
- "1:2::5:1.2.3.4",
- "1::5:1.2.3.4",
- "1::5:11.22.33.44",
- "fe80::217:f2ff:254.7.237.98",
- "::ffff:192.168.1.26",
- "::ffff:192.168.1.1",
- "0:0:0:0:0:0:13.1.68.3", # IPv4-compatible IPv6 address, full, deprecated
- "0:0:0:0:0:FFFF:129.144.52.38", # IPv4-mapped IPv6 address, full
- "::13.1.68.3", # IPv4-compatible IPv6 address, compressed, deprecated
- "::FFFF:129.144.52.38", # IPv4-mapped IPv6 address, compressed
- "fe80:0:0:0:204:61ff:254.157.241.86",
- "fe80::204:61ff:254.157.241.86",
- "::ffff:12.34.56.78",
- "::ffff:192.0.2.128", # this is OK, since there's a single zero digit in IPv4
- "fe80:0000:0000:0000:0204:61ff:fe9d:f156",
- "fe80:0:0:0:204:61ff:fe9d:f156",
- "fe80::204:61ff:fe9d:f156",
- "::1",
- "fe80::",
- "fe80::1",
- "::ffff:c000:280",
+ '1:2:3:4:5:6:1.2.3.4',
+ '1:2:3:4:5::1.2.3.4',
+ '1:2:3:4::1.2.3.4',
+ '1:2:3::1.2.3.4',
+ '1:2::1.2.3.4',
+ '1::1.2.3.4',
+ '1:2:3:4::5:1.2.3.4',
+ '1:2:3::5:1.2.3.4',
+ '1:2::5:1.2.3.4',
+ '1::5:1.2.3.4',
+ '1::5:11.22.33.44',
+ 'fe80::217:f2ff:254.7.237.98',
+ '::ffff:192.168.1.26',
+ '::ffff:192.168.1.1',
+ '0:0:0:0:0:0:13.1.68.3', # IPv4-compatible IPv6 address, full, deprecated
+ '0:0:0:0:0:FFFF:129.144.52.38', # IPv4-mapped IPv6 address, full
+ '::13.1.68.3', # IPv4-compatible IPv6 address, compressed, deprecated
+ '::FFFF:129.144.52.38', # IPv4-mapped IPv6 address, compressed
+ 'fe80:0:0:0:204:61ff:254.157.241.86',
+ 'fe80::204:61ff:254.157.241.86',
+ '::ffff:12.34.56.78',
+ '::ffff:192.0.2.128', # this is OK, since there's a single zero digit in IPv4
+ 'fe80:0000:0000:0000:0204:61ff:fe9d:f156',
+ 'fe80:0:0:0:204:61ff:fe9d:f156',
+ 'fe80::204:61ff:fe9d:f156',
+ '::1',
+ 'fe80::',
+ 'fe80::1',
+ '::ffff:c000:280',
# Additional test cases from http://rt.cpan.org/Public/Bug/Display.html?id=50693
- "2001:0db8:85a3:0000:0000:8a2e:0370:7334",
- "2001:db8:85a3:0:0:8a2e:370:7334",
- "2001:db8:85a3::8a2e:370:7334",
- "2001:0db8:0000:0000:0000:0000:1428:57ab",
- "2001:0db8:0000:0000:0000::1428:57ab",
- "2001:0db8:0:0:0:0:1428:57ab",
- "2001:0db8:0:0::1428:57ab",
- "2001:0db8::1428:57ab",
- "2001:db8::1428:57ab",
- "0000:0000:0000:0000:0000:0000:0000:0001",
- "::1",
- "::ffff:0c22:384e",
- "2001:0db8:1234:0000:0000:0000:0000:0000",
- "2001:0db8:1234:ffff:ffff:ffff:ffff:ffff",
- "2001:db8:a::123",
- "fe80::",
-
- "1111:2222:3333:4444:5555:6666:7777:8888",
- "1111:2222:3333:4444:5555:6666:7777::",
- "1111:2222:3333:4444:5555:6666::",
- "1111:2222:3333:4444:5555::",
- "1111:2222:3333:4444::",
- "1111:2222:3333::",
- "1111:2222::",
- "1111::",
- "1111:2222:3333:4444:5555:6666::8888",
- "1111:2222:3333:4444:5555::8888",
- "1111:2222:3333:4444::8888",
- "1111:2222:3333::8888",
- "1111:2222::8888",
- "1111::8888",
- "::8888",
- "1111:2222:3333:4444:5555::7777:8888",
- "1111:2222:3333:4444::7777:8888",
- "1111:2222:3333::7777:8888",
- "1111:2222::7777:8888",
- "1111::7777:8888",
- "::7777:8888",
- "1111:2222:3333:4444::6666:7777:8888",
- "1111:2222:3333::6666:7777:8888",
- "1111:2222::6666:7777:8888",
- "1111::6666:7777:8888",
- "::6666:7777:8888",
- "1111:2222:3333::5555:6666:7777:8888",
- "1111:2222::5555:6666:7777:8888",
- "1111::5555:6666:7777:8888",
- "::5555:6666:7777:8888",
- "1111:2222::4444:5555:6666:7777:8888",
- "1111::4444:5555:6666:7777:8888",
- "::4444:5555:6666:7777:8888",
- "1111::3333:4444:5555:6666:7777:8888",
- "::3333:4444:5555:6666:7777:8888",
- "::2222:3333:4444:5555:6666:7777:8888",
- "1111:2222:3333:4444:5555:6666:123.123.123.123",
- "1111:2222:3333:4444:5555::123.123.123.123",
- "1111:2222:3333:4444::123.123.123.123",
- "1111:2222:3333::123.123.123.123",
- "1111:2222::123.123.123.123",
- "1111::123.123.123.123",
- "::123.123.123.123",
- "1111:2222:3333:4444::6666:123.123.123.123",
- "1111:2222:3333::6666:123.123.123.123",
- "1111:2222::6666:123.123.123.123",
- "1111::6666:123.123.123.123",
- "::6666:123.123.123.123",
- "1111:2222:3333::5555:6666:123.123.123.123",
- "1111:2222::5555:6666:123.123.123.123",
- "1111::5555:6666:123.123.123.123",
- "::5555:6666:123.123.123.123",
- "1111:2222::4444:5555:6666:123.123.123.123",
- "1111::4444:5555:6666:123.123.123.123",
- "::4444:5555:6666:123.123.123.123",
- "1111::3333:4444:5555:6666:123.123.123.123",
- "::2222:3333:4444:5555:6666:123.123.123.123",
+ '2001:0db8:85a3:0000:0000:8a2e:0370:7334',
+ '2001:db8:85a3:0:0:8a2e:370:7334',
+ '2001:db8:85a3::8a2e:370:7334',
+ '2001:0db8:0000:0000:0000:0000:1428:57ab',
+ '2001:0db8:0000:0000:0000::1428:57ab',
+ '2001:0db8:0:0:0:0:1428:57ab',
+ '2001:0db8:0:0::1428:57ab',
+ '2001:0db8::1428:57ab',
+ '2001:db8::1428:57ab',
+ '0000:0000:0000:0000:0000:0000:0000:0001',
+ '::1',
+ '::ffff:0c22:384e',
+ '2001:0db8:1234:0000:0000:0000:0000:0000',
+ '2001:0db8:1234:ffff:ffff:ffff:ffff:ffff',
+ '2001:db8:a::123',
+ 'fe80::',
+
+ '1111:2222:3333:4444:5555:6666:7777:8888',
+ '1111:2222:3333:4444:5555:6666:7777::',
+ '1111:2222:3333:4444:5555:6666::',
+ '1111:2222:3333:4444:5555::',
+ '1111:2222:3333:4444::',
+ '1111:2222:3333::',
+ '1111:2222::',
+ '1111::',
+ '1111:2222:3333:4444:5555:6666::8888',
+ '1111:2222:3333:4444:5555::8888',
+ '1111:2222:3333:4444::8888',
+ '1111:2222:3333::8888',
+ '1111:2222::8888',
+ '1111::8888',
+ '::8888',
+ '1111:2222:3333:4444:5555::7777:8888',
+ '1111:2222:3333:4444::7777:8888',
+ '1111:2222:3333::7777:8888',
+ '1111:2222::7777:8888',
+ '1111::7777:8888',
+ '::7777:8888',
+ '1111:2222:3333:4444::6666:7777:8888',
+ '1111:2222:3333::6666:7777:8888',
+ '1111:2222::6666:7777:8888',
+ '1111::6666:7777:8888',
+ '::6666:7777:8888',
+ '1111:2222:3333::5555:6666:7777:8888',
+ '1111:2222::5555:6666:7777:8888',
+ '1111::5555:6666:7777:8888',
+ '::5555:6666:7777:8888',
+ '1111:2222::4444:5555:6666:7777:8888',
+ '1111::4444:5555:6666:7777:8888',
+ '::4444:5555:6666:7777:8888',
+ '1111::3333:4444:5555:6666:7777:8888',
+ '::3333:4444:5555:6666:7777:8888',
+ '::2222:3333:4444:5555:6666:7777:8888',
+ '1111:2222:3333:4444:5555:6666:123.123.123.123',
+ '1111:2222:3333:4444:5555::123.123.123.123',
+ '1111:2222:3333:4444::123.123.123.123',
+ '1111:2222:3333::123.123.123.123',
+ '1111:2222::123.123.123.123',
+ '1111::123.123.123.123',
+ '::123.123.123.123',
+ '1111:2222:3333:4444::6666:123.123.123.123',
+ '1111:2222:3333::6666:123.123.123.123',
+ '1111:2222::6666:123.123.123.123',
+ '1111::6666:123.123.123.123',
+ '::6666:123.123.123.123',
+ '1111:2222:3333::5555:6666:123.123.123.123',
+ '1111:2222::5555:6666:123.123.123.123',
+ '1111::5555:6666:123.123.123.123',
+ '::5555:6666:123.123.123.123',
+ '1111:2222::4444:5555:6666:123.123.123.123',
+ '1111::4444:5555:6666:123.123.123.123',
+ '::4444:5555:6666:123.123.123.123',
+ '1111::3333:4444:5555:6666:123.123.123.123',
+ '::2222:3333:4444:5555:6666:123.123.123.123',
# Playing with combinations of "0" and "::"; these are all sytactically
# correct, but are bad form because "0" adjacent to "::" should be
# combined into "::"
- "::0:0:0:0:0:0:0",
- "::0:0:0:0:0:0",
- "::0:0:0:0:0",
- "::0:0:0:0",
- "::0:0:0",
- "::0:0",
- "::0",
- "0:0:0:0:0:0:0::",
- "0:0:0:0:0:0::",
- "0:0:0:0:0::",
- "0:0:0:0::",
- "0:0:0::",
- "0:0::",
- "0::",
+ '::0:0:0:0:0:0:0',
+ '::0:0:0:0:0:0',
+ '::0:0:0:0:0',
+ '::0:0:0:0',
+ '::0:0:0',
+ '::0:0',
+ '::0',
+ '0:0:0:0:0:0:0::',
+ '0:0:0:0:0:0::',
+ '0:0:0:0:0::',
+ '0:0:0:0::',
+ '0:0:0::',
+ '0:0::',
+ '0::',
# Additional cases: http://crisp.tweakblogs.net/blog/2031/ipv6-validation-%28and-caveats%29.html
- "0:a:b:c:d:e:f::",
- "::0:a:b:c:d:e:f", # syntactically correct, but bad form (::0:... could be combined)
- "a:b:c:d:e:f:0::",
- ].each do |ip|
+ '0:a:b:c:d:e:f::',
+ '::0:a:b:c:d:e:f', # syntactically correct, but bad form (::0:... could be combined)
+ 'a:b:c:d:e:f:0::'].each do |ip|
it "should accept #{ip.inspect} as an IPv6 address" do
- expect { @class.new(:name => "foo", :ip => ip) }.not_to raise_error
+ expect { @class.new(name: 'foo', ip: ip) }.not_to raise_error
end
end
# ...aaaand, some failure cases.
- [":",
- "02001:0000:1234:0000:0000:C1C0:ABCD:0876", # extra 0 not allowed!
- "2001:0000:1234:0000:00001:C1C0:ABCD:0876", # extra 0 not allowed!
- "2001:0000:1234:0000:0000:C1C0:ABCD:0876 0", # junk after valid address
- "2001:0000:1234: 0000:0000:C1C0:ABCD:0876", # internal space
- "3ffe:0b00:0000:0001:0000:0000:000a", # seven segments
- "FF02:0000:0000:0000:0000:0000:0000:0000:0001", # nine segments
- "3ffe:b00::1::a", # double "::"
- "::1111:2222:3333:4444:5555:6666::", # double "::"
- "1:2:3::4:5::7:8", # Double "::"
- "12345::6:7:8",
+ [':',
+ '02001:0000:1234:0000:0000:C1C0:ABCD:0876', # extra 0 not allowed!
+ '2001:0000:1234:0000:00001:C1C0:ABCD:0876', # extra 0 not allowed!
+ '2001:0000:1234:0000:0000:C1C0:ABCD:0876 0', # junk after valid address
+ '2001:0000:1234: 0000:0000:C1C0:ABCD:0876', # internal space
+ '3ffe:0b00:0000:0001:0000:0000:000a', # seven segments
+ 'FF02:0000:0000:0000:0000:0000:0000:0000:0001', # nine segments
+ '3ffe:b00::1::a', # double "::"
+ '::1111:2222:3333:4444:5555:6666::', # double "::"
+ '1:2:3::4:5::7:8', # Double "::"
+ '12345::6:7:8',
# IPv4 embedded, but bad...
- "1::5:400.2.3.4", "1::5:260.2.3.4", "1::5:256.2.3.4", "1::5:1.256.3.4",
- "1::5:1.2.256.4", "1::5:1.2.3.256", "1::5:300.2.3.4", "1::5:1.300.3.4",
- "1::5:1.2.300.4", "1::5:1.2.3.300", "1::5:900.2.3.4", "1::5:1.900.3.4",
- "1::5:1.2.900.4", "1::5:1.2.3.900", "1::5:300.300.300.300", "1::5:3000.30.30.30",
- "1::400.2.3.4", "1::260.2.3.4", "1::256.2.3.4", "1::1.256.3.4",
- "1::1.2.256.4", "1::1.2.3.256", "1::300.2.3.4", "1::1.300.3.4",
- "1::1.2.300.4", "1::1.2.3.300", "1::900.2.3.4", "1::1.900.3.4",
- "1::1.2.900.4", "1::1.2.3.900", "1::300.300.300.300", "1::3000.30.30.30",
- "::400.2.3.4", "::260.2.3.4", "::256.2.3.4", "::1.256.3.4",
- "::1.2.256.4", "::1.2.3.256", "::300.2.3.4", "::1.300.3.4",
- "::1.2.300.4", "::1.2.3.300", "::900.2.3.4", "::1.900.3.4",
- "::1.2.900.4", "::1.2.3.900", "::300.300.300.300", "::3000.30.30.30",
- "2001:1:1:1:1:1:255Z255X255Y255", # garbage instead of "." in IPv4
- "::ffff:192x168.1.26", # ditto
- "::ffff:2.3.4",
- "::ffff:257.1.2.3",
- "1.2.3.4:1111:2222:3333:4444::5555",
- "1.2.3.4:1111:2222:3333::5555",
- "1.2.3.4:1111:2222::5555",
- "1.2.3.4:1111::5555",
- "1.2.3.4::5555",
- "1.2.3.4::",
+ '1::5:400.2.3.4', '1::5:260.2.3.4', '1::5:256.2.3.4', '1::5:1.256.3.4',
+ '1::5:1.2.256.4', '1::5:1.2.3.256', '1::5:300.2.3.4', '1::5:1.300.3.4',
+ '1::5:1.2.300.4', '1::5:1.2.3.300', '1::5:900.2.3.4', '1::5:1.900.3.4',
+ '1::5:1.2.900.4', '1::5:1.2.3.900', '1::5:300.300.300.300', '1::5:3000.30.30.30',
+ '1::400.2.3.4', '1::260.2.3.4', '1::256.2.3.4', '1::1.256.3.4',
+ '1::1.2.256.4', '1::1.2.3.256', '1::300.2.3.4', '1::1.300.3.4',
+ '1::1.2.300.4', '1::1.2.3.300', '1::900.2.3.4', '1::1.900.3.4',
+ '1::1.2.900.4', '1::1.2.3.900', '1::300.300.300.300', '1::3000.30.30.30',
+ '::400.2.3.4', '::260.2.3.4', '::256.2.3.4', '::1.256.3.4',
+ '::1.2.256.4', '::1.2.3.256', '::300.2.3.4', '::1.300.3.4',
+ '::1.2.300.4', '::1.2.3.300', '::900.2.3.4', '::1.900.3.4',
+ '::1.2.900.4', '::1.2.3.900', '::300.300.300.300', '::3000.30.30.30',
+ '2001:1:1:1:1:1:255Z255X255Y255', # garbage instead of "." in IPv4
+ '::ffff:192x168.1.26', # ditto
+ '::ffff:2.3.4',
+ '::ffff:257.1.2.3',
+ '1.2.3.4:1111:2222:3333:4444::5555',
+ '1.2.3.4:1111:2222:3333::5555',
+ '1.2.3.4:1111:2222::5555',
+ '1.2.3.4:1111::5555',
+ '1.2.3.4::5555',
+ '1.2.3.4::',
# Testing IPv4 addresses represented as dotted-quads Leading zero's in
# IPv4 addresses not allowed: some systems treat the leading "0" in
# ".086" as the start of an octal number Update: The BNF in RFC-3986
# explicitly defines the dec-octet (for IPv4 addresses) not to have a
# leading zero
- "fe80:0000:0000:0000:0204:61ff:254.157.241.086",
- "XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:1.2.3.4",
- "1111:2222:3333:4444:5555:6666:00.00.00.00",
- "1111:2222:3333:4444:5555:6666:000.000.000.000",
- "1111:2222:3333:4444:5555:6666:256.256.256.256",
-
- "1111:2222:3333:4444::5555:",
- "1111:2222:3333::5555:",
- "1111:2222::5555:",
- "1111::5555:",
- "::5555:",
- ":::",
- "1111:",
- ":",
-
- ":1111:2222:3333:4444::5555",
- ":1111:2222:3333::5555",
- ":1111:2222::5555",
- ":1111::5555",
- ":::5555",
- ":::",
+ 'fe80:0000:0000:0000:0204:61ff:254.157.241.086',
+ 'XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:1.2.3.4',
+ '1111:2222:3333:4444:5555:6666:00.00.00.00',
+ '1111:2222:3333:4444:5555:6666:000.000.000.000',
+ '1111:2222:3333:4444:5555:6666:256.256.256.256',
+
+ '1111:2222:3333:4444::5555:',
+ '1111:2222:3333::5555:',
+ '1111:2222::5555:',
+ '1111::5555:',
+ '::5555:',
+ ':::',
+ '1111:',
+ ':',
+
+ ':1111:2222:3333:4444::5555',
+ ':1111:2222:3333::5555',
+ ':1111:2222::5555',
+ ':1111::5555',
+ ':::5555',
+ ':::',
# Additional test cases from http://rt.cpan.org/Public/Bug/Display.html?id=50693
- "123",
- "ldkfj",
- "2001::FFD3::57ab",
- "2001:db8:85a3::8a2e:37023:7334",
- "2001:db8:85a3::8a2e:370k:7334",
- "1:2:3:4:5:6:7:8:9",
- "1::2::3",
- "1:::3:4:5",
- "1:2:3::4:5:6:7:8:9",
+ '123',
+ 'ldkfj',
+ '2001::FFD3::57ab',
+ '2001:db8:85a3::8a2e:37023:7334',
+ '2001:db8:85a3::8a2e:370k:7334',
+ '1:2:3:4:5:6:7:8:9',
+ '1::2::3',
+ '1:::3:4:5',
+ '1:2:3::4:5:6:7:8:9',
# Invalid data
- "XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX",
+ 'XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX',
# Too many components
- "1111:2222:3333:4444:5555:6666:7777:8888:9999",
- "1111:2222:3333:4444:5555:6666:7777:8888::",
- "::2222:3333:4444:5555:6666:7777:8888:9999",
+ '1111:2222:3333:4444:5555:6666:7777:8888:9999',
+ '1111:2222:3333:4444:5555:6666:7777:8888::',
+ '::2222:3333:4444:5555:6666:7777:8888:9999',
# Too few components
- "1111:2222:3333:4444:5555:6666:7777",
- "1111:2222:3333:4444:5555:6666",
- "1111:2222:3333:4444:5555",
- "1111:2222:3333:4444",
- "1111:2222:3333",
- "1111:2222",
- "1111",
+ '1111:2222:3333:4444:5555:6666:7777',
+ '1111:2222:3333:4444:5555:6666',
+ '1111:2222:3333:4444:5555',
+ '1111:2222:3333:4444',
+ '1111:2222:3333',
+ '1111:2222',
+ '1111',
# Missing :
- "11112222:3333:4444:5555:6666:7777:8888",
- "1111:22223333:4444:5555:6666:7777:8888",
- "1111:2222:33334444:5555:6666:7777:8888",
- "1111:2222:3333:44445555:6666:7777:8888",
- "1111:2222:3333:4444:55556666:7777:8888",
- "1111:2222:3333:4444:5555:66667777:8888",
- "1111:2222:3333:4444:5555:6666:77778888",
+ '11112222:3333:4444:5555:6666:7777:8888',
+ '1111:22223333:4444:5555:6666:7777:8888',
+ '1111:2222:33334444:5555:6666:7777:8888',
+ '1111:2222:3333:44445555:6666:7777:8888',
+ '1111:2222:3333:4444:55556666:7777:8888',
+ '1111:2222:3333:4444:5555:66667777:8888',
+ '1111:2222:3333:4444:5555:6666:77778888',
# Missing : intended for ::
- "1111:2222:3333:4444:5555:6666:7777:8888:",
- "1111:2222:3333:4444:5555:6666:7777:",
- "1111:2222:3333:4444:5555:6666:",
- "1111:2222:3333:4444:5555:",
- "1111:2222:3333:4444:",
- "1111:2222:3333:",
- "1111:2222:",
- "1111:",
- ":",
- ":8888",
- ":7777:8888",
- ":6666:7777:8888",
- ":5555:6666:7777:8888",
- ":4444:5555:6666:7777:8888",
- ":3333:4444:5555:6666:7777:8888",
- ":2222:3333:4444:5555:6666:7777:8888",
- ":1111:2222:3333:4444:5555:6666:7777:8888",
+ '1111:2222:3333:4444:5555:6666:7777:8888:',
+ '1111:2222:3333:4444:5555:6666:7777:',
+ '1111:2222:3333:4444:5555:6666:',
+ '1111:2222:3333:4444:5555:',
+ '1111:2222:3333:4444:',
+ '1111:2222:3333:',
+ '1111:2222:',
+ '1111:',
+ ':',
+ ':8888',
+ ':7777:8888',
+ ':6666:7777:8888',
+ ':5555:6666:7777:8888',
+ ':4444:5555:6666:7777:8888',
+ ':3333:4444:5555:6666:7777:8888',
+ ':2222:3333:4444:5555:6666:7777:8888',
+ ':1111:2222:3333:4444:5555:6666:7777:8888',
# :::
- ":::2222:3333:4444:5555:6666:7777:8888",
- "1111:::3333:4444:5555:6666:7777:8888",
- "1111:2222:::4444:5555:6666:7777:8888",
- "1111:2222:3333:::5555:6666:7777:8888",
- "1111:2222:3333:4444:::6666:7777:8888",
- "1111:2222:3333:4444:5555:::7777:8888",
- "1111:2222:3333:4444:5555:6666:::8888",
- "1111:2222:3333:4444:5555:6666:7777:::",
+ ':::2222:3333:4444:5555:6666:7777:8888',
+ '1111:::3333:4444:5555:6666:7777:8888',
+ '1111:2222:::4444:5555:6666:7777:8888',
+ '1111:2222:3333:::5555:6666:7777:8888',
+ '1111:2222:3333:4444:::6666:7777:8888',
+ '1111:2222:3333:4444:5555:::7777:8888',
+ '1111:2222:3333:4444:5555:6666:::8888',
+ '1111:2222:3333:4444:5555:6666:7777:::',
# Double ::",
- "::2222::4444:5555:6666:7777:8888",
- "::2222:3333::5555:6666:7777:8888",
- "::2222:3333:4444::6666:7777:8888",
- "::2222:3333:4444:5555::7777:8888",
- "::2222:3333:4444:5555:7777::8888",
- "::2222:3333:4444:5555:7777:8888::",
-
- "1111::3333::5555:6666:7777:8888",
- "1111::3333:4444::6666:7777:8888",
- "1111::3333:4444:5555::7777:8888",
- "1111::3333:4444:5555:6666::8888",
- "1111::3333:4444:5555:6666:7777::",
+ '::2222::4444:5555:6666:7777:8888',
+ '::2222:3333::5555:6666:7777:8888',
+ '::2222:3333:4444::6666:7777:8888',
+ '::2222:3333:4444:5555::7777:8888',
+ '::2222:3333:4444:5555:7777::8888',
+ '::2222:3333:4444:5555:7777:8888::',
- "1111:2222::4444::6666:7777:8888",
- "1111:2222::4444:5555::7777:8888",
- "1111:2222::4444:5555:6666::8888",
- "1111:2222::4444:5555:6666:7777::",
+ '1111::3333::5555:6666:7777:8888',
+ '1111::3333:4444::6666:7777:8888',
+ '1111::3333:4444:5555::7777:8888',
+ '1111::3333:4444:5555:6666::8888',
+ '1111::3333:4444:5555:6666:7777::',
- "1111:2222:3333::5555::7777:8888",
- "1111:2222:3333::5555:6666::8888",
- "1111:2222:3333::5555:6666:7777::",
+ '1111:2222::4444::6666:7777:8888',
+ '1111:2222::4444:5555::7777:8888',
+ '1111:2222::4444:5555:6666::8888',
+ '1111:2222::4444:5555:6666:7777::',
- "1111:2222:3333:4444::6666::8888",
- "1111:2222:3333:4444::6666:7777::",
+ '1111:2222:3333::5555::7777:8888',
+ '1111:2222:3333::5555:6666::8888',
+ '1111:2222:3333::5555:6666:7777::',
- "1111:2222:3333:4444:5555::7777::",
+ '1111:2222:3333:4444::6666::8888',
+ '1111:2222:3333:4444::6666:7777::',
+ '1111:2222:3333:4444:5555::7777::',
# Too many components"
- "1111:2222:3333:4444:5555:6666:7777:8888:1.2.3.4",
- "1111:2222:3333:4444:5555:6666:7777:1.2.3.4",
- "1111:2222:3333:4444:5555:6666::1.2.3.4",
- "::2222:3333:4444:5555:6666:7777:1.2.3.4",
- "1111:2222:3333:4444:5555:6666:1.2.3.4.5",
+ '1111:2222:3333:4444:5555:6666:7777:8888:1.2.3.4',
+ '1111:2222:3333:4444:5555:6666:7777:1.2.3.4',
+ '1111:2222:3333:4444:5555:6666::1.2.3.4',
+ '::2222:3333:4444:5555:6666:7777:1.2.3.4',
+ '1111:2222:3333:4444:5555:6666:1.2.3.4.5',
# Too few components
- "1111:2222:3333:4444:5555:1.2.3.4",
- "1111:2222:3333:4444:1.2.3.4",
- "1111:2222:3333:1.2.3.4",
- "1111:2222:1.2.3.4",
- "1111:1.2.3.4",
+ '1111:2222:3333:4444:5555:1.2.3.4',
+ '1111:2222:3333:4444:1.2.3.4',
+ '1111:2222:3333:1.2.3.4',
+ '1111:2222:1.2.3.4',
+ '1111:1.2.3.4',
# Missing :
- "11112222:3333:4444:5555:6666:1.2.3.4",
- "1111:22223333:4444:5555:6666:1.2.3.4",
- "1111:2222:33334444:5555:6666:1.2.3.4",
- "1111:2222:3333:44445555:6666:1.2.3.4",
- "1111:2222:3333:4444:55556666:1.2.3.4",
- "1111:2222:3333:4444:5555:66661.2.3.4",
+ '11112222:3333:4444:5555:6666:1.2.3.4',
+ '1111:22223333:4444:5555:6666:1.2.3.4',
+ '1111:2222:33334444:5555:6666:1.2.3.4',
+ '1111:2222:3333:44445555:6666:1.2.3.4',
+ '1111:2222:3333:4444:55556666:1.2.3.4',
+ '1111:2222:3333:4444:5555:66661.2.3.4',
# Missing .
- "1111:2222:3333:4444:5555:6666:255255.255.255",
- "1111:2222:3333:4444:5555:6666:255.255255.255",
- "1111:2222:3333:4444:5555:6666:255.255.255255",
+ '1111:2222:3333:4444:5555:6666:255255.255.255',
+ '1111:2222:3333:4444:5555:6666:255.255255.255',
+ '1111:2222:3333:4444:5555:6666:255.255.255255',
# Missing : intended for ::
- ":1.2.3.4",
- ":6666:1.2.3.4",
- ":5555:6666:1.2.3.4",
- ":4444:5555:6666:1.2.3.4",
- ":3333:4444:5555:6666:1.2.3.4",
- ":2222:3333:4444:5555:6666:1.2.3.4",
- ":1111:2222:3333:4444:5555:6666:1.2.3.4",
+ ':1.2.3.4',
+ ':6666:1.2.3.4',
+ ':5555:6666:1.2.3.4',
+ ':4444:5555:6666:1.2.3.4',
+ ':3333:4444:5555:6666:1.2.3.4',
+ ':2222:3333:4444:5555:6666:1.2.3.4',
+ ':1111:2222:3333:4444:5555:6666:1.2.3.4',
# :::
- ":::2222:3333:4444:5555:6666:1.2.3.4",
- "1111:::3333:4444:5555:6666:1.2.3.4",
- "1111:2222:::4444:5555:6666:1.2.3.4",
- "1111:2222:3333:::5555:6666:1.2.3.4",
- "1111:2222:3333:4444:::6666:1.2.3.4",
- "1111:2222:3333:4444:5555:::1.2.3.4",
+ ':::2222:3333:4444:5555:6666:1.2.3.4',
+ '1111:::3333:4444:5555:6666:1.2.3.4',
+ '1111:2222:::4444:5555:6666:1.2.3.4',
+ '1111:2222:3333:::5555:6666:1.2.3.4',
+ '1111:2222:3333:4444:::6666:1.2.3.4',
+ '1111:2222:3333:4444:5555:::1.2.3.4',
# Double ::
- "::2222::4444:5555:6666:1.2.3.4",
- "::2222:3333::5555:6666:1.2.3.4",
- "::2222:3333:4444::6666:1.2.3.4",
- "::2222:3333:4444:5555::1.2.3.4",
+ '::2222::4444:5555:6666:1.2.3.4',
+ '::2222:3333::5555:6666:1.2.3.4',
+ '::2222:3333:4444::6666:1.2.3.4',
+ '::2222:3333:4444:5555::1.2.3.4',
- "1111::3333::5555:6666:1.2.3.4",
- "1111::3333:4444::6666:1.2.3.4",
- "1111::3333:4444:5555::1.2.3.4",
+ '1111::3333::5555:6666:1.2.3.4',
+ '1111::3333:4444::6666:1.2.3.4',
+ '1111::3333:4444:5555::1.2.3.4',
- "1111:2222::4444::6666:1.2.3.4",
- "1111:2222::4444:5555::1.2.3.4",
+ '1111:2222::4444::6666:1.2.3.4',
+ '1111:2222::4444:5555::1.2.3.4',
- "1111:2222:3333::5555::1.2.3.4",
+ '1111:2222:3333::5555::1.2.3.4',
# Missing parts
- "::.",
- "::..",
- "::...",
- "::1...",
- "::1.2..",
- "::1.2.3.",
- "::.2..",
- "::.2.3.",
- "::.2.3.4",
- "::..3.",
- "::..3.4",
- "::...4",
+ '::.',
+ '::..',
+ '::...',
+ '::1...',
+ '::1.2..',
+ '::1.2.3.',
+ '::.2..',
+ '::.2.3.',
+ '::.2.3.4',
+ '::..3.',
+ '::..3.4',
+ '::...4',
# Extra : in front
- ":1111:2222:3333:4444:5555:6666:7777::",
- ":1111:2222:3333:4444:5555:6666::",
- ":1111:2222:3333:4444:5555::",
- ":1111:2222:3333:4444::",
- ":1111:2222:3333::",
- ":1111:2222::",
- ":1111::",
- ":::",
- ":1111:2222:3333:4444:5555:6666::8888",
- ":1111:2222:3333:4444:5555::8888",
- ":1111:2222:3333:4444::8888",
- ":1111:2222:3333::8888",
- ":1111:2222::8888",
- ":1111::8888",
- ":::8888",
- ":1111:2222:3333:4444:5555::7777:8888",
- ":1111:2222:3333:4444::7777:8888",
- ":1111:2222:3333::7777:8888",
- ":1111:2222::7777:8888",
- ":1111::7777:8888",
- ":::7777:8888",
- ":1111:2222:3333:4444::6666:7777:8888",
- ":1111:2222:3333::6666:7777:8888",
- ":1111:2222::6666:7777:8888",
- ":1111::6666:7777:8888",
- ":::6666:7777:8888",
- ":1111:2222:3333::5555:6666:7777:8888",
- ":1111:2222::5555:6666:7777:8888",
- ":1111::5555:6666:7777:8888",
- ":::5555:6666:7777:8888",
- ":1111:2222::4444:5555:6666:7777:8888",
- ":1111::4444:5555:6666:7777:8888",
- ":::4444:5555:6666:7777:8888",
- ":1111::3333:4444:5555:6666:7777:8888",
- ":::3333:4444:5555:6666:7777:8888",
- ":::2222:3333:4444:5555:6666:7777:8888",
- ":1111:2222:3333:4444:5555:6666:1.2.3.4",
- ":1111:2222:3333:4444:5555::1.2.3.4",
- ":1111:2222:3333:4444::1.2.3.4",
- ":1111:2222:3333::1.2.3.4",
- ":1111:2222::1.2.3.4",
- ":1111::1.2.3.4",
- ":::1.2.3.4",
- ":1111:2222:3333:4444::6666:1.2.3.4",
- ":1111:2222:3333::6666:1.2.3.4",
- ":1111:2222::6666:1.2.3.4",
- ":1111::6666:1.2.3.4",
- ":::6666:1.2.3.4",
- ":1111:2222:3333::5555:6666:1.2.3.4",
- ":1111:2222::5555:6666:1.2.3.4",
- ":1111::5555:6666:1.2.3.4",
- ":::5555:6666:1.2.3.4",
- ":1111:2222::4444:5555:6666:1.2.3.4",
- ":1111::4444:5555:6666:1.2.3.4",
- ":::4444:5555:6666:1.2.3.4",
- ":1111::3333:4444:5555:6666:1.2.3.4",
- ":::2222:3333:4444:5555:6666:1.2.3.4",
+ ':1111:2222:3333:4444:5555:6666:7777::',
+ ':1111:2222:3333:4444:5555:6666::',
+ ':1111:2222:3333:4444:5555::',
+ ':1111:2222:3333:4444::',
+ ':1111:2222:3333::',
+ ':1111:2222::',
+ ':1111::',
+ ':::',
+ ':1111:2222:3333:4444:5555:6666::8888',
+ ':1111:2222:3333:4444:5555::8888',
+ ':1111:2222:3333:4444::8888',
+ ':1111:2222:3333::8888',
+ ':1111:2222::8888',
+ ':1111::8888',
+ ':::8888',
+ ':1111:2222:3333:4444:5555::7777:8888',
+ ':1111:2222:3333:4444::7777:8888',
+ ':1111:2222:3333::7777:8888',
+ ':1111:2222::7777:8888',
+ ':1111::7777:8888',
+ ':::7777:8888',
+ ':1111:2222:3333:4444::6666:7777:8888',
+ ':1111:2222:3333::6666:7777:8888',
+ ':1111:2222::6666:7777:8888',
+ ':1111::6666:7777:8888',
+ ':::6666:7777:8888',
+ ':1111:2222:3333::5555:6666:7777:8888',
+ ':1111:2222::5555:6666:7777:8888',
+ ':1111::5555:6666:7777:8888',
+ ':::5555:6666:7777:8888',
+ ':1111:2222::4444:5555:6666:7777:8888',
+ ':1111::4444:5555:6666:7777:8888',
+ ':::4444:5555:6666:7777:8888',
+ ':1111::3333:4444:5555:6666:7777:8888',
+ ':::3333:4444:5555:6666:7777:8888',
+ ':::2222:3333:4444:5555:6666:7777:8888',
+ ':1111:2222:3333:4444:5555:6666:1.2.3.4',
+ ':1111:2222:3333:4444:5555::1.2.3.4',
+ ':1111:2222:3333:4444::1.2.3.4',
+ ':1111:2222:3333::1.2.3.4',
+ ':1111:2222::1.2.3.4',
+ ':1111::1.2.3.4',
+ ':::1.2.3.4',
+ ':1111:2222:3333:4444::6666:1.2.3.4',
+ ':1111:2222:3333::6666:1.2.3.4',
+ ':1111:2222::6666:1.2.3.4',
+ ':1111::6666:1.2.3.4',
+ ':::6666:1.2.3.4',
+ ':1111:2222:3333::5555:6666:1.2.3.4',
+ ':1111:2222::5555:6666:1.2.3.4',
+ ':1111::5555:6666:1.2.3.4',
+ ':::5555:6666:1.2.3.4',
+ ':1111:2222::4444:5555:6666:1.2.3.4',
+ ':1111::4444:5555:6666:1.2.3.4',
+ ':::4444:5555:6666:1.2.3.4',
+ ':1111::3333:4444:5555:6666:1.2.3.4',
+ ':::2222:3333:4444:5555:6666:1.2.3.4',
# Extra : at end
- "1111:2222:3333:4444:5555:6666:7777:::",
- "1111:2222:3333:4444:5555:6666:::",
- "1111:2222:3333:4444:5555:::",
- "1111:2222:3333:4444:::",
- "1111:2222:3333:::",
- "1111:2222:::",
- "1111:::",
- ":::",
- "1111:2222:3333:4444:5555:6666::8888:",
- "1111:2222:3333:4444:5555::8888:",
- "1111:2222:3333:4444::8888:",
- "1111:2222:3333::8888:",
- "1111:2222::8888:",
- "1111::8888:",
- "::8888:",
- "1111:2222:3333:4444:5555::7777:8888:",
- "1111:2222:3333:4444::7777:8888:",
- "1111:2222:3333::7777:8888:",
- "1111:2222::7777:8888:",
- "1111::7777:8888:",
- "::7777:8888:",
- "1111:2222:3333:4444::6666:7777:8888:",
- "1111:2222:3333::6666:7777:8888:",
- "1111:2222::6666:7777:8888:",
- "1111::6666:7777:8888:",
- "::6666:7777:8888:",
- "1111:2222:3333::5555:6666:7777:8888:",
- "1111:2222::5555:6666:7777:8888:",
- "1111::5555:6666:7777:8888:",
- "::5555:6666:7777:8888:",
- "1111:2222::4444:5555:6666:7777:8888:",
- "1111::4444:5555:6666:7777:8888:",
- "::4444:5555:6666:7777:8888:",
- "1111::3333:4444:5555:6666:7777:8888:",
- "::3333:4444:5555:6666:7777:8888:",
- "::2222:3333:4444:5555:6666:7777:8888:",
- ].each do |ip|
+ '1111:2222:3333:4444:5555:6666:7777:::',
+ '1111:2222:3333:4444:5555:6666:::',
+ '1111:2222:3333:4444:5555:::',
+ '1111:2222:3333:4444:::',
+ '1111:2222:3333:::',
+ '1111:2222:::',
+ '1111:::',
+ ':::',
+ '1111:2222:3333:4444:5555:6666::8888:',
+ '1111:2222:3333:4444:5555::8888:',
+ '1111:2222:3333:4444::8888:',
+ '1111:2222:3333::8888:',
+ '1111:2222::8888:',
+ '1111::8888:',
+ '::8888:',
+ '1111:2222:3333:4444:5555::7777:8888:',
+ '1111:2222:3333:4444::7777:8888:',
+ '1111:2222:3333::7777:8888:',
+ '1111:2222::7777:8888:',
+ '1111::7777:8888:',
+ '::7777:8888:',
+ '1111:2222:3333:4444::6666:7777:8888:',
+ '1111:2222:3333::6666:7777:8888:',
+ '1111:2222::6666:7777:8888:',
+ '1111::6666:7777:8888:',
+ '::6666:7777:8888:',
+ '1111:2222:3333::5555:6666:7777:8888:',
+ '1111:2222::5555:6666:7777:8888:',
+ '1111::5555:6666:7777:8888:',
+ '::5555:6666:7777:8888:',
+ '1111:2222::4444:5555:6666:7777:8888:',
+ '1111::4444:5555:6666:7777:8888:',
+ '::4444:5555:6666:7777:8888:',
+ '1111::3333:4444:5555:6666:7777:8888:',
+ '::3333:4444:5555:6666:7777:8888:',
+ '::2222:3333:4444:5555:6666:7777:8888:'].each do |ip|
it "should reject #{ip.inspect} as an IPv6 address" do
- expect { @class.new(:name => "foo", :ip => ip) }.to raise_error(Puppet::ResourceError, /Parameter ip failed/)
+ expect { @class.new(name: 'foo', ip: ip) }.to raise_error(Puppet::ResourceError, %r{Parameter ip failed})
end
end
- it "should not accept newlines in resourcename" do
- expect { @class.new(:name => "fo\no", :ip => '127.0.0.1' ) }.to raise_error(Puppet::ResourceError, /Hostname cannot include newline/)
+ it 'does not accept newlines in resourcename' do
+ expect { @class.new(name: "fo\no", ip: '127.0.0.1') }.to raise_error(Puppet::ResourceError, %r{Hostname cannot include newline})
end
- it "should not accept newlines in ipaddress" do
- expect { @class.new(:name => "foo", :ip => "127.0.0.1\n") }.to raise_error(Puppet::ResourceError, /Invalid IP address/)
+ it 'does not accept newlines in ipaddress' do
+ expect { @class.new(name: 'foo', ip: "127.0.0.1\n") }.to raise_error(Puppet::ResourceError, %r{Invalid IP address})
end
- it "should not accept newlines in host_aliases" do
- expect { @class.new(:name => "foo", :ip => '127.0.0.1', :host_aliases => [ 'well_formed', "thisalias\nhavenewline" ] ) }.to raise_error(Puppet::ResourceError, /Host aliases cannot include whitespace/)
+ it 'does not accept newlines in host_aliases' do
+ expect { @class.new(name: 'foo', ip: '127.0.0.1', host_aliases: ['well_formed', "thisalias\nhavenewline"]) }.to raise_error(Puppet::ResourceError, %r{Host aliases cannot include whitespace})
end
- it "should not accept newlines in comment" do
- expect { @class.new(:name => "foo", :ip => '127.0.0.1', :comment => "Test of comment blah blah \n test 123" ) }.to raise_error(Puppet::ResourceError, /Comment cannot include newline/)
+ it 'does not accept newlines in comment' do
+ expect { @class.new(name: 'foo', ip: '127.0.0.1', comment: "Test of comment blah blah \n test 123") }.to raise_error(Puppet::ResourceError, %r{Comment cannot include newline})
end
- it "should not accept spaces in resourcename" do
- expect { @class.new(:name => "foo bar") }.to raise_error(Puppet::ResourceError, /Invalid host name/)
+ it 'does not accept spaces in resourcename' do
+ expect { @class.new(name: 'foo bar') }.to raise_error(Puppet::ResourceError, %r{Invalid host name})
end
- it "should not accept host_aliases with spaces" do
- expect { @class.new(:name => "foo", :host_aliases => [ 'well_formed', 'not wellformed' ]) }.to raise_error(Puppet::ResourceError, /Host aliases cannot include whitespace/)
+ it 'does not accept host_aliases with spaces' do
+ expect { @class.new(name: 'foo', host_aliases: ['well_formed', 'not wellformed']) }.to raise_error(Puppet::ResourceError, %r{Host aliases cannot include whitespace})
end
- it "should not accept empty host_aliases" do
- expect { @class.new(:name => "foo", :host_aliases => ['alias1','']) }.to raise_error(Puppet::ResourceError, /Host aliases cannot be an empty string/)
+ it 'does not accept empty host_aliases' do
+ expect { @class.new(name: 'foo', host_aliases: ['alias1', '']) }.to raise_error(Puppet::ResourceError, %r{Host aliases cannot be an empty string})
end
end
- describe "when syncing" do
-
- it "should send the first value to the provider for ip property" do
- @ip = @class.attrclass(:ip).new(:resource => @resource, :should => %w{192.168.0.1 192.168.0.2})
+ describe 'when syncing' do
+ it 'sends the first value to the provider for ip property' do
+ @ip = @class.attrclass(:ip).new(resource: @resource, should: ['192.168.0.1', '192.168.0.2'])
@ip.sync
expect(@provider.ip).to eq('192.168.0.1')
end
- it "should send the first value to the provider for comment property" do
- @comment = @class.attrclass(:comment).new(:resource => @resource, :should => %w{Bazinga Notme})
+ it 'sends the first value to the provider for comment property' do
+ @comment = @class.attrclass(:comment).new(resource: @resource, should: ['Bazinga', 'Notme'])
@comment.sync
expect(@provider.comment).to eq('Bazinga')
end
- it "should send the joined array to the provider for host_alias" do
- @host_aliases = @class.attrclass(:host_aliases).new(:resource => @resource, :should => %w{foo bar})
+ it 'sends the joined array to the provider for host_alias' do
+ @host_aliases = @class.attrclass(:host_aliases).new(resource: @resource, should: ['foo', 'bar'])
@host_aliases.sync
expect(@provider.host_aliases).to eq('foo bar')
end
- it "should also use the specified delimiter for joining" do
- @host_aliases = @class.attrclass(:host_aliases).new(:resource => @resource, :should => %w{foo bar})
+ it 'alsoes use the specified delimiter for joining' do
+ @host_aliases = @class.attrclass(:host_aliases).new(resource: @resource, should: ['foo', 'bar'])
@host_aliases.stubs(:delimiter).returns "\t"
@host_aliases.sync
@@ -666,16 +661,15 @@ describe host do
expect(@provider.host_aliases).to eq("foo\tbar")
end
- it "should care about the order of host_aliases" do
- @host_aliases = @class.attrclass(:host_aliases).new(:resource => @resource, :should => %w{foo bar})
- expect(@host_aliases.insync?(%w{foo bar})).to eq(true)
- expect(@host_aliases.insync?(%w{bar foo})).to eq(false)
+ it 'cares about the order of host_aliases' do
+ @host_aliases = @class.attrclass(:host_aliases).new(resource: @resource, should: ['foo', 'bar'])
+ expect(@host_aliases.insync?(['foo', 'bar'])).to eq(true)
+ expect(@host_aliases.insync?(['bar', 'foo'])).to eq(false)
end
- it "should not consider aliases to be in sync if should is a subset of current" do
- @host_aliases = @class.attrclass(:host_aliases).new(:resource => @resource, :should => %w{foo bar})
- expect(@host_aliases.insync?(%w{foo bar anotherone})).to eq(false)
+ it 'does not consider aliases to be in sync if should is a subset of current' do
+ @host_aliases = @class.attrclass(:host_aliases).new(resource: @resource, should: ['foo', 'bar'])
+ expect(@host_aliases.insync?(['foo', 'bar', 'anotherone'])).to eq(false)
end
-
end
end