nodespec 0.1.10 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/Gemfile.lock +29 -21
  4. data/README.md +10 -8
  5. data/lib/nodespec/backend_proxy/ssh.rb +1 -1
  6. data/lib/nodespec/backend_proxy/winrm.rb +1 -1
  7. data/lib/nodespec/backend_proxy.rb +23 -0
  8. data/lib/nodespec/communication_adapters/aws_ec2.rb +3 -3
  9. data/lib/nodespec/communication_adapters/native_communicator.rb +11 -18
  10. data/lib/nodespec/communication_adapters/ssh.rb +2 -3
  11. data/lib/nodespec/communication_adapters/ssh_communicator.rb +15 -28
  12. data/lib/nodespec/communication_adapters/vagrant.rb +2 -2
  13. data/lib/nodespec/communication_adapters/winrm.rb +2 -2
  14. data/lib/nodespec/communication_adapters/winrm_communicator.rb +17 -30
  15. data/lib/nodespec/communication_adapters.rb +3 -3
  16. data/lib/nodespec/configuration_binding.rb +48 -0
  17. data/lib/nodespec/node.rb +1 -3
  18. data/lib/nodespec/provisioning/ansible.rb +1 -1
  19. data/lib/nodespec/version.rb +1 -1
  20. data/lib/nodespec.rb +9 -11
  21. data/nodespec.gemspec +7 -4
  22. data/spec/backend_proxy/exec_spec.rb +4 -4
  23. data/spec/backend_proxy/ssh_spec.rb +5 -5
  24. data/spec/backend_proxy/unixshell_utility_spec.rb +1 -1
  25. data/spec/backend_proxy/winrm_spec.rb +2 -2
  26. data/spec/command_execution_spec.rb +2 -2
  27. data/spec/communication_adapters/aws_ec2_spec.rb +8 -8
  28. data/spec/communication_adapters/native_communicator_spec.rb +16 -34
  29. data/spec/communication_adapters/ssh_communicator_spec.rb +34 -90
  30. data/spec/communication_adapters/ssh_spec.rb +1 -9
  31. data/spec/communication_adapters/vagrant_spec.rb +2 -2
  32. data/spec/communication_adapters/winrm_communicator_spec.rb +31 -83
  33. data/spec/communication_adapters/winrm_spec.rb +1 -9
  34. data/spec/communication_adapters_spec.rb +4 -4
  35. data/spec/configuration_binding_spec.rb +167 -0
  36. data/spec/local_command_runner_spec.rb +3 -3
  37. data/spec/node_spec.rb +10 -10
  38. data/spec/provisioning_spec.rb +3 -3
  39. data/spec/support/backend.rb +5 -5
  40. data/spec/support/communicator_adapters.rb +23 -0
  41. data/spec/support/init_with_current_node.rb +1 -1
  42. metadata +32 -22
  43. data/lib/nodespec/backends.rb +0 -13
  44. data/lib/nodespec/communication_adapters/local_backend.rb +0 -15
  45. data/lib/nodespec/communication_adapters/remote_backend.rb +0 -15
  46. data/spec/communication_adapters/local_backend_spec.rb +0 -38
  47. data/spec/communication_adapters/remote_backend_spec.rb +0 -46
  48. data/spec/support/ssh_communicator.rb +0 -9
  49. data/spec/support/winrm_communicator.rb +0 -9
@@ -4,27 +4,27 @@ module NodeSpec
4
4
  module BackendProxy
5
5
  describe Ssh do
6
6
  let(:ssh_session) { double('ssh session') }
7
- let(:subject) {Ssh.new(ssh_session)}
7
+ subject {Ssh.new(ssh_session)}
8
8
 
9
9
  shared_examples 'an ssh session command run' do |user, original_command, actual_command|
10
10
  before do
11
11
  allow(ssh_session).to receive(:options).and_return({user: user})
12
12
  allow(subject).to receive(:execute_within_timeout).with(actual_command).and_yield
13
13
  end
14
-
14
+
15
15
  it 'returns true if the command succeeds' do
16
16
  allow(ssh_session).to receive(:exec!).with(actual_command).and_yield(nil, 'a stream', 'test data')
17
-
17
+
18
18
  expect(subject.execute(original_command)).to be_truthy
19
19
  end
20
20
 
21
21
  it 'returns false if the command fails' do
22
22
  allow(ssh_session).to receive(:exec!).with(actual_command).and_yield(nil, :stderr, 'test data')
23
-
23
+
24
24
  expect(subject.execute(original_command)).to be_falsy
25
25
  end
26
26
  end
27
-
27
+
28
28
  it_behaves_like 'an ssh session command run', 'root', 'test command', 'test command'
29
29
  it_behaves_like 'an ssh session command run', 'some_user', 'test command', 'sudo test command'
30
30
  end
@@ -3,7 +3,7 @@ require 'nodespec/backend_proxy/unixshell_utility'
3
3
  module NodeSpec
4
4
  module BackendProxy
5
5
  describe UnixshellUtility do
6
- let(:subject) {Object.new.extend UnixshellUtility}
6
+ subject {Object.new.extend UnixshellUtility}
7
7
 
8
8
  it 'returns the command as run by sudo' do
9
9
  expect(subject.run_as_sudo('command')).to eq 'sudo command'
@@ -2,9 +2,9 @@ require 'nodespec/backend_proxy/winrm'
2
2
 
3
3
  module NodeSpec
4
4
  module BackendProxy
5
- describe WinRM do
5
+ describe Winrm do
6
6
  let(:winrm) { double('winrm session') }
7
- let(:subject) {WinRM.new(winrm)}
7
+ subject {Winrm.new(winrm)}
8
8
  before do
9
9
  allow(winrm).to receive(:set_timeout).with(NodeSpec::RunOptions.command_timeout)
10
10
  end
@@ -2,8 +2,8 @@ require 'nodespec/command_execution'
2
2
 
3
3
  module NodeSpec
4
4
  describe CommandExecution do
5
- let(:subject) {Object.new.extend CommandExecution}
6
-
5
+ subject {Object.new.extend CommandExecution}
6
+
7
7
  it 'does not raise an error if the command succeeds' do
8
8
  subject.execute_within_timeout('test command') { true }
9
9
  end
@@ -17,28 +17,28 @@ module NodeSpec
17
17
  before do
18
18
  allow(ec2_instance).to receive(:exists?).ordered.and_return(true)
19
19
  allow(ec2_instance).to receive(:status).ordered.and_return(:running)
20
- allow(ec2_instance).to receive(:public_dns_name).ordered.and_return('test hostname')
20
+ allow(ec2_instance).to receive(:public_dns_name).ordered.and_return('test.host.name')
21
21
  end
22
22
 
23
23
  %w[ssh winrm].each do |connection|
24
24
  describe "#{connection} communicator" do
25
- include_context "new_#{connection}_communicator", 'test hostname', 'test_os', 'foo' => 'bar'
25
+ include_context "new_#{connection}_communicator", 'test.host.name', 'foo' => 'bar'
26
26
 
27
27
  it 'returns communicator with the instance name from the node name' do
28
- expect(AwsEc2.communicator_for('test-instance', 'test_os', connection => {'foo' => 'bar'})).to eq("#{connection} communicator")
28
+ expect(AwsEc2.communicator_for('test-instance', connection => {'foo' => 'bar'})).to eq("#{connection} communicator")
29
29
  end
30
30
 
31
31
  it 'returns communicator with the instance name from the options' do
32
- expect(AwsEc2.communicator_for('test_node', 'test_os', 'instance' => 'test-instance', connection => {'foo' => 'bar'})).to eq("#{connection} communicator")
32
+ expect(AwsEc2.communicator_for('test_node', 'instance' => 'test-instance', connection => {'foo' => 'bar'})).to eq("#{connection} communicator")
33
33
  end
34
34
  end
35
35
  end
36
36
 
37
37
  describe 'openssh default connection' do
38
- include_context "new_ssh_communicator", 'test hostname', 'test_os', {}
38
+ include_context "new_ssh_communicator", 'test.host.name', {}
39
39
 
40
40
  it 'returns an ssh communicator' do
41
- expect(AwsEc2.communicator_for('test-instance', 'test_os')).to eq("ssh communicator")
41
+ expect(AwsEc2.communicator_for('test-instance')).to eq("ssh communicator")
42
42
  end
43
43
  end
44
44
  end
@@ -50,7 +50,7 @@ module NodeSpec
50
50
  end
51
51
 
52
52
  it 'raises an error' do
53
- expect {AwsEc2.communicator_for('test-instance', 'test_os', 'foo' => 'bar')}.to raise_error
53
+ expect {AwsEc2.communicator_for('test-instance', 'foo' => 'bar')}.to raise_error
54
54
  end
55
55
  end
56
56
 
@@ -61,7 +61,7 @@ module NodeSpec
61
61
  end
62
62
 
63
63
  it 'raises an error' do
64
- expect {AwsEc2.communicator_for('test-instance', 'test_os', 'foo' => 'bar')}.to raise_error
64
+ expect {AwsEc2.communicator_for('test-instance', 'foo' => 'bar')}.to raise_error
65
65
  end
66
66
  end
67
67
  end
@@ -1,51 +1,33 @@
1
+ require 'spec_helper'
1
2
  require 'nodespec/communication_adapters/native_communicator'
2
3
 
3
4
  module NodeSpec
4
5
  module CommunicationAdapters
5
6
  describe NativeCommunicator do
6
- it 'provides a local backend' do
7
- expect(NativeCommunicator.new).to be_a(LocalBackend)
8
- end
9
-
10
- describe '#initialize' do
11
- [nil, 'Test OS'].each do |os|
12
- it 'holds the os information' do
13
- expect(NativeCommunicator.new(os).os).to eq os
7
+ describe 'providing backend proxy' do
8
+ context 'non Windows os' do
9
+ before do
10
+ allow(OS).to receive(:windows?).and_return(false)
14
11
  end
12
+ include_examples 'providing a backend', :exec, BackendProxy::Exec
15
13
  end
16
- end
17
-
18
- describe '#bind_to' do
19
- let(:rspec_configuration) {double('rspec configuration')}
20
-
21
- context('ssh session') do
22
- let(:ssh_session) {double('ssh session')}
23
14
 
15
+ context 'Windows os' do
24
16
  before do
25
- allow(rspec_configuration).to receive(:ssh).and_return(ssh_session)
26
- allow(rspec_configuration).to receive(:winrm)
27
- [:close, :host].each {|m| allow(ssh_session).to receive(m)}
28
- allow(ssh_session).to receive(:options).and_return({port: 'port'})
29
- expect(rspec_configuration).to receive(:ssh=).with(nil)
17
+ allow(OS).to receive(:windows?).and_return(true)
30
18
  end
31
19
 
32
- it 'closes and removes an existing ssh session' do
33
- subject.bind_to(rspec_configuration)
34
- end
20
+ include_examples 'providing a backend', :cmd, BackendProxy::Cmd
35
21
  end
22
+ end
36
23
 
37
- context('winrm session') do
38
- let(:winrm_session) {double('winrm session')}
39
-
40
- before do
41
- allow(rspec_configuration).to receive(:ssh)
42
- allow(rspec_configuration).to receive(:winrm).and_return(winrm_session)
43
- expect(rspec_configuration).to receive(:winrm=).with(nil)
44
- end
24
+ describe '#bind_to' do
25
+ let(:configuration) {double('configuration')}
45
26
 
46
- it 'removes an existing winrm session' do
47
- subject.bind_to(rspec_configuration)
48
- end
27
+ it 'unbinds other sessions' do
28
+ expect(configuration).to receive(:unbind_ssh_session)
29
+ expect(configuration).to receive(:unbind_winrm_session)
30
+ subject.bind_to(configuration)
49
31
  end
50
32
  end
51
33
  end
@@ -1,120 +1,64 @@
1
+ require 'spec_helper'
1
2
  require 'nodespec/communication_adapters/ssh_communicator'
2
3
 
3
4
  module NodeSpec
4
5
  module CommunicationAdapters
5
6
  describe SshCommunicator do
6
- let(:rspec_configuration) {double('rspec configuration')}
7
- let(:ssh_session) {double('ssh session')}
7
+ let(:configuration) {double('configuration')}
8
8
 
9
- before do
10
- allow(Net::SSH).to receive(:start).with('test.host.name', 'testuser', port: 1234, password: 'testpassword', keys: 'testkeys').and_return('new session')
11
- end
12
-
13
- shared_context 'existing session' do |hostname, port|
9
+ shared_context 'creating new session' do |hostname, options|
14
10
  before do
15
- allow(rspec_configuration).to receive(:ssh).and_return(ssh_session)
16
- allow(ssh_session).to receive(:host).and_return(hostname)
17
- allow(ssh_session).to receive(:options).and_return({port: port})
11
+ expect(configuration).to receive(:unbind_winrm_session)
12
+ allow(Net::SSH).to receive(:start).with(hostname, 'testuser', options).and_return('session')
13
+ allow(configuration).to receive(:bind_ssh_session_for) do |host, port, &block|
14
+ expect(host).to eq hostname
15
+ expect(port).to eq port
16
+ block.call
17
+ end
18
18
  end
19
19
  end
20
20
 
21
- shared_examples 'creating new session' do
22
- before do
23
- expect(rspec_configuration).to receive(:ssh=).with('new session')
24
- expect(rspec_configuration).to receive(:host=).with('test.host.name')
25
- end
26
-
27
- it 'creates and holds a new session' do
28
- subject.bind_to(rspec_configuration)
21
+ shared_examples 'binding session' do
22
+ it 'returns a session' do
23
+ subject.bind_to(configuration)
29
24
 
30
- expect(subject.session).to eq('new session')
25
+ expect(subject.session).to eq('session')
31
26
  end
32
27
  end
33
28
 
34
- shared_examples 'binding to configuration' do
35
- before do
36
- allow(rspec_configuration).to receive(:winrm)
37
- end
38
-
39
- context 'existing winrm session' do
29
+ describe 'binding the session' do
30
+ context 'default options' do
31
+ subject {SshCommunicator.new('test.host.name')}
40
32
  before do
41
- allow(rspec_configuration).to receive(:winrm).and_return('winrm')
42
- allow(rspec_configuration).to receive(:ssh).and_return(nil)
43
- expect(rspec_configuration).to receive(:winrm=).with(nil)
33
+ allow(Net::SSH).to receive(:configuration_for).and_return({someoption: 'somevalue', user: 'testuser'})
44
34
  end
45
-
46
- include_examples 'creating new session'
35
+ include_context 'creating new session', 'test.host.name', someoption: 'somevalue', user: 'testuser'
36
+ include_examples 'binding session'
47
37
  end
48
38
 
49
- context 'no existing ssh session' do
39
+ context 'custom options' do
40
+ subject {SshCommunicator.new('test.host.name', 'port' => 1234, 'user' => 'testuser', 'password' => 'testpassword', 'keys' => 'testkeys')}
50
41
  before do
51
- allow(rspec_configuration).to receive(:ssh).and_return(nil)
52
- end
53
-
54
- include_examples 'creating new session'
55
- end
56
-
57
- {'another host' => 1234, 'test.host.name' => 5678}.each do |hostname, port|
58
- context 'existing session with different connection' do
59
- include_context 'existing session', hostname, port
60
- before do
61
- expect(ssh_session).to receive(:close)
62
- allow(ssh_session).to receive(:closed?).and_return(true)
63
- end
64
- include_examples 'creating new session'
42
+ allow(Net::SSH).to receive(:configuration_for).and_return({someoption: 'somevalue', port: 22, user: 'testuser'})
65
43
  end
44
+ include_context 'creating new session', 'test.host.name', someoption: 'somevalue', port: 1234, user: 'testuser', password: 'testpassword', keys: 'testkeys'
45
+ include_examples 'binding session'
66
46
  end
67
47
 
68
- context 'existing ssh session with same connection' do
69
- include_context 'existing session', 'test.host.name', 1234
70
- context 'open session' do
71
- before { allow(ssh_session).to receive(:closed?).and_return(false) }
72
-
73
- it 'does not change the current rspec configuration' do
74
- expect(Net::SSH).not_to receive(:start)
75
- expect(rspec_configuration).not_to receive(:ssh=)
76
- expect(rspec_configuration).not_to receive(:host=)
77
-
78
- subject.bind_to(rspec_configuration)
79
-
80
- expect(subject.session).to eq(ssh_session)
81
- end
82
- end
83
-
84
- context 'closed session' do
85
- before { allow(ssh_session).to receive(:closed?).and_return(true) }
86
- include_examples 'creating new session'
48
+ context 'same session' do
49
+ subject {SshCommunicator.new('test.host.name', 'port' => 1234, 'user' => 'testuser')}
50
+ before do
51
+ expect(configuration).to receive(:unbind_winrm_session)
52
+ allow(configuration).to receive(:bind_ssh_session_for).with('test.host.name', 1234).and_return('session')
87
53
  end
88
- end
89
- end
90
54
 
91
- context 'with given credentials' do
92
- let(:subject) {SshCommunicator.new('test.host.name', nil, 'port' => 1234, 'user' => 'testuser', 'password' => 'testpassword', 'keys' => 'testkeys')}
93
- before do
94
- allow(Net::SSH).to receive(:configuration_for).and_return({})
55
+ include_examples 'binding session'
95
56
  end
96
- include_examples 'binding to configuration'
97
57
  end
98
58
 
99
- context 'credentials from OpenSSH config files' do
100
- let(:subject) {SshCommunicator.new('test.host.name', nil, 'port' => 1234, 'user' => 'testuser')}
101
- before do
102
- allow(Net::SSH).to receive(:configuration_for).with('test.host.name').and_return(password: 'testpassword', keys: 'testkeys')
103
- end
104
-
105
- include_examples 'binding to configuration'
106
- end
107
-
108
- it 'provides a remote backend' do
109
- expect(SshCommunicator.new('test.host.name')).to be_a(RemoteBackend)
110
- end
111
-
112
- describe '#initialize' do
113
- [nil, 'Test OS'].each do |os|
114
- it 'holds the os information' do
115
- expect(SshCommunicator.new('test.host.name', os, {}).os).to eq os
116
- end
117
- end
59
+ describe 'providing backend proxy' do
60
+ subject {SshCommunicator.new('test.host.name')}
61
+ include_examples 'providing a backend', :ssh, BackendProxy::Ssh
118
62
  end
119
63
  end
120
64
  end
@@ -4,15 +4,7 @@ require 'nodespec/communication_adapters/ssh'
4
4
  module NodeSpec
5
5
  module CommunicationAdapters
6
6
  describe Ssh do
7
- include_context 'new_ssh_communicator', 'test.host.name', 'test_os', {'foo' => 'bar'}
8
-
9
- it 'returns communicator with the host name from the node name' do
10
- expect(Ssh.communicator_for('test.host.name', 'test_os', 'foo' => 'bar')).to eq('ssh communicator')
11
- end
12
-
13
- it 'returns communicator with the host name from the options' do
14
- expect(Ssh.communicator_for('test_node', 'test_os', 'host' => 'test.host.name', 'foo' => 'bar')).to eq('ssh communicator')
15
- end
7
+ include_examples 'new_communicator', Ssh, 'ssh'
16
8
  end
17
9
  end
18
10
  end
@@ -4,7 +4,7 @@ require 'nodespec/communication_adapters/vagrant'
4
4
  module NodeSpec
5
5
  module CommunicationAdapters
6
6
  describe Vagrant do
7
- [['test_vm', 'test_os'], ['test_node', 'test_os', {'vm_name' => 'test_vm'}]].each do |args|
7
+ [['test_vm', 'test_os'], ['test_node', {'vm_name' => 'test_vm'}]].each do |args|
8
8
  describe "#communicator_for" do
9
9
  let(:cmd_status) { double('status') }
10
10
 
@@ -40,7 +40,7 @@ Host test_vm
40
40
  EOS
41
41
  }
42
42
 
43
- include_context 'new_ssh_communicator', 'test.host.name', 'test_os', {
43
+ include_context 'new_ssh_communicator', 'test.host.name', {
44
44
  'user' => 'testuser',
45
45
  'port' => 1234,
46
46
  'keys' => '/test/path/private_key'
@@ -1,110 +1,58 @@
1
- require 'winrm'
1
+ require 'spec_helper'
2
2
  require 'nodespec/communication_adapters/winrm_communicator'
3
3
 
4
4
  module NodeSpec
5
5
  module CommunicationAdapters
6
6
  describe WinrmCommunicator do
7
- let(:rspec_configuration) {double('rspec configuration')}
8
- shared_examples 'creating new session' do |hostname, port, transport, options|
7
+ let(:configuration) {double('configuration')}
8
+
9
+ shared_context 'creating new session' do |hostname, port, transport, options|
9
10
  before do
10
- allow(WinRM::WinRMWebService).to receive(:new).with("http://#{hostname}:#{port}/wsman", transport, options).and_return('new session')
11
- expect(rspec_configuration).to receive(:winrm=).with('new session')
12
- expect(rspec_configuration).to receive(:host=).with(hostname)
11
+ expect(configuration).to receive(:unbind_ssh_session)
12
+ allow(WinRM::WinRMWebService).to receive(:new).with("http://#{hostname}:#{port}/wsman", transport, options).and_return('session')
13
+ allow(configuration).to receive(:bind_winrm_session_for) do |host, endpoint, &block|
14
+ expect(host).to eq hostname
15
+ expect(endpoint).to eq "http://#{hostname}:#{port}/wsman"
16
+ block.call
17
+ end
13
18
  end
19
+ end
14
20
 
15
- it 'creates and holds a new session' do
16
- subject.bind_to(rspec_configuration)
21
+ shared_examples 'binding session' do
22
+ it 'returns a session' do
23
+ subject.bind_to(configuration)
17
24
 
18
- expect(subject.session).to eq('new session')
25
+ expect(subject.session).to eq('session')
19
26
  end
20
27
  end
21
28
 
22
- describe 'connecting to the web service' do
23
- before do
24
- allow(rspec_configuration).to receive(:ssh)
25
- allow(rspec_configuration).to receive(:winrm).and_return(nil)
26
- end
27
-
29
+ describe 'binding the session' do
28
30
  context 'default port and transport' do
29
- let(:subject) {WinrmCommunicator.new('test.host.name', nil, 'foo' => 'bar')}
30
- include_examples 'creating new session', 'test.host.name', 5985, :plaintext, {foo: 'bar', disable_sspi: true}
31
+ subject {WinrmCommunicator.new('test.host.name', 'foo' => 'bar')}
32
+ include_context 'creating new session', 'test.host.name', 5985, :plaintext, {foo: 'bar', disable_sspi: true}
33
+ include_examples 'binding session'
31
34
  end
32
35
 
33
36
  context 'custom port and transport' do
34
- let(:subject) {WinrmCommunicator.new('test.host.name', nil, 'port' => 1234, 'transport' => 'test_transport', 'foo' => 'bar')}
35
- include_examples 'creating new session', 'test.host.name', 1234, :test_transport, {foo: 'bar'}
36
- end
37
- end
38
-
39
- describe 'binding to configuration' do
40
- let(:winrm_session) {double('winrm session')}
41
- let(:subject) { WinrmCommunicator.new(
42
- 'test.host.name', nil, 'port' => 1234, 'transport' => 'test_transport', foo: 'bar', 'baz' => 'quaz')
43
- }
44
-
45
- before do
46
- allow(rspec_configuration).to receive(:ssh)
47
- end
48
-
49
- shared_context 'existing session' do |endpoint|
50
- before do
51
- allow(rspec_configuration).to receive(:winrm).and_return(winrm_session)
52
- allow(winrm_session).to receive(:endpoint).and_return(endpoint)
53
- end
37
+ subject {WinrmCommunicator.new('test.host.name', 'port' => 1234, 'transport' => 'test_transport', 'foo' => 'bar')}
38
+ include_context 'creating new session', 'test.host.name', 1234, :test_transport, {foo: 'bar'}
39
+ include_examples 'binding session'
54
40
  end
55
41
 
56
- context 'existing ssh session' do
57
- let(:ssh_session) {double('ssh session')}
42
+ context 'same session' do
43
+ subject {WinrmCommunicator.new('test.host.name', 'foo' => 'bar')}
58
44
  before do
59
- allow(rspec_configuration).to receive(:ssh).and_return(ssh_session)
60
- allow(rspec_configuration).to receive(:winrm).and_return(nil)
61
- allow(ssh_session).to receive(:host)
62
- allow(ssh_session).to receive(:options).and_return({})
63
- expect(ssh_session).to receive(:close)
64
- expect(rspec_configuration).to receive(:ssh=).with(nil)
45
+ expect(configuration).to receive(:unbind_ssh_session)
46
+ allow(configuration).to receive(:bind_winrm_session_for).with('test.host.name', "http://test.host.name:5985/wsman").and_return('session')
65
47
  end
66
48
 
67
- include_examples 'creating new session', 'test.host.name', 1234, :test_transport, {foo: 'bar', baz: 'quaz'}
68
- end
69
-
70
- context 'no existing session' do
71
- before do
72
- allow(rspec_configuration).to receive(:winrm).and_return(nil)
73
- end
74
-
75
- include_examples 'creating new session', 'test.host.name', 1234, :test_transport, {foo: 'bar', baz: 'quaz'}
76
- end
77
-
78
- context 'existing session with different endpoint' do
79
- include_context 'existing session', 'http://test.another.host.name:1234/wsman'
80
- include_examples 'creating new session', 'test.host.name', 1234, :test_transport, {foo: 'bar', baz: 'quaz'}
81
- end
82
-
83
- context 'existing session with same connection' do
84
- include_context 'existing session', "http://test.host.name:1234/wsman"
85
-
86
- it 'does not change the current rspec configuration' do
87
- expect(WinRM::WinRMWebService).not_to receive(:new)
88
- expect(rspec_configuration).not_to receive(:winrm=)
89
- expect(rspec_configuration).not_to receive(:host=)
90
-
91
- subject.bind_to(rspec_configuration)
92
-
93
- expect(subject.session).to eq(winrm_session)
94
- end
49
+ include_examples 'binding session'
95
50
  end
96
51
  end
97
52
 
98
- it 'provides a remote backend' do
99
- expect(WinrmCommunicator.new('test.host.name')).to be_a(RemoteBackend)
100
- end
101
-
102
- describe '#initialize' do
103
- [nil, 'Test OS'].each do |os|
104
- it 'holds the os information' do
105
- expect(WinrmCommunicator.new('test.host.name', os, {}).os).to eq os
106
- end
107
- end
53
+ describe 'providing backend proxy' do
54
+ subject {WinrmCommunicator.new('test.host.name')}
55
+ include_examples 'providing a backend', :winrm, BackendProxy::Winrm
108
56
  end
109
57
  end
110
58
  end
@@ -4,15 +4,7 @@ require 'nodespec/communication_adapters/winrm'
4
4
  module NodeSpec
5
5
  module CommunicationAdapters
6
6
  describe Winrm do
7
- include_context 'new_winrm_communicator', 'test.host.name', 'test_os', {'foo' => 'bar'}
8
-
9
- it 'returns communicator with the host name from the node name' do
10
- expect(Winrm.communicator_for('test.host.name', 'test_os', 'foo' => 'bar')).to eq('winrm communicator')
11
- end
12
-
13
- it 'returns communicator with the host name from the options' do
14
- expect(Winrm.communicator_for('test_node', 'test_os', 'host' => 'test.host.name', 'foo' => 'bar')).to eq('winrm communicator')
15
- end
7
+ include_examples 'new_communicator', Winrm, 'winrm'
16
8
  end
17
9
  end
18
10
  end
@@ -10,18 +10,18 @@ module NodeSpec
10
10
  'winrm' => CommunicationAdapters::Winrm
11
11
  }.each do |adapter_name, adapter_class|
12
12
  it "retrieves a communicator from #{adapter_class}" do
13
- expect(adapter_class).to receive(:communicator_for).with('test_node', 'test_os', 'adapter_options' => 'test_options').and_return('communicator')
13
+ expect(adapter_class).to receive(:communicator_for).with('test_node', 'adapter_options' => 'test_options').and_return('communicator')
14
14
 
15
- communicator = CommunicationAdapters.get_communicator('test_node', 'test_os', adapter_name, 'adapter_options' => 'test_options')
15
+ communicator = CommunicationAdapters.get_communicator('test_node', adapter_name, 'adapter_options' => 'test_options')
16
16
 
17
17
  expect(communicator).to eq('communicator')
18
18
  end
19
19
  end
20
20
 
21
21
  it 'defaults to a NativeCommunicator' do
22
- expect(CommunicationAdapters::NativeCommunicator).to receive(:new).with('test_os').and_return('communicator')
22
+ expect(CommunicationAdapters::NativeCommunicator).to receive(:new).and_return('communicator')
23
23
 
24
- communicator = CommunicationAdapters.get_communicator('test_node', 'test_os', nil)
24
+ communicator = CommunicationAdapters.get_communicator('test_node')
25
25
 
26
26
  expect(communicator).to eq('communicator')
27
27
  end