test_server.rb 895 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. require 'atto'
  2. include Atto::Test
  3. require_relative '../../lib/woe/client'
  4. require_relative '../../lib/woe/server'
  5. assert { Woe::Server }
  6. # Fork off the server so the Net::Telnet tests can procede
  7. pid = Process.fork do
  8. Woe::Server.new
  9. sleep
  10. # exit here to ge
  11. puts __FILE__ + ' Server Done'
  12. exit 0
  13. end
  14. p pid
  15. assert { pid }
  16. require 'net/telnet'
  17. assert do
  18. sleep 1
  19. client = Net::Telnet.new('Host' => 'localhost', 'Port' => 7000,
  20. 'Timeout' => 3)
  21. res = client.waitfor(/Login:/)
  22. client.write("Axl\n")
  23. client.waitfor(/.*/)
  24. client.write("pass\n")
  25. client.waitfor(/.*/)
  26. client.write("hello\n")
  27. client.waitfor(/.*/)
  28. client.write("/quit\n")
  29. client.waitfor(/.*/)
  30. client.close
  31. ok = !!client
  32. ok
  33. end
  34. # Finally stop the server and wait for it to finish
  35. Process.kill(:TERM, pid)
  36. Process.wait(pid)
  37. puts __FILE__ + ' Tests Done'