1
0
Fork 0
mirror of https://github.com/capistrano/capistrano synced 2023-03-27 23:21:18 -04:00

Compare servers by user, hostname and port

To check if servers match compare them by
user, hostname and port.
This commit is contained in:
Pavel Shpak 2014-02-02 23:05:33 +03:00
parent aeab6b6a1e
commit 0bee4f6fb8
4 changed files with 26 additions and 19 deletions

View file

@ -51,7 +51,7 @@ module Capistrano
end
def matches?(other)
hostname == other.hostname && port == other.port
user == other.user && hostname == other.hostname && port == other.port
end
private

View file

@ -201,16 +201,18 @@ describe Capistrano::DSL do
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 @@ describe Capistrano::DSL do
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

View file

@ -3,7 +3,7 @@ require 'spec_helper'
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 @@ module Capistrano
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

View file

@ -106,10 +106,15 @@ module Capistrano
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