Permalink
Browse files

Compare servers by user, hostname and port

To check if servers match compare them by
user, hostname and port.
  • Loading branch information...
1 parent aeab6b6 commit 0bee4f6fb8dde090516a0669121605e237f12480 @ShPakvel ShPakvel committed Feb 2, 2014
@@ -51,7 +51,7 @@ def roles_array
end
def matches?(other)
- hostname == other.hostname && port == other.port
+ user == other.user && hostname == other.hostname && port == other.port
end
private
@@ -201,16 +201,18 @@
describe 'when defining a host using a combination of the `server` and `role` syntax' do
before do
- dsl.server 'example1.com:1234', roles: %w{web}, active: true
+ dsl.server 'db@example1.com:1234', roles: %w{db}, active: true
+ dsl.server 'root@example1.com:1234', roles: %w{web}, active: true
dsl.server 'example1.com:5678', roles: %w{web}, active: true
+ dsl.role :app, %w{deployer@example1.com:1234}
dsl.role :app, %w{example1.com:5678}
end
describe 'fetching all servers' do
- subject { dsl.roles(:all).map { |server| "#{server.hostname}:#{server.port}" } }
+ subject { dsl.roles(:all).map { |server| "#{server.user}@#{server.hostname}:#{server.port}" } }
- it 'creates a server instance for each unique host:port combination' do
- expect(subject).to eq %w{example1.com:1234 example1.com:5678}
+ it 'creates a server instance for each unique user@host:port combination' do
+ expect(subject).to eq %w{db@example1.com:1234 root@example1.com:1234 @example1.com:5678 deployer@example1.com:1234}
end
end
@@ -220,7 +222,7 @@
end
it 'roles defined using the `role` syntax are included' do
- expect(dsl.roles(:app)).to have(1).items
+ expect(dsl.roles(:app)).to have(2).items
end
end
@@ -3,7 +3,7 @@
module Capistrano
class Configuration
describe Server do
- let(:server) { Server.new('hostname:1234') }
+ let(:server) { Server.new('root@hostname:1234') }
describe 'adding a role' do
subject { server.add_role(:test) }
@@ -35,23 +35,23 @@ class Configuration
describe 'comparing identity' do
subject { server.matches? Server[hostname] }
- context 'with the same hostname' do
- let(:hostname) { 'hostname:1234' }
+ context 'with the same user, hostname and port' do
+ let(:hostname) { 'root@hostname:1234' }
it { should be_true }
end
- context 'with the same hostname and a user' do
- let(:hostname) { 'user@hostname:1234' }
- it { should be_true }
+ context 'with a different user' do
+ let(:hostname) { 'deployer@hostname:1234' }
+ it { should be_false }
end
- context 'with the same hostname but different port' do
- let(:hostname) { 'hostname:5678' }
+ context 'with a different port' do
+ let(:hostname) { 'root@hostname:5678' }
it { should be_false }
end
context 'with a different hostname' do
- let(:hostname) { 'otherserver' }
+ let(:hostname) { 'root@otherserver:1234' }
it { should be_false }
end
end
@@ -106,10 +106,15 @@ class Configuration
expect(servers.roles_for([:all]).first.properties.test).to eq :value
end
- it 'can accept multiple servers with the same hostname but different ports' do
- servers.add_host('2', roles: [:app, 'web'], test: :value, port: 12)
- servers.add_host('2', roles: [:app, 'web'], test: :value, port: 34)
- expect(servers.count { |server| server.hostname == '2' }).to eq 2
+ it 'can accept multiple servers with the same hostname but different ports or users' do
+ servers.add_host('1', roles: [:app, 'web'], test: :value, port: 12)
+ servers.add_host('1', roles: [:app, 'web'], test: :value, port: 34)
+ servers.add_host('1', roles: [:app, 'web'], test: :value, user: 'root')
+ servers.add_host('1', roles: [:app, 'web'], test: :value, user: 'deployer')
+ servers.add_host('1', roles: [:app, 'web'], test: :value, user: 'root', port: 34)
+ servers.add_host('1', roles: [:app, 'web'], test: :value, user: 'deployer', port: 34)
+ servers.add_host('1', roles: [:app, 'web'], test: :value, user: 'deployer', port: 56)
+ servers.should have(8).items
end
end

0 comments on commit 0bee4f6

Please sign in to comment.