2011-08-09 13:45:36 +00:00
|
|
|
require './test/test_helper'
|
|
|
|
|
|
|
|
class NodeTest < Test::Unit::TestCase
|
2011-08-25 16:56:06 +00:00
|
|
|
|
|
|
|
def setup
|
|
|
|
@connection = mock()
|
|
|
|
end
|
|
|
|
|
2011-08-09 13:45:36 +00:00
|
|
|
should "load a node from an array" do
|
2011-08-25 16:56:06 +00:00
|
|
|
node = Node.new(@connection, ['power.level.com', 9001])
|
2011-08-09 13:45:36 +00:00
|
|
|
assert_equal 'power.level.com', node.host
|
|
|
|
assert_equal 9001, node.port
|
|
|
|
assert_equal 'power.level.com:9001', node.address
|
|
|
|
end
|
2011-08-25 16:56:06 +00:00
|
|
|
|
2011-08-09 13:45:36 +00:00
|
|
|
should "should default the port for an array" do
|
2011-08-25 16:56:06 +00:00
|
|
|
node = Node.new(@connection, ['power.level.com'])
|
2011-08-09 13:45:36 +00:00
|
|
|
assert_equal 'power.level.com', node.host
|
|
|
|
assert_equal Connection::DEFAULT_PORT, node.port
|
|
|
|
assert_equal "power.level.com:#{Connection::DEFAULT_PORT}", node.address
|
|
|
|
end
|
2011-08-25 16:56:06 +00:00
|
|
|
|
2011-08-25 18:57:24 +00:00
|
|
|
should "load a node from a string" do
|
2011-08-25 16:56:06 +00:00
|
|
|
node = Node.new(@connection, 'localhost:1234')
|
2011-08-09 13:45:36 +00:00
|
|
|
assert_equal 'localhost', node.host
|
|
|
|
assert_equal 1234, node.port
|
|
|
|
assert_equal 'localhost:1234', node.address
|
|
|
|
end
|
2011-08-25 16:56:06 +00:00
|
|
|
|
2011-08-09 13:45:36 +00:00
|
|
|
should "should default the port for a string" do
|
2011-08-25 16:56:06 +00:00
|
|
|
node = Node.new(@connection, '192.168.0.1')
|
2011-08-09 13:45:36 +00:00
|
|
|
assert_equal '192.168.0.1', node.host
|
|
|
|
assert_equal Connection::DEFAULT_PORT, node.port
|
|
|
|
assert_equal "192.168.0.1:#{Connection::DEFAULT_PORT}", node.address
|
|
|
|
end
|
2011-08-25 16:56:06 +00:00
|
|
|
|
2011-08-09 13:45:36 +00:00
|
|
|
should "two nodes with the same address should be equal" do
|
2011-08-25 16:56:06 +00:00
|
|
|
assert_equal Node.new(@connection, '192.168.0.1'),
|
|
|
|
Node.new(@connection, ['192.168.0.1', Connection::DEFAULT_PORT])
|
2011-08-09 13:45:36 +00:00
|
|
|
end
|
2011-08-25 16:56:06 +00:00
|
|
|
|
2011-08-09 13:45:36 +00:00
|
|
|
should "two nodes with the same address should have the same hash" do
|
2011-08-25 16:56:06 +00:00
|
|
|
assert_equal Node.new(@connection, '192.168.0.1').hash,
|
|
|
|
Node.new(@connection, ['192.168.0.1', Connection::DEFAULT_PORT]).hash
|
2011-08-09 13:45:36 +00:00
|
|
|
end
|
2011-08-25 16:56:06 +00:00
|
|
|
|
2011-08-09 13:45:36 +00:00
|
|
|
should "two nodes with different addresses should not be equal" do
|
2011-08-25 16:56:06 +00:00
|
|
|
assert_not_equal Node.new(@connection, '192.168.0.2'),
|
|
|
|
Node.new(@connection, ['192.168.0.1', Connection::DEFAULT_PORT])
|
2011-08-09 13:45:36 +00:00
|
|
|
end
|
2011-08-25 16:56:06 +00:00
|
|
|
|
2011-08-09 13:45:36 +00:00
|
|
|
should "two nodes with the same address should have the same hash" do
|
2011-08-25 16:56:06 +00:00
|
|
|
assert_not_equal Node.new(@connection, '192.168.0.1').hash,
|
|
|
|
Node.new(@connection, '1239.33.4.2393:29949').hash
|
2011-08-09 13:45:36 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|