| 1 |
require "#{File.dirname(__FILE__)}/utils" |
|---|
| 2 |
require 'capistrano/server_definition' |
|---|
| 3 |
|
|---|
| 4 |
class ServerDefinitionTest < Test::Unit::TestCase |
|---|
| 5 |
def test_new_without_credentials_or_port_should_set_values_to_defaults |
|---|
| 6 |
server = Capistrano::ServerDefinition.new("www.capistrano.test") |
|---|
| 7 |
assert_equal "www.capistrano.test", server.host |
|---|
| 8 |
assert_nil server.user |
|---|
| 9 |
assert_nil server.port |
|---|
| 10 |
end |
|---|
| 11 |
|
|---|
| 12 |
def test_new_with_encoded_user_should_extract_user_and_use_default_port |
|---|
| 13 |
server = Capistrano::ServerDefinition.new("jamis@www.capistrano.test") |
|---|
| 14 |
assert_equal "www.capistrano.test", server.host |
|---|
| 15 |
assert_equal "jamis", server.user |
|---|
| 16 |
assert_nil server.port |
|---|
| 17 |
end |
|---|
| 18 |
|
|---|
| 19 |
def test_new_with_encoded_port_should_extract_port_and_use_default_user |
|---|
| 20 |
server = Capistrano::ServerDefinition.new("www.capistrano.test:8080") |
|---|
| 21 |
assert_equal "www.capistrano.test", server.host |
|---|
| 22 |
assert_nil server.user |
|---|
| 23 |
assert_equal 8080, server.port |
|---|
| 24 |
end |
|---|
| 25 |
|
|---|
| 26 |
def test_new_with_encoded_user_and_port_should_extract_user_and_port |
|---|
| 27 |
server = Capistrano::ServerDefinition.new("jamis@www.capistrano.test:8080") |
|---|
| 28 |
assert_equal "www.capistrano.test", server.host |
|---|
| 29 |
assert_equal "jamis", server.user |
|---|
| 30 |
assert_equal 8080, server.port |
|---|
| 31 |
end |
|---|
| 32 |
|
|---|
| 33 |
def test_new_with_user_as_option_should_use_given_user |
|---|
| 34 |
server = Capistrano::ServerDefinition.new("www.capistrano.test", :user => "jamis") |
|---|
| 35 |
assert_equal "www.capistrano.test", server.host |
|---|
| 36 |
assert_equal "jamis", server.user |
|---|
| 37 |
assert_nil server.port |
|---|
| 38 |
end |
|---|
| 39 |
|
|---|
| 40 |
def test_new_with_port_as_option_should_use_given_user |
|---|
| 41 |
server = Capistrano::ServerDefinition.new("www.capistrano.test", :port => 8080) |
|---|
| 42 |
assert_equal "www.capistrano.test", server.host |
|---|
| 43 |
assert_nil server.user |
|---|
| 44 |
assert_equal 8080, server.port |
|---|
| 45 |
end |
|---|
| 46 |
|
|---|
| 47 |
def test_encoded_value_should_override_hash_option |
|---|
| 48 |
server = Capistrano::ServerDefinition.new("jamis@www.capistrano.test:8080", :user => "david", :port => 8081) |
|---|
| 49 |
assert_equal "www.capistrano.test", server.host |
|---|
| 50 |
assert_equal "jamis", server.user |
|---|
| 51 |
assert_equal 8080, server.port |
|---|
| 52 |
assert server.options.empty? |
|---|
| 53 |
end |
|---|
| 54 |
|
|---|
| 55 |
def test_new_with_option_should_dup_option_hash |
|---|
| 56 |
options = {} |
|---|
| 57 |
server = Capistrano::ServerDefinition.new("www.capistrano.test", options) |
|---|
| 58 |
assert_not_equal options.object_id, server.options.object_id |
|---|
| 59 |
end |
|---|
| 60 |
|
|---|
| 61 |
def test_new_with_options_should_keep_options |
|---|
| 62 |
server = Capistrano::ServerDefinition.new("www.capistrano.test", :primary => true) |
|---|
| 63 |
assert_equal true, server.options[:primary] |
|---|
| 64 |
end |
|---|
| 65 |
|
|---|
| 66 |
def test_comparison_should_match_when_host_user_port_are_same |
|---|
| 67 |
s1 = server("jamis@www.capistrano.test:8080") |
|---|
| 68 |
s2 = server("www.capistrano.test", :user => "jamis", :port => 8080) |
|---|
| 69 |
assert_equal s1, s2 |
|---|
| 70 |
assert_equal s1.hash, s2.hash |
|---|
| 71 |
assert s1.eql?(s2) |
|---|
| 72 |
end |
|---|
| 73 |
|
|---|
| 74 |
def test_servers_should_be_comparable |
|---|
| 75 |
s1 = server("jamis@www.capistrano.test:8080") |
|---|
| 76 |
s2 = server("www.alphabet.test:1234") |
|---|
| 77 |
s3 = server("jamis@www.capistrano.test:8075") |
|---|
| 78 |
s4 = server("billy@www.capistrano.test:8080") |
|---|
| 79 |
|
|---|
| 80 |
assert s2 < s1 |
|---|
| 81 |
assert s3 < s1 |
|---|
| 82 |
assert s4 < s1 |
|---|
| 83 |
assert s2 < s3 |
|---|
| 84 |
assert s2 < s4 |
|---|
| 85 |
assert s3 < s4 |
|---|
| 86 |
end |
|---|
| 87 |
|
|---|
| 88 |
def test_comparison_should_not_match_when_any_of_host_user_port_differ |
|---|
| 89 |
s1 = server("jamis@www.capistrano.test:8080") |
|---|
| 90 |
s2 = server("bob@www.capistrano.test:8080") |
|---|
| 91 |
s3 = server("jamis@www.capistrano.test:8081") |
|---|
| 92 |
s4 = server("jamis@app.capistrano.test:8080") |
|---|
| 93 |
assert_not_equal s1, s2 |
|---|
| 94 |
assert_not_equal s1, s3 |
|---|
| 95 |
assert_not_equal s1, s4 |
|---|
| 96 |
assert_not_equal s2, s3 |
|---|
| 97 |
assert_not_equal s2, s4 |
|---|
| 98 |
assert_not_equal s3, s4 |
|---|
| 99 |
end |
|---|
| 100 |
|
|---|
| 101 |
def test_to_s |
|---|
| 102 |
assert_equal "www.capistrano.test", server("www.capistrano.test").to_s |
|---|
| 103 |
assert_equal "www.capistrano.test", server("www.capistrano.test:22").to_s |
|---|
| 104 |
assert_equal "www.capistrano.test:1234", server("www.capistrano.test:1234").to_s |
|---|
| 105 |
assert_equal "jamis@www.capistrano.test", server("jamis@www.capistrano.test").to_s |
|---|
| 106 |
assert_equal "jamis@www.capistrano.test:1234", server("jamis@www.capistrano.test:1234").to_s |
|---|
| 107 |
end |
|---|
| 108 |
end |
|---|