PageRenderTime 53ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/spec/unit/puppet/util/ipcidr_spec.rb

https://bitbucket.org/schatt/puppetlabs-firewall
Ruby | 67 lines | 59 code | 8 blank | 0 comment | 24 complexity | 1a6eeb2dd7c9634fcfb60d8ead6e1d79 MD5 | raw file
  1. require 'spec_helper'
  2. describe 'Puppet::Util::IPCidr' do
  3. describe 'ipv4 address' do
  4. before { @ipaddr = Puppet::Util::IPCidr.new('96.126.112.51') }
  5. subject { @ipaddr }
  6. specify { subject.cidr.should == '96.126.112.51/32' }
  7. specify { subject.prefixlen.should == 32 }
  8. specify { subject.netmask.should == '255.255.255.255' }
  9. end
  10. describe 'single ipv4 address with cidr' do
  11. before { @ipcidr = Puppet::Util::IPCidr.new('96.126.112.51/32') }
  12. subject { @ipcidr }
  13. specify { subject.cidr.should == '96.126.112.51/32' }
  14. specify { subject.prefixlen.should == 32 }
  15. specify { subject.netmask.should == '255.255.255.255' }
  16. end
  17. describe 'ipv4 address range with cidr' do
  18. before { @ipcidr = Puppet::Util::IPCidr.new('96.126.112.0/24') }
  19. subject { @ipcidr }
  20. specify { subject.cidr.should == '96.126.112.0/24' }
  21. specify { subject.prefixlen.should == 24 }
  22. specify { subject.netmask.should == '255.255.255.0' }
  23. end
  24. describe 'ipv4 open range with cidr' do
  25. before { @ipcidr = Puppet::Util::IPCidr.new('0.0.0.0/0') }
  26. subject { @ipcidr }
  27. specify { subject.cidr.should == '0.0.0.0/0' }
  28. specify { subject.prefixlen.should == 0 }
  29. specify { subject.netmask.should == '0.0.0.0' }
  30. end
  31. describe 'ipv6 address' do
  32. before { @ipaddr = Puppet::Util::IPCidr.new('2001:db8:85a3:0:0:8a2e:370:7334') }
  33. subject { @ipaddr }
  34. specify { subject.cidr.should == '2001:db8:85a3::8a2e:370:7334/128' }
  35. specify { subject.prefixlen.should == 128 }
  36. specify { subject.netmask.should == 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' }
  37. end
  38. describe 'single ipv6 addr with cidr' do
  39. before { @ipaddr = Puppet::Util::IPCidr.new('2001:db8:85a3:0:0:8a2e:370:7334/128') }
  40. subject { @ipaddr }
  41. specify { subject.cidr.should == '2001:db8:85a3::8a2e:370:7334/128' }
  42. specify { subject.prefixlen.should == 128 }
  43. specify { subject.netmask.should == 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' }
  44. end
  45. describe 'ipv6 addr range with cidr' do
  46. before { @ipaddr = Puppet::Util::IPCidr.new('2001:db8:1234::/48') }
  47. subject { @ipaddr }
  48. specify { subject.cidr.should == '2001:db8:1234::/48' }
  49. specify { subject.prefixlen.should == 48 }
  50. specify { subject.netmask.should == 'ffff:ffff:ffff:0000:0000:0000:0000:0000' }
  51. end
  52. describe 'ipv6 open range with cidr' do
  53. before { @ipaddr = Puppet::Util::IPCidr.new('::/0') }
  54. subject { @ipaddr }
  55. specify { subject.cidr.should == '::/0' }
  56. specify { subject.prefixlen.should == 0 }
  57. specify { subject.netmask.should == '0000:0000:0000:0000:0000:0000:0000:0000' }
  58. end
  59. end