2016-02-28 18:16:11 -05:00
|
|
|
require "spec_helper"
|
2013-06-02 07:30:11 -04:00
|
|
|
|
|
|
|
describe Capistrano::DSL do
|
|
|
|
let(:dsl) { Class.new.extend Capistrano::DSL }
|
|
|
|
|
2013-11-21 11:35:46 -05:00
|
|
|
before do
|
|
|
|
Capistrano::Configuration.reset!
|
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
describe "setting and fetching hosts" do
|
|
|
|
describe "when defining a host using the `server` syntax" do
|
2013-06-02 07:30:11 -04:00
|
|
|
before do
|
2016-02-28 18:16:11 -05:00
|
|
|
dsl.server "example1.com", :roles => %w{web}, :active => true
|
|
|
|
dsl.server "example2.com", :roles => %w{web}
|
|
|
|
dsl.server "example3.com", :roles => %w{app web}, :active => true
|
|
|
|
dsl.server "example4.com", :roles => %w{app}, :primary => true
|
|
|
|
dsl.server "example5.com", :roles => %w{db}, :no_release => true, :active => true
|
2013-06-02 07:30:11 -04:00
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
describe "fetching all servers" do
|
2013-06-16 08:08:15 -04:00
|
|
|
subject { dsl.roles(:all) }
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
it "returns all servers" do
|
2013-10-18 06:25:59 -04:00
|
|
|
expect(subject.map(&:hostname)).to eq %w{example1.com example2.com example3.com example4.com example5.com}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
describe "fetching all release servers" do
|
|
|
|
context "with no additional options" do
|
2013-10-18 06:25:59 -04:00
|
|
|
subject { dsl.release_roles(:all) }
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
it "returns all release servers" do
|
2013-10-18 06:25:59 -04:00
|
|
|
expect(subject.map(&:hostname)).to eq %w{example1.com example2.com example3.com example4.com}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
context "with property filter options" do
|
2016-02-28 18:14:50 -05:00
|
|
|
subject { dsl.release_roles(:all, :filter => :active) }
|
2013-10-18 06:25:59 -04:00
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
it "returns all release servers that match the property filter" do
|
2013-10-18 06:25:59 -04:00
|
|
|
expect(subject.map(&:hostname)).to eq %w{example1.com example3.com}
|
|
|
|
end
|
2013-06-16 08:08:15 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
describe "fetching servers by multiple roles" do
|
2013-07-05 10:21:53 -04:00
|
|
|
it "does not confuse the last role with options" do
|
|
|
|
expect(dsl.roles(:app, :web).count).to eq 4
|
2016-02-28 18:14:50 -05:00
|
|
|
expect(dsl.roles(:app, :web, :filter => :active).count).to eq 2
|
2013-07-05 10:21:53 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
describe "fetching servers by role" do
|
2013-06-02 07:30:11 -04:00
|
|
|
subject { dsl.roles(:app) }
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
it "returns the servers" do
|
2013-06-02 07:30:11 -04:00
|
|
|
expect(subject.map(&:hostname)).to eq %w{example3.com example4.com}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
describe "fetching servers by an array of roles" do
|
2013-11-22 10:49:37 -05:00
|
|
|
subject { dsl.roles([:app]) }
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
it "returns the servers" do
|
2013-11-22 10:49:37 -05:00
|
|
|
expect(subject.map(&:hostname)).to eq %w{example3.com example4.com}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
describe "fetching filtered servers by role" do
|
2016-02-28 18:14:50 -05:00
|
|
|
subject { dsl.roles(:app, :filter => :active) }
|
2013-06-02 07:30:11 -04:00
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
it "returns the servers" do
|
2013-06-02 07:30:11 -04:00
|
|
|
expect(subject.map(&:hostname)).to eq %w{example3.com}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
describe "fetching selected servers by role" do
|
2016-02-28 18:14:50 -05:00
|
|
|
subject { dsl.roles(:app, :select => :active) }
|
2013-06-02 07:30:11 -04:00
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
it "returns the servers" do
|
2013-06-02 07:30:11 -04:00
|
|
|
expect(subject.map(&:hostname)).to eq %w{example3.com}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
describe "fetching the primary server by role" do
|
|
|
|
context "when inferring primary status based on order" do
|
2013-06-02 07:30:11 -04:00
|
|
|
subject { dsl.primary(:web) }
|
2016-02-28 18:16:11 -05:00
|
|
|
it "returns the servers" do
|
|
|
|
expect(subject.hostname).to eq "example1.com"
|
2013-06-02 07:30:11 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
context "when the attribute `primary` is explicitly set" do
|
2013-06-02 07:30:11 -04:00
|
|
|
subject { dsl.primary(:app) }
|
2016-02-28 18:16:11 -05:00
|
|
|
it "returns the servers" do
|
|
|
|
expect(subject.hostname).to eq "example4.com"
|
2013-06-02 07:30:11 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
describe "setting an internal host filter" do
|
2014-09-14 14:53:02 -04:00
|
|
|
subject { dsl.roles(:app) }
|
2016-02-28 18:16:11 -05:00
|
|
|
it "is ignored" do
|
2016-02-28 18:32:33 -05:00
|
|
|
dsl.set :filter, :host => "example3.com"
|
2016-02-28 18:16:11 -05:00
|
|
|
expect(subject.map(&:hostname)).to eq(["example3.com", "example4.com"])
|
2014-09-14 14:53:02 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
describe "setting an internal role filter" do
|
2014-09-14 14:53:02 -04:00
|
|
|
subject { dsl.roles(:app) }
|
2016-02-28 18:16:11 -05:00
|
|
|
it "ignores it" do
|
2016-02-28 18:32:33 -05:00
|
|
|
dsl.set :filter, :role => :web
|
2016-03-01 10:02:00 -05:00
|
|
|
expect(subject.map(&:hostname)).to eq(["example3.com", "example4.com"])
|
2014-09-14 14:53:02 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
describe "setting an internal host and role filter" do
|
2014-09-14 14:53:02 -04:00
|
|
|
subject { dsl.roles(:app) }
|
2016-02-28 18:16:11 -05:00
|
|
|
it "ignores it" do
|
2016-02-28 18:32:33 -05:00
|
|
|
dsl.set :filter, :role => :web, :host => "example1.com"
|
2016-03-01 10:02:00 -05:00
|
|
|
expect(subject.map(&:hostname)).to eq(["example3.com", "example4.com"])
|
2014-09-14 14:53:02 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
describe "setting an internal regexp host filter" do
|
2014-09-14 14:53:02 -04:00
|
|
|
subject { dsl.roles(:all) }
|
2016-02-28 18:16:11 -05:00
|
|
|
it "is ignored" do
|
2016-02-28 18:32:33 -05:00
|
|
|
dsl.set :filter, :host => /1/
|
2014-09-24 23:12:14 -04:00
|
|
|
expect(subject.map(&:hostname)).to eq(%w{example1.com example2.com example3.com example4.com example5.com})
|
2014-09-14 14:53:02 -04:00
|
|
|
end
|
|
|
|
end
|
2014-09-24 23:12:14 -04:00
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
describe "setting an internal hosts filter" do
|
2015-07-16 19:03:20 -04:00
|
|
|
subject { dsl.roles(:app) }
|
2016-02-28 18:16:11 -05:00
|
|
|
it "is ignored" do
|
2016-02-28 18:32:33 -05:00
|
|
|
dsl.set :filter, :hosts => "example3.com"
|
2016-02-28 18:16:11 -05:00
|
|
|
expect(subject.map(&:hostname)).to eq(["example3.com", "example4.com"])
|
2015-07-16 19:03:20 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
describe "setting an internal roles filter" do
|
2015-07-16 19:03:20 -04:00
|
|
|
subject { dsl.roles(:app) }
|
2016-02-28 18:16:11 -05:00
|
|
|
it "ignores it" do
|
2016-02-28 18:32:33 -05:00
|
|
|
dsl.set :filter, :roles => :web
|
2016-03-01 10:02:00 -05:00
|
|
|
expect(subject.map(&:hostname)).to eq(["example3.com", "example4.com"])
|
2015-07-16 19:03:20 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
describe "setting an internal hosts and roles filter" do
|
2015-07-16 19:03:20 -04:00
|
|
|
subject { dsl.roles(:app) }
|
2016-02-28 18:16:11 -05:00
|
|
|
it "ignores it" do
|
2016-02-28 18:32:33 -05:00
|
|
|
dsl.set :filter, :roles => :web, :hosts => "example1.com"
|
2016-03-01 10:02:00 -05:00
|
|
|
expect(subject.map(&:hostname)).to eq(["example3.com", "example4.com"])
|
2015-07-16 19:03:20 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
describe "setting an internal regexp hosts filter" do
|
2015-07-16 19:03:20 -04:00
|
|
|
subject { dsl.roles(:all) }
|
2016-02-28 18:16:11 -05:00
|
|
|
it "is ignored" do
|
2016-02-28 18:32:33 -05:00
|
|
|
dsl.set :filter, :hosts => /1/
|
2015-07-16 19:03:20 -04:00
|
|
|
expect(subject.map(&:hostname)).to eq(%w{example1.com example2.com example3.com example4.com example5.com})
|
|
|
|
end
|
|
|
|
end
|
2013-06-02 07:30:11 -04:00
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
describe "when defining role with reserved name" do
|
|
|
|
it "fails with ArgumentError" do
|
2013-10-17 06:38:48 -04:00
|
|
|
expect {
|
|
|
|
dsl.role :all, %w{example1.com}
|
|
|
|
}.to raise_error(ArgumentError, "all reserved name for role. Please choose another name")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
describe "when defining hosts using the `role` syntax" do
|
2013-06-02 07:30:11 -04:00
|
|
|
before do
|
|
|
|
dsl.role :web, %w{example1.com example2.com example3.com}
|
2016-02-28 18:14:50 -05:00
|
|
|
dsl.role :web, %w{example1.com}, :active => true
|
2013-06-02 07:30:11 -04:00
|
|
|
dsl.role :app, %w{example3.com example4.com}
|
2016-02-28 18:14:50 -05:00
|
|
|
dsl.role :app, %w{example3.com}, :active => true
|
|
|
|
dsl.role :app, %w{example4.com}, :primary => true
|
|
|
|
dsl.role :db, %w{example5.com}, :no_release => true
|
2013-06-02 07:30:11 -04:00
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
describe "fetching all servers" do
|
2013-06-16 08:08:15 -04:00
|
|
|
subject { dsl.roles(:all) }
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
it "returns all servers" do
|
2013-10-18 06:25:59 -04:00
|
|
|
expect(subject.map(&:hostname)).to eq %w{example1.com example2.com example3.com example4.com example5.com}
|
2013-06-16 08:08:15 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
describe "fetching all release servers" do
|
|
|
|
context "with no additional options" do
|
2013-10-18 06:25:59 -04:00
|
|
|
subject { dsl.release_roles(:all) }
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
it "returns all release servers" do
|
2013-10-18 06:25:59 -04:00
|
|
|
expect(subject.map(&:hostname)).to eq %w{example1.com example2.com example3.com example4.com}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
context "with filter options" do
|
2016-02-28 18:14:50 -05:00
|
|
|
subject { dsl.release_roles(:all, :filter => :active) }
|
2013-10-18 06:25:59 -04:00
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
it "returns all release servers that match the filter" do
|
2013-10-18 06:25:59 -04:00
|
|
|
expect(subject.map(&:hostname)).to eq %w{example1.com example3.com}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
describe "fetching servers by role" do
|
2013-06-02 07:30:11 -04:00
|
|
|
subject { dsl.roles(:app) }
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
it "returns the servers" do
|
2013-06-02 07:30:11 -04:00
|
|
|
expect(subject.map(&:hostname)).to eq %w{example3.com example4.com}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
describe "fetching servers by an array of roles" do
|
2013-11-22 10:49:37 -05:00
|
|
|
subject { dsl.roles([:app]) }
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
it "returns the servers" do
|
2013-11-22 10:49:37 -05:00
|
|
|
expect(subject.map(&:hostname)).to eq %w{example3.com example4.com}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
describe "fetching filtered servers by role" do
|
2016-02-28 18:14:50 -05:00
|
|
|
subject { dsl.roles(:app, :filter => :active) }
|
2013-06-02 07:30:11 -04:00
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
it "returns the servers" do
|
2013-06-02 07:30:11 -04:00
|
|
|
expect(subject.map(&:hostname)).to eq %w{example3.com}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
describe "fetching selected servers by role" do
|
2016-02-28 18:14:50 -05:00
|
|
|
subject { dsl.roles(:app, :select => :active) }
|
2013-06-02 07:30:11 -04:00
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
it "returns the servers" do
|
2013-06-02 07:30:11 -04:00
|
|
|
expect(subject.map(&:hostname)).to eq %w{example3.com}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
describe "fetching the primary server by role" do
|
|
|
|
context "when inferring primary status based on order" do
|
2013-06-02 07:30:11 -04:00
|
|
|
subject { dsl.primary(:web) }
|
2016-02-28 18:16:11 -05:00
|
|
|
it "returns the servers" do
|
|
|
|
expect(subject.hostname).to eq "example1.com"
|
2013-06-02 07:30:11 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
context "when the attribute `primary` is explicity set" do
|
2013-06-02 07:30:11 -04:00
|
|
|
subject { dsl.primary(:app) }
|
2016-02-28 18:16:11 -05:00
|
|
|
it "returns the servers" do
|
|
|
|
expect(subject.hostname).to eq "example4.com"
|
2013-06-02 07:30:11 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
describe "when defining a host using a combination of the `server` and `role` syntax" do
|
2013-11-21 11:35:46 -05:00
|
|
|
before do
|
2016-02-28 18:16:11 -05:00
|
|
|
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
|
2014-02-02 15:05:33 -05:00
|
|
|
dsl.role :app, %w{deployer@example1.com:1234}
|
2013-11-21 11:35:46 -05:00
|
|
|
dsl.role :app, %w{example1.com:5678}
|
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
describe "fetching all servers" do
|
|
|
|
it "creates one server per hostname, ignoring user combinations" do
|
2015-09-10 11:09:23 -04:00
|
|
|
expect(dsl.roles(:all).size).to eq(2)
|
2013-11-21 11:35:46 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
describe "fetching servers for a role" do
|
|
|
|
it "roles defined using the `server` syntax are included" do
|
2015-02-06 13:24:59 -05:00
|
|
|
as = dsl.roles(:web).map { |server| "#{server.user}@#{server.hostname}:#{server.port}" }
|
2015-09-10 11:09:23 -04:00
|
|
|
expect(as.size).to eq(2)
|
|
|
|
expect(as[0]).to eq("deployer@example1.com:1234")
|
|
|
|
expect(as[1]).to eq("@example1.com:5678")
|
2013-11-21 11:35:46 -05:00
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
it "roles defined using the `role` syntax are included" do
|
2015-02-06 13:24:59 -05:00
|
|
|
as = dsl.roles(:app).map { |server| "#{server.user}@#{server.hostname}:#{server.port}" }
|
2015-09-10 11:09:23 -04:00
|
|
|
expect(as.size).to eq(2)
|
|
|
|
expect(as[0]).to eq("deployer@example1.com:1234")
|
|
|
|
expect(as[1]).to eq("@example1.com:5678")
|
2013-11-21 11:35:46 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
describe "when setting user and port" do
|
2015-02-06 13:24:59 -05:00
|
|
|
subject { dsl.roles(:all).map { |server| "#{server.user}@#{server.hostname}:#{server.port}" }.first }
|
|
|
|
|
|
|
|
describe "using the :user property" do
|
|
|
|
it "takes precedence over in the host string" do
|
2016-02-28 18:16:11 -05:00
|
|
|
dsl.server "db@example1.com:1234", :roles => %w{db}, :active => true, :user => "brian"
|
2015-02-06 13:24:59 -05:00
|
|
|
expect(subject).to eq("brian@example1.com:1234")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "using the :port property" do
|
|
|
|
it "takes precedence over in the host string" do
|
2016-02-28 18:16:11 -05:00
|
|
|
dsl.server "db@example1.com:9090", :roles => %w{db}, :active => true, :port => 1234
|
2015-02-06 13:24:59 -05:00
|
|
|
expect(subject).to eq("db@example1.com:1234")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-06-02 07:30:11 -04:00
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
describe "setting and fetching variables" do
|
2013-06-02 07:30:11 -04:00
|
|
|
before do
|
|
|
|
dsl.set :scm, :git
|
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
context "without a default" do
|
|
|
|
context "when the variables is defined" do
|
|
|
|
it "returns the variable" do
|
2013-06-02 07:30:11 -04:00
|
|
|
expect(dsl.fetch(:scm)).to eq :git
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
context "when the variables is undefined" do
|
|
|
|
it "returns nil" do
|
2013-06-02 07:30:11 -04:00
|
|
|
expect(dsl.fetch(:source_control)).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
context "with a default" do
|
|
|
|
context "when the variables is defined" do
|
|
|
|
it "returns the variable" do
|
2013-06-02 07:30:11 -04:00
|
|
|
expect(dsl.fetch(:scm, :svn)).to eq :git
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
context "when the variables is undefined" do
|
|
|
|
it "returns the default" do
|
2013-06-02 07:30:11 -04:00
|
|
|
expect(dsl.fetch(:source_control, :svn)).to eq :svn
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
context "with a block" do
|
|
|
|
context "when the variables is defined" do
|
|
|
|
it "returns the variable" do
|
2013-08-09 09:15:50 -04:00
|
|
|
expect(dsl.fetch(:scm) { :svn }).to eq :git
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
context "when the variables is undefined" do
|
|
|
|
it "calls the block" do
|
2013-08-09 09:15:50 -04:00
|
|
|
expect(dsl.fetch(:source_control) { :svn }).to eq :svn
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-06-02 07:30:11 -04:00
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
describe "asking for a variable" do
|
2013-06-02 07:30:11 -04:00
|
|
|
before do
|
|
|
|
dsl.ask(:scm, :svn)
|
2014-04-15 18:11:10 -04:00
|
|
|
$stdout.stubs(:print)
|
2013-06-02 07:30:11 -04:00
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
context "variable is provided" do
|
2013-06-02 07:30:11 -04:00
|
|
|
before do
|
2016-02-28 18:16:11 -05:00
|
|
|
$stdin.expects(:gets).returns("git")
|
2013-06-02 07:30:11 -04:00
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
it "sets the input as the variable" do
|
|
|
|
expect(dsl.fetch(:scm)).to eq "git"
|
2013-06-02 07:30:11 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
context "variable is not provided" do
|
2013-06-02 07:30:11 -04:00
|
|
|
before do
|
2016-02-28 18:16:11 -05:00
|
|
|
$stdin.expects(:gets).returns("")
|
2013-06-02 07:30:11 -04:00
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
it "sets the variable as the default" do
|
2013-06-02 07:30:11 -04:00
|
|
|
expect(dsl.fetch(:scm)).to eq :svn
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
describe "checking for presence" do
|
2013-06-02 07:30:11 -04:00
|
|
|
subject { dsl.any? :linked_files }
|
|
|
|
|
|
|
|
before do
|
|
|
|
dsl.set(:linked_files, linked_files)
|
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
context "variable is an non-empty array" do
|
2013-06-02 07:30:11 -04:00
|
|
|
let(:linked_files) { %w{1} }
|
|
|
|
|
2014-08-12 14:52:37 -04:00
|
|
|
it { expect(subject).to be_truthy }
|
2013-06-02 07:30:11 -04:00
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
context "variable is an empty array" do
|
2013-06-02 07:30:11 -04:00
|
|
|
let(:linked_files) { [] }
|
2014-08-12 14:52:37 -04:00
|
|
|
it { expect(subject).to be_falsey }
|
2013-06-02 07:30:11 -04:00
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
context "variable exists, is not an array" do
|
2013-06-02 07:30:11 -04:00
|
|
|
let(:linked_files) { stub }
|
2014-08-12 14:52:37 -04:00
|
|
|
it { expect(subject).to be_truthy }
|
2013-06-02 07:30:11 -04:00
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
context "variable is nil" do
|
2013-06-02 07:30:11 -04:00
|
|
|
let(:linked_files) { nil }
|
2014-08-12 14:52:37 -04:00
|
|
|
it { expect(subject).to be_falsey }
|
2013-06-02 07:30:11 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
describe "configuration SSHKit" do
|
2013-06-14 05:02:59 -04:00
|
|
|
let(:config) { SSHKit.config }
|
|
|
|
let(:backend) { SSHKit.config.backend.config }
|
2016-02-28 18:14:50 -05:00
|
|
|
let(:default_env) { { :rails_env => :production } }
|
2013-06-14 05:02:59 -04:00
|
|
|
|
|
|
|
before do
|
|
|
|
dsl.set(:format, :dot)
|
|
|
|
dsl.set(:log_level, :debug)
|
|
|
|
dsl.set(:default_env, default_env)
|
|
|
|
dsl.set(:pty, true)
|
|
|
|
dsl.set(:connection_timeout, 10)
|
2016-02-28 18:43:12 -05:00
|
|
|
dsl.set(:ssh_options, :keys => %w(/home/user/.ssh/id_rsa),
|
2016-03-01 10:47:37 -05:00
|
|
|
:forward_agent => false,
|
|
|
|
:auth_methods => %w(publickey password))
|
2013-06-14 05:02:59 -04:00
|
|
|
dsl.configure_backend
|
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
it "sets the output" do
|
2013-06-14 05:02:59 -04:00
|
|
|
expect(config.output).to be_a SSHKit::Formatter::Dot
|
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
it "sets the output verbosity" do
|
2013-06-14 05:02:59 -04:00
|
|
|
expect(config.output_verbosity).to eq 0
|
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
it "sets the default env" do
|
2013-06-14 05:02:59 -04:00
|
|
|
expect(config.default_env).to eq default_env
|
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
it "sets the backend pty" do
|
2014-08-12 14:52:37 -04:00
|
|
|
expect(backend.pty).to be_truthy
|
2013-06-14 05:02:59 -04:00
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
it "sets the backend connection timeout" do
|
2013-06-14 05:02:59 -04:00
|
|
|
expect(backend.connection_timeout).to eq 10
|
|
|
|
end
|
2013-07-11 11:38:55 -04:00
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
it "sets the backend ssh_options" do
|
2013-07-11 11:38:55 -04:00
|
|
|
expect(backend.ssh_options[:keys]).to eq %w(/home/user/.ssh/id_rsa)
|
|
|
|
expect(backend.ssh_options[:forward_agent]).to eq false
|
|
|
|
expect(backend.ssh_options[:auth_methods]).to eq %w(publickey password)
|
|
|
|
end
|
2013-06-14 05:02:59 -04:00
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
describe "on()" do
|
2015-03-04 18:25:27 -05:00
|
|
|
describe "when passed server objects" do
|
|
|
|
before do
|
2016-02-28 18:16:11 -05:00
|
|
|
dsl.server "example1.com", :roles => %w{web}, :active => true
|
|
|
|
dsl.server "example2.com", :roles => %w{web}
|
|
|
|
dsl.server "example3.com", :roles => %w{app web}, :active => true
|
|
|
|
dsl.server "example4.com", :roles => %w{app}, :primary => true
|
|
|
|
dsl.server "example5.com", :roles => %w{db}, :no_release => true
|
|
|
|
@coordinator = mock("coordinator")
|
2015-03-04 18:25:27 -05:00
|
|
|
@coordinator.expects(:each).returns(nil)
|
2016-02-28 18:16:11 -05:00
|
|
|
ENV.delete "ROLES"
|
|
|
|
ENV.delete "HOSTS"
|
2015-03-04 18:25:27 -05:00
|
|
|
end
|
2014-09-24 23:12:14 -04:00
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
it "filters by role from the :filter variable" do
|
2015-03-04 18:25:27 -05:00
|
|
|
hosts = dsl.roles(:web)
|
|
|
|
all = dsl.roles(:all)
|
|
|
|
SSHKit::Coordinator.expects(:new).with(hosts).returns(@coordinator)
|
2016-02-28 18:32:33 -05:00
|
|
|
dsl.set :filter, :role => "web"
|
2015-03-04 18:25:27 -05:00
|
|
|
dsl.on(all)
|
|
|
|
end
|
2014-09-24 23:12:14 -04:00
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
it "filters by host and role from the :filter variable" do
|
2015-03-04 18:25:27 -05:00
|
|
|
all = dsl.roles(:all)
|
|
|
|
SSHKit::Coordinator.expects(:new).with([]).returns(@coordinator)
|
2016-02-28 18:32:33 -05:00
|
|
|
dsl.set :filter, :role => "db", :host => "example3.com"
|
2015-03-04 18:25:27 -05:00
|
|
|
dsl.on(all)
|
|
|
|
end
|
2014-09-24 23:12:14 -04:00
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
it "filters by roles from the :filter variable" do
|
2015-07-16 19:03:20 -04:00
|
|
|
hosts = dsl.roles(:web)
|
|
|
|
all = dsl.roles(:all)
|
|
|
|
SSHKit::Coordinator.expects(:new).with(hosts).returns(@coordinator)
|
2016-02-28 18:32:33 -05:00
|
|
|
dsl.set :filter, :roles => "web"
|
2015-07-16 19:03:20 -04:00
|
|
|
dsl.on(all)
|
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
it "filters by hosts and roles from the :filter variable" do
|
2015-07-16 19:03:20 -04:00
|
|
|
all = dsl.roles(:all)
|
|
|
|
SSHKit::Coordinator.expects(:new).with([]).returns(@coordinator)
|
2016-02-28 18:32:33 -05:00
|
|
|
dsl.set :filter, :roles => "db", :hosts => "example3.com"
|
2015-07-16 19:03:20 -04:00
|
|
|
dsl.on(all)
|
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
it "filters from ENV[ROLES]" do
|
2015-03-04 18:25:27 -05:00
|
|
|
hosts = dsl.roles(:db)
|
|
|
|
all = dsl.roles(:all)
|
|
|
|
SSHKit::Coordinator.expects(:new).with(hosts).returns(@coordinator)
|
2016-02-28 18:16:11 -05:00
|
|
|
ENV["ROLES"] = "db"
|
2015-03-04 18:25:27 -05:00
|
|
|
dsl.on(all)
|
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
it "filters from ENV[HOSTS]" do
|
2015-03-04 18:25:27 -05:00
|
|
|
hosts = dsl.roles(:db)
|
|
|
|
all = dsl.roles(:all)
|
|
|
|
SSHKit::Coordinator.expects(:new).with(hosts).returns(@coordinator)
|
2016-02-28 18:16:11 -05:00
|
|
|
ENV["HOSTS"] = "example5.com"
|
2015-03-04 18:25:27 -05:00
|
|
|
dsl.on(all)
|
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
it "filters by ENV[HOSTS] && ENV[ROLES]" do
|
2015-03-04 18:25:27 -05:00
|
|
|
all = dsl.roles(:all)
|
|
|
|
SSHKit::Coordinator.expects(:new).with([]).returns(@coordinator)
|
2016-02-28 18:16:11 -05:00
|
|
|
ENV["HOSTS"] = "example5.com"
|
|
|
|
ENV["ROLES"] = "web"
|
2015-03-04 18:25:27 -05:00
|
|
|
dsl.on(all)
|
|
|
|
end
|
2014-09-24 23:12:14 -04:00
|
|
|
end
|
|
|
|
|
2015-03-04 18:25:27 -05:00
|
|
|
describe "when passed server literal names" do
|
|
|
|
before do
|
2016-02-28 18:16:11 -05:00
|
|
|
ENV.delete "ROLES"
|
|
|
|
ENV.delete "HOSTS"
|
|
|
|
@coordinator = mock("coordinator")
|
2015-03-04 18:25:27 -05:00
|
|
|
@coordinator.expects(:each).returns(nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "selects nothing when a role filter is present" do
|
2016-02-28 18:32:33 -05:00
|
|
|
dsl.set :filter, :role => "web"
|
2015-03-04 18:25:27 -05:00
|
|
|
SSHKit::Coordinator.expects(:new).with([]).returns(@coordinator)
|
2016-02-28 18:16:11 -05:00
|
|
|
dsl.on("my.server")
|
2015-03-04 18:25:27 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "selects using the string when a host filter is present" do
|
2016-02-28 18:32:33 -05:00
|
|
|
dsl.set :filter, :host => "server.local"
|
2016-02-28 18:16:11 -05:00
|
|
|
SSHKit::Coordinator.expects(:new).with(["server.local"]).returns(@coordinator)
|
|
|
|
dsl.on("server.local")
|
2015-03-04 18:25:27 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't select when a host filter is present that doesn't match" do
|
2016-02-28 18:32:33 -05:00
|
|
|
dsl.set :filter, :host => "ruby.local"
|
2015-03-04 18:25:27 -05:00
|
|
|
SSHKit::Coordinator.expects(:new).with([]).returns(@coordinator)
|
2016-02-28 18:16:11 -05:00
|
|
|
dsl.on("server.local")
|
2015-03-04 18:25:27 -05:00
|
|
|
end
|
|
|
|
|
2015-07-16 19:03:20 -04:00
|
|
|
it "selects nothing when a roles filter is present" do
|
2016-02-28 18:32:33 -05:00
|
|
|
dsl.set :filter, :roles => "web"
|
2015-07-16 19:03:20 -04:00
|
|
|
SSHKit::Coordinator.expects(:new).with([]).returns(@coordinator)
|
2016-02-28 18:16:11 -05:00
|
|
|
dsl.on("my.server")
|
2015-07-16 19:03:20 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "selects using the string when a hosts filter is present" do
|
2016-02-28 18:32:33 -05:00
|
|
|
dsl.set :filter, :hosts => "server.local"
|
2016-02-28 18:16:11 -05:00
|
|
|
SSHKit::Coordinator.expects(:new).with(["server.local"]).returns(@coordinator)
|
|
|
|
dsl.on("server.local")
|
2015-07-16 19:03:20 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't select when a hosts filter is present that doesn't match" do
|
2016-02-28 18:32:33 -05:00
|
|
|
dsl.set :filter, :hosts => "ruby.local"
|
2015-07-16 19:03:20 -04:00
|
|
|
SSHKit::Coordinator.expects(:new).with([]).returns(@coordinator)
|
2016-02-28 18:16:11 -05:00
|
|
|
dsl.on("server.local")
|
2015-07-16 19:03:20 -04:00
|
|
|
end
|
2014-09-24 23:12:14 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
describe "role_properties()" do
|
2015-01-28 18:34:20 -05:00
|
|
|
before do
|
2016-02-28 18:14:50 -05:00
|
|
|
dsl.role :redis, %w[example1.com example2.com], :redis => { :port => 6379, :type => :slave }
|
2016-02-28 18:16:11 -05:00
|
|
|
dsl.server "example1.com", :roles => %w{web}, :active => true, :web => { :port => 80 }
|
|
|
|
dsl.server "example2.com", :roles => %w{web redis}, :web => { :port => 81 }, :redis => { :type => :master }
|
|
|
|
dsl.server "example3.com", :roles => %w{app}, :primary => true
|
2015-01-28 18:34:20 -05:00
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
it "retrieves properties for a single role as a set" do
|
2015-01-28 18:34:20 -05:00
|
|
|
rps = dsl.role_properties(:app)
|
2016-02-28 18:35:06 -05:00
|
|
|
expect(rps).to eq(Set[{ :hostname => "example3.com", :role => :app }])
|
2015-01-28 18:34:20 -05:00
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
it "retrieves properties for multiple roles as a set" do
|
2015-01-28 18:34:20 -05:00
|
|
|
rps = dsl.role_properties(:app, :web)
|
2016-03-01 10:02:00 -05:00
|
|
|
expect(rps).to eq(Set[{ :hostname => "example3.com", :role => :app }, { :hostname => "example1.com", :role => :web, :port => 80 }, { :hostname => "example2.com", :role => :web, :port => 81 }])
|
2015-01-28 18:34:20 -05:00
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
it "yields the properties for a single role" do
|
|
|
|
recipient = mock("recipient")
|
2016-02-28 18:32:33 -05:00
|
|
|
recipient.expects(:doit).with("example1.com", :redis, :port => 6379, :type => :slave)
|
|
|
|
recipient.expects(:doit).with("example2.com", :redis, :port => 6379, :type => :master)
|
2015-01-28 18:34:20 -05:00
|
|
|
dsl.role_properties(:redis) do |host, role, props|
|
|
|
|
recipient.doit(host, role, props)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
it "yields the properties for multiple roles" do
|
|
|
|
recipient = mock("recipient")
|
2016-02-28 18:32:33 -05:00
|
|
|
recipient.expects(:doit).with("example1.com", :redis, :port => 6379, :type => :slave)
|
|
|
|
recipient.expects(:doit).with("example2.com", :redis, :port => 6379, :type => :master)
|
2016-02-28 18:16:11 -05:00
|
|
|
recipient.expects(:doit).with("example3.com", :app, nil)
|
2015-01-28 18:34:20 -05:00
|
|
|
dsl.role_properties(:redis, :app) do |host, role, props|
|
|
|
|
recipient.doit(host, role, props)
|
|
|
|
end
|
|
|
|
end
|
2015-02-06 13:31:40 -05:00
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
it "yields the merged properties for multiple roles" do
|
|
|
|
recipient = mock("recipient")
|
2016-02-28 18:32:33 -05:00
|
|
|
recipient.expects(:doit).with("example1.com", :redis, :port => 6379, :type => :slave)
|
|
|
|
recipient.expects(:doit).with("example2.com", :redis, :port => 6379, :type => :master)
|
|
|
|
recipient.expects(:doit).with("example1.com", :web, :port => 80)
|
|
|
|
recipient.expects(:doit).with("example2.com", :web, :port => 81)
|
2015-02-06 13:31:40 -05:00
|
|
|
dsl.role_properties(:redis, :web) do |host, role, props|
|
|
|
|
recipient.doit(host, role, props)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-28 18:16:11 -05:00
|
|
|
it "honours a property filter before yielding" do
|
|
|
|
recipient = mock("recipient")
|
2016-02-28 18:32:33 -05:00
|
|
|
recipient.expects(:doit).with("example1.com", :redis, :port => 6379, :type => :slave)
|
|
|
|
recipient.expects(:doit).with("example1.com", :web, :port => 80)
|
2016-02-28 18:14:50 -05:00
|
|
|
dsl.role_properties(:redis, :web, :select => :active) do |host, role, props|
|
2015-02-06 13:31:40 -05:00
|
|
|
recipient.doit(host, role, props)
|
|
|
|
end
|
|
|
|
end
|
2015-01-28 18:34:20 -05:00
|
|
|
end
|
2013-06-02 07:30:11 -04:00
|
|
|
end
|