PageRenderTime 43ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/esper/pm/tests/dns_updater_test.rb

https://github.com/seanrees/tools
Ruby | 81 lines | 64 code | 16 blank | 1 comment | 0 complexity | 862e751961efed7fba9cee254a35ea49 MD5 | raw file
  1. require 'test/unit'
  2. require 'lib/dns_updater.rb'
  3. class DnsUpdaterTest < Test::Unit::TestCase
  4. class DnsUpdaterProxy < DnsUpdater
  5. # proxy send_commands to private method
  6. def send_commands(io)
  7. _send_commands(io)
  8. end
  9. end
  10. def setup
  11. @updater = DnsUpdater.new(nil, nil, nil)
  12. end
  13. def test_constructor
  14. assert_equal(@updater.commands.size, 0, 'commands not empty')
  15. end
  16. def test_add
  17. @updater.add('test.com', '127.0.0.1', 'A', 1000)
  18. assert_equal(@updater.commands.size, 1, 'command size not == 1')
  19. assert_equal(@updater.commands[0], 'update add test.com. 1000 A 127.0.0.1')
  20. @updater.add('ipv6.test.com', '2001:dead::beef', 'AAAA', 1000)
  21. assert_equal(@updater.commands.size, 2, 'command size not == 2')
  22. assert_equal(@updater.commands[1], 'update add ipv6.test.com. 1000 AAAA 2001:dead::beef')
  23. end
  24. def test_add_all
  25. @updater.add_all([ 'test.com', 'test2.com' ], '127.0.0.1', 'A', 1000)
  26. assert_equal(@updater.commands.size, 2, 'command size not == 2')
  27. assert_equal(@updater.commands[0], 'update add test.com. 1000 A 127.0.0.1')
  28. assert_equal(@updater.commands[1], 'update add test2.com. 1000 A 127.0.0.1')
  29. end
  30. def test_delete
  31. @updater.delete('test.com', '127.0.0.1', 'A')
  32. assert_equal(@updater.commands.size, 1, 'command size not == 1')
  33. assert_equal(@updater.commands[0], 'update delete test.com. A 127.0.0.1')
  34. @updater.delete('ipv6.test.com', '2001:dead::beef', 'AAAA')
  35. assert_equal(@updater.commands.size, 2, 'command size not == 2')
  36. assert_equal(@updater.commands[1], 'update delete ipv6.test.com. AAAA 2001:dead::beef')
  37. end
  38. def test_delete_all
  39. @updater.delete_all([ 'test.com', 'test2.com' ], '127.0.0.1', 'A')
  40. assert_equal(@updater.commands.size, 2, 'command size not == 2')
  41. assert_equal(@updater.commands[0], 'update delete test.com. A 127.0.0.1')
  42. assert_equal(@updater.commands[1], 'update delete test2.com. A 127.0.0.1')
  43. end
  44. def test_order
  45. @updater.add('test.com', '127.0.0.1', 'A', 1000)
  46. @updater.delete('ipv6.test.com', '2001:dead::beef', 'AAAA')
  47. assert_equal(@updater.commands.size, 2, 'command size not == 2')
  48. assert_equal(@updater.commands[0], 'update add test.com. 1000 A 127.0.0.1', 'messages not in order')
  49. assert_equal(@updater.commands[1], 'update delete ipv6.test.com. AAAA 2001:dead::beef', 'messages not in order')
  50. end
  51. def test_send_commands
  52. updater = DnsUpdaterProxy.new(nil, nil, 'test.server')
  53. read, write = IO.pipe
  54. updater.add('test.com', '127.0.0.1', 'A', 1000)
  55. updater.delete('ipv6.test.com', '2001:dead::beef', 'AAAA')
  56. updater.send_commands(write)
  57. write.close
  58. lines = read.readlines
  59. assert_equal(lines[0].rstrip, 'server test.server')
  60. assert_equal(lines[1].rstrip, 'update add test.com. 1000 A 127.0.0.1')
  61. assert_equal(lines[2].rstrip, 'update delete ipv6.test.com. AAAA 2001:dead::beef')
  62. assert_equal(lines[3].rstrip, 'send')
  63. assert_equal(lines[4].rstrip, 'quit')
  64. end
  65. end