-
1
require 'chake/node'
-
-
1
describe Chake::Node do
-
-
1
before do
-
14
ent = double
-
14
allow(ent).to receive(:name).and_return('jonhdoe')
-
14
allow(Etc).to receive(:getpwuid).and_return(ent)
-
end
-
-
8
let(:simple) { Chake::Node.new('hostname') }
-
2
it('has a name') { expect(simple.hostname).to eq('hostname') }
-
2
it('uses ssh by default') { expect(simple.backend).to be_an_instance_of(Chake::Backend::Ssh) }
-
1
it('user current username by default') {
-
1
expect(simple.username).to eq('jonhdoe')
-
}
-
1
it('writes to /var/tmp/chef.$username') {
-
1
expect(simple.path).to eq('/var/tmp/chef.jonhdoe')
-
}
-
-
3
let(:with_username) { Chake::Node.new('username@hostname') }
-
2
it('accepts username') { expect(with_username.username).to eq('username') }
-
2
it('uses ssh') { expect(with_username.backend).to be_an_instance_of(Chake::Backend::Ssh) }
-
-
2
let(:with_backend) { Chake::Node.new('local://hostname')}
-
2
it('accepts backend as URI scheme') { expect(with_backend.backend).to be_an_instance_of(Chake::Backend::Local) }
-
-
1
it('wont accept any backend') do
-
2
expect { Chake::Node.new('foobar://bazqux').backend }.to raise_error(ArgumentError)
-
end
-
-
2
let(:with_data) { Chake::Node.new('local://localhost', 'run_list' => ['recipe[common]']) }
-
1
it('takes data') do
-
1
expect(with_data.data).to be_a(Hash)
-
end
-
-
2
let(:with_port) { Chake::Node.new('ssh://foo.bar.com:2222') }
-
1
it('accepts a port specification') do
-
1
expect(with_port.port).to eq(2222)
-
end
-
-
2
let(:with_port_but_no_scheme) { Chake::Node.new('foo.bar.com:2222') }
-
1
it('accepts a port specification without a scheme') do
-
1
expect(with_port_but_no_scheme.port).to eq(2222)
-
1
expect(with_port_but_no_scheme.backend.to_s).to eq('ssh')
-
end
-
-
1
[:run, :run_as_root, :rsync_dest].each do |method|
-
3
it("delegates #{method} to backend") do
-
3
node = simple
-
-
3
backend = double
-
3
args = Object.new
-
3
allow(node).to receive(:backend).and_return(backend)
-
-
3
expect(backend).to receive(method).with(args)
-
3
node.send(method, args)
-
end
-
end
-
-
end