PageRenderTime 40ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/spec/unit/ipaddress6_spec.rb

https://github.com/shsingh/facter
Ruby | 55 lines | 40 code | 14 blank | 1 comment | 8 complexity | 388e7570d918957f8975e825ad205621 MD5 | raw file
Possible License(s): Apache-2.0
  1. #!/usr/bin/env ruby
  2. $basedir = File.expand_path(File.dirname(__FILE__) + '/..')
  3. require File.join($basedir, 'spec_helper')
  4. require 'facter'
  5. def ifconfig_fixture(filename)
  6. ifconfig = File.new(File.join($basedir, 'fixtures', 'ifconfig', filename)).read
  7. end
  8. def netsh_fixture(filename)
  9. ifconfig = File.new(File.join($basedir, 'fixtures', 'netsh', filename)).read
  10. end
  11. describe "IPv6 address fact" do
  12. before do
  13. Facter::Util::Config.stubs(:is_windows?).returns(false)
  14. end
  15. it "should return ipaddress6 information for Darwin" do
  16. Facter::Util::Resolution.stubs(:exec).with('uname -s').returns('Darwin')
  17. Facter::Util::Resolution.stubs(:exec).with('/sbin/ifconfig -a').
  18. returns(ifconfig_fixture('darwin_ifconfig_all_with_multiple_interfaces'))
  19. Facter.value(:ipaddress6).should == "2610:10:20:209:223:32ff:fed5:ee34"
  20. end
  21. it "should return ipaddress6 information for Linux" do
  22. Facter::Util::Resolution.stubs(:exec).with('uname -s').returns('Linux')
  23. Facter::Util::Resolution.stubs(:exec).with('/sbin/ifconfig').
  24. returns(ifconfig_fixture('linux_ifconfig_all_with_multiple_interfaces'))
  25. Facter.value(:ipaddress6).should == "2610:10:20:209:212:3fff:febe:2201"
  26. end
  27. it "should return ipaddress6 information for Solaris" do
  28. Facter::Util::Resolution.stubs(:exec).with('uname -s').returns('SunOS')
  29. Facter::Util::Resolution.stubs(:exec).with('/usr/sbin/ifconfig -a').
  30. returns(ifconfig_fixture('sunos_ifconfig_all_with_multiple_interfaces'))
  31. Facter.value(:ipaddress6).should == "2610:10:20:209:203:baff:fe27:a7c"
  32. end
  33. it "should return ipaddress6 information for Windows" do
  34. ENV.stubs(:[]).with('SYSTEMROOT').returns('d:/windows')
  35. Facter::Util::Config.stubs(:is_windows?).returns(true)
  36. fixture = netsh_fixture('windows_netsh_addresses_with_multiple_interfaces')
  37. Facter::Util::Resolution.stubs(:exec).with('d:/windows/system32/netsh interface ipv6 show address level=verbose').
  38. returns(fixture)
  39. Facter.value(:ipaddress6).should == "2001:0:4137:9e76:2087:77a:53ef:7527"
  40. end
  41. end