specinfra 1.27.5 → 2.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,132 +2,112 @@ require 'spec_helper'
2
2
 
3
3
  include SpecInfra::Helper::Ssh
4
4
 
5
- ssh = double
6
-
7
-
8
- describe 'build command with sudo' do
9
- before :each do
10
- RSpec.configure do |c|
11
- ssh.stub(:options) { { :user => 'foo' } }
12
- c.ssh = ssh
13
- c.sudo_path = nil
5
+ describe SpecInfra::Backend::Ssh do
6
+ describe '#build_command' do
7
+ context 'with root user' do
8
+ before do
9
+ RSpec.configure do |c|
10
+ c.ssh = double(:ssh, :options => { :user => 'root' })
11
+ end
12
+ end
13
+
14
+ it 'should not prepend sudo' do
15
+ expect(backend.build_command('test -f /etc/passwd')).to eq '/bin/sh -c test\ -f\ /etc/passwd'
16
+ end
17
+
18
+ it 'should escape special characters' do
19
+ expect(backend.build_command('test ! -f /etc/selinux/config || (getenforce | grep -i -- disabled && grep -i -- ^SELINUX=disabled$ /etc/selinux/config)')).to eq '/bin/sh -c test\ \!\ -f\ /etc/selinux/config\ \|\|\ \(getenforce\ \|\ grep\ -i\ --\ disabled\ \&\&\ grep\ -i\ --\ \^SELINUX\=disabled\$\ /etc/selinux/config\)'
20
+ end
14
21
  end
15
- end
16
-
17
- context 'command pattern 1' do
18
- subject { backend.build_command('test -f /etc/passwd') }
19
- it { should eq 'sudo test -f /etc/passwd' }
20
- end
21
22
 
22
- context 'command pattern 2' do
23
- subject { backend.build_command('test ! -f /etc/selinux/config || (getenforce | grep -i -- disabled && grep -i -- ^SELINUX=disabled$ /etc/selinux/config)') }
24
- it { should eq 'sudo test ! -f /etc/selinux/config || (sudo getenforce | grep -i -- disabled && sudo grep -i -- ^SELINUX=disabled$ /etc/selinux/config)' }
25
- end
23
+ context 'with non-root user' do
24
+ before do
25
+ RSpec.configure do |c|
26
+ c.ssh = double(:ssh, :options => { :user => 'foo' })
27
+ end
28
+ end
26
29
 
27
- context 'command pattern 3' do
28
- subject { backend.build_command("dpkg -s apache2 && ! dpkg -s apache2 | grep -E '^Status: .+ not-installed$'") }
29
- it { should eq "sudo dpkg -s apache2 && ! sudo dpkg -s apache2 | grep -E '^Status: .+ not-installed$'" }
30
- end
31
- end
30
+ it 'should prepend sudo' do
31
+ expect(backend.build_command('test -f /etc/passwd')).to eq 'sudo /bin/sh -c test\ -f\ /etc/passwd'
32
+ end
32
33
 
33
- # Alternate path for sudo command:
34
- sudo_path = '/usr/local/bin'
35
-
36
- describe 'build command with sudo on alternate path' do
37
- before :each do
38
- RSpec.configure do |c|
39
- ssh.stub(:options) { { :user => 'foo' } }
40
- c.ssh = ssh
41
- c.sudo_path = "#{sudo_path}"
34
+ it 'should escape special characters' do
35
+ expect(backend.build_command('test ! -f /etc/selinux/config || (getenforce | grep -i -- disabled && grep -i -- ^SELINUX=disabled$ /etc/selinux/config)')).to eq 'sudo /bin/sh -c test\ \!\ -f\ /etc/selinux/config\ \|\|\ \(getenforce\ \|\ grep\ -i\ --\ disabled\ \&\&\ grep\ -i\ --\ \^SELINUX\=disabled\$\ /etc/selinux/config\)'
36
+ end
42
37
  end
43
- end
44
38
 
45
-
46
- context 'command pattern 1a' do
47
- subject { backend.build_command('test -f /etc/passwd') }
48
- it { should eq "#{sudo_path}/sudo test -f /etc/passwd" }
49
- end
50
-
51
- context 'command pattern 2a' do
52
- subject { backend.build_command('test ! -f /etc/selinux/config || (getenforce | grep -i -- disabled && grep -i -- ^SELINUX=disabled$ /etc/selinux/config)') }
53
- it { should eq "#{sudo_path}/sudo test ! -f /etc/selinux/config || (#{sudo_path}/sudo getenforce | grep -i -- disabled && #{sudo_path}/sudo grep -i -- ^SELINUX=disabled$ /etc/selinux/config)" }
54
- end
55
-
56
- context 'command pattern 3a' do
57
- subject { backend.build_command("dpkg -s apache2 && ! dpkg -s apache2 | grep -E '^Status: .+ not-installed$'") }
58
- it { should eq "#{sudo_path}/sudo dpkg -s apache2 && ! #{sudo_path}/sudo dpkg -s apache2 | grep -E '^Status: .+ not-installed$'" }
59
- end
60
-
61
- after :each do
62
- RSpec.configure do |c|
63
- c.sudo_path = nil
39
+ context 'with custom sudo path' do
40
+ before do
41
+ RSpec.configure do |c|
42
+ c.ssh = double(:ssh, :options => { :user => 'foo' })
43
+ c.sudo_path = '/usr/local/bin'
44
+ end
45
+ end
46
+
47
+ after do
48
+ RSpec.configure do |c|
49
+ c.sudo_path = nil
50
+ end
51
+ end
52
+
53
+ it 'command pattern 1a' do
54
+ expect(backend.build_command('test -f /etc/passwd')).to eq '/usr/local/bin/sudo /bin/sh -c test\ -f\ /etc/passwd'
55
+ end
56
+
57
+ it 'command pattern 2a' do
58
+ expect(backend.build_command('test ! -f /etc/selinux/config || (getenforce | grep -i -- disabled && grep -i -- ^SELINUX=disabled$ /etc/selinux/config)')).to eq '/usr/local/bin/sudo /bin/sh -c test\ \!\ -f\ /etc/selinux/config\ \|\|\ \(getenforce\ \|\ grep\ -i\ --\ disabled\ \&\&\ grep\ -i\ --\ \^SELINUX\=disabled\$\ /etc/selinux/config\)'
59
+ end
64
60
  end
65
- end
66
61
 
67
- end
62
+ context 'without sudo' do
63
+ before do
64
+ RSpec.configure do |c|
65
+ c.ssh = double(:ssh, :options => { :user => 'foo' })
66
+ c.disable_sudo = true
67
+ end
68
+ end
68
69
 
69
- describe 'build command without sudo' do
70
- before :each do
71
- RSpec.configure do |c|
72
- ssh.stub(:options) { { :user => 'foo' } }
73
- c.ssh = ssh
74
- c.disable_sudo = true
75
- end
76
- end
70
+ after do
71
+ RSpec.configure do |c|
72
+ c.disable_sudo = false
73
+ end
74
+ end
77
75
 
78
- context 'command pattern 1b' do
79
- subject { backend.build_command('test -f /etc/passwd') }
80
- it { should eq 'test -f /etc/passwd' }
81
- end
82
-
83
- context 'command pattern 2b' do
84
- subject { backend.build_command('test ! -f /etc/selinux/config || (getenforce | grep -i -- disabled && grep -i -- ^SELINUX=disabled$ /etc/selinux/config)') }
85
- it { should eq 'test ! -f /etc/selinux/config || (getenforce | grep -i -- disabled && grep -i -- ^SELINUX=disabled$ /etc/selinux/config)' }
86
- end
87
-
88
- context 'command pattern 3b' do
89
- subject { backend.build_command("dpkg -s apache2 && ! dpkg -s apache2 | grep -E '^Status: .+ not-installed$'") }
90
- it { should eq "dpkg -s apache2 && ! dpkg -s apache2 | grep -E '^Status: .+ not-installed$'" }
91
- end
92
-
93
- after :each do
94
- RSpec.configure do |c|
95
- c.disable_sudo = false
96
- end
97
- end
98
- end
76
+ it 'command pattern 1b' do
77
+ expect(backend.build_command('test -f /etc/passwd')).to eq '/bin/sh -c test\ -f\ /etc/passwd'
78
+ end
99
79
 
100
- sudo_options = ['-p', '"[sudo] password for"']
101
- sudo_options_string = ' -p "[sudo] password for"'
80
+ it 'command pattern 2b' do
81
+ expect(backend.build_command('test ! -f /etc/selinux/config || (getenforce | grep -i -- disabled && grep -i -- ^SELINUX=disabled$ /etc/selinux/config)')).to eq '/bin/sh -c test\ \!\ -f\ /etc/selinux/config\ \|\|\ \(getenforce\ \|\ grep\ -i\ --\ disabled\ \&\&\ grep\ -i\ --\ \^SELINUX\=disabled\$\ /etc/selinux/config\)'
82
+ end
102
83
 
103
- describe 'build command with sudo on alternate path' do
104
- before :each do
105
- RSpec.configure do |c|
106
- ssh.stub(:options) { { :user => 'foo' } }
107
- c.ssh = ssh
108
- c.sudo_options = sudo_options
109
84
  end
110
- end
111
85
 
112
86
 
113
- context 'command pattern 1a' do
114
- subject { backend.build_command('test -f /etc/passwd') }
115
- it { should eq "sudo#{sudo_options_string} test -f /etc/passwd" }
116
- end
117
-
118
- context 'command pattern 2a' do
119
- subject { backend.build_command('test ! -f /etc/selinux/config || (getenforce | grep -i -- disabled && grep -i -- ^SELINUX=disabled$ /etc/selinux/config)') }
120
- it { should eq "sudo#{sudo_options_string} test ! -f /etc/selinux/config || (sudo#{sudo_options_string} getenforce | grep -i -- disabled && sudo#{sudo_options_string} grep -i -- ^SELINUX=disabled$ /etc/selinux/config)" }
121
- end
122
-
123
- context 'command pattern 3a' do
124
- subject { backend.build_command("dpkg -s apache2 && ! dpkg -s apache2 | grep -E '^Status: .+ not-installed$'") }
125
- it { should eq "sudo#{sudo_options_string} dpkg -s apache2 && ! sudo#{sudo_options_string} dpkg -s apache2 | grep -E '^Status: .+ not-installed$'" }
126
- end
127
-
128
- after :each do
129
- RSpec.configure do |c|
130
- c.sudo_options = nil
87
+ context 'with sudo on alternative path' do
88
+ before do
89
+ RSpec.configure do |c|
90
+ c.ssh = double(:ssh, :options => { :user => 'foo' })
91
+ c.sudo_options = ['-p', '[sudo] password for']
92
+ c.sudo_path = nil
93
+ end
94
+ end
95
+
96
+ after do
97
+ RSpec.configure do |c|
98
+ c.sudo_options = nil
99
+ end
100
+ end
101
+
102
+ context 'command pattern 1a' do
103
+ subject { backend.build_command('test -f /etc/passwd') }
104
+ it { should eq 'sudo -p \[sudo\]\ password\ for /bin/sh -c test\ -f\ /etc/passwd' }
105
+ end
106
+
107
+ context 'command pattern 2a' do
108
+ subject { backend.build_command('test ! -f /etc/selinux/config || (getenforce | grep -i -- disabled && grep -i -- ^SELINUX=disabled$ /etc/selinux/config)') }
109
+ it { should eq 'sudo -p \[sudo\]\ password\ for /bin/sh -c test\ \!\ -f\ /etc/selinux/config\ \|\|\ \(getenforce\ \|\ grep\ -i\ --\ disabled\ \&\&\ grep\ -i\ --\ \^SELINUX\=disabled\$\ /etc/selinux/config\)' }
110
+ end
131
111
  end
132
112
  end
133
113
  end
@@ -7,8 +7,3 @@ end
7
7
  describe RSpec.configuration.path do
8
8
  it { should eq SpecInfra.configuration.path }
9
9
  end
10
-
11
- SpecInfra.configuration.os = 'foo'
12
- describe SpecInfra.configuration.os do
13
- it { should eq 'foo' }
14
- end
data/specinfra.gemspec CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
8
8
  spec.version = SpecInfra::VERSION
9
9
  spec.authors = ["Gosuke Miyashita"]
10
10
  spec.email = ["gosukenator@gmail.com"]
11
- spec.description = %q{Common layer for serverspec and itamae}
12
- spec.summary = %q{Common layer for serverspec and itamae}
11
+ spec.description = %q{Common layer for serverspec and configspec}
12
+ spec.summary = %q{Common layer for serverspec and configspec}
13
13
  spec.homepage = ""
14
14
  spec.license = "MIT"
15
15
 
@@ -21,4 +21,6 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency "bundler", "~> 1.3"
22
22
  spec.add_development_dependency "rake", "~> 10.1.1"
23
23
  spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "octokit", "~> 2.7.2"
25
+ spec.add_development_dependency "octorelease"
24
26
  end
data/wercker.yml CHANGED
@@ -1,4 +1,4 @@
1
- box: mizzy/serverspec-base@0.0.5
1
+ box: mizzy/serverspec-base
2
2
  build:
3
3
  steps:
4
4
  - script:
@@ -26,39 +26,35 @@ build:
26
26
  name: Run vagrant up centos65
27
27
  code: vagrant up centos65 --provider=digital_ocean
28
28
  cwd: $WORKING_DIR
29
- - script:
30
- name: Run itamae
31
- code: bundle exec itamae ssh --host centos65 --vagrant recipe.rb
32
- cwd: $WORKING_DIR
33
29
  - script:
34
30
  name: Run vagrant reload centos65
35
31
  code: vagrant reload centos65
36
32
  cwd: $WORKING_DIR
37
33
  - script:
38
34
  name: Run rake spec:centos65
39
- code: DIGITALOCEAN=true rake spec:centos65
40
- cwd: $WORKING_DIR
41
- - script:
42
- name: Run vagrant up ubuntu1404
43
- code: vagrant up ubuntu1404 --provider=digital_ocean
35
+ code: rake spec:centos65
44
36
  cwd: $WORKING_DIR
45
37
  - script:
46
- name: Run itamae
47
- code: bundle exec itamae ssh --host ubuntu1404 --vagrant recipe.rb
38
+ name: Run vagrant up ubuntu1310
39
+ code: vagrant up ubuntu1310 --provider=digital_ocean
48
40
  cwd: $WORKING_DIR
49
41
  - script:
50
- name: Run vagrant reload ubuntu1404
51
- code: vagrant reload ubuntu1404
42
+ name: Run vagrant reload ubuntu1310
43
+ code: vagrant reload ubuntu1310
52
44
  cwd: $WORKING_DIR
53
45
  - script:
54
- name: Run rake spec:ubuntu1404
55
- code: DIGITALOCEAN=true rake spec:ubuntu1404
46
+ name: Run rake spec:ubuntu1310
47
+ code: rake spec:ubuntu1310
56
48
  cwd: $WORKING_DIR
57
49
 
58
50
  after-steps:
59
51
  - script:
60
- name: Run vagrant destroy
61
- code: vagrant destroy --force
52
+ name: Run vagrant destroy centos65
53
+ code: vagrant destroy centos65 --force
54
+ cwd: $WORKING_DIR
55
+ - script:
56
+ name: Run vagrant destroy ubuntu1310
57
+ code: vagrant destroy ubuntu1310 --force
62
58
  cwd: $WORKING_DIR
63
59
  - 1syo/idobata-notify@0.1.1:
64
60
  token: $IDOBATA_TOKEN
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: specinfra
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.27.5
4
+ version: 2.0.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gosuke Miyashita
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-29 00:00:00.000000000 Z
11
+ date: 2014-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,7 +52,35 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- description: Common layer for serverspec and itamae
55
+ - !ruby/object:Gem::Dependency
56
+ name: octokit
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 2.7.2
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 2.7.2
69
+ - !ruby/object:Gem::Dependency
70
+ name: octorelease
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Common layer for serverspec and configspec
56
84
  email:
57
85
  - gosukenator@gmail.com
58
86
  executables: []
@@ -82,7 +110,6 @@ files:
82
110
  - lib/specinfra/backend/powershell/support/find_iis_component.ps1
83
111
  - lib/specinfra/backend/powershell/support/find_installed_application.ps1
84
112
  - lib/specinfra/backend/powershell/support/find_installed_hot_fix.ps1
85
- - lib/specinfra/backend/powershell/support/find_scheduled_task.ps1
86
113
  - lib/specinfra/backend/powershell/support/find_service.ps1
87
114
  - lib/specinfra/backend/powershell/support/find_user.ps1
88
115
  - lib/specinfra/backend/powershell/support/find_usergroup.ps1
@@ -98,17 +125,13 @@ files:
98
125
  - lib/specinfra/command/base.rb
99
126
  - lib/specinfra/command/darwin.rb
100
127
  - lib/specinfra/command/debian.rb
101
- - lib/specinfra/command/fedora.rb
102
128
  - lib/specinfra/command/freebsd.rb
103
129
  - lib/specinfra/command/freebsd10.rb
104
130
  - lib/specinfra/command/gentoo.rb
105
131
  - lib/specinfra/command/linux.rb
106
- - lib/specinfra/command/nixos.rb
107
132
  - lib/specinfra/command/openbsd.rb
108
- - lib/specinfra/command/opensuse.rb
109
133
  - lib/specinfra/command/plamo.rb
110
134
  - lib/specinfra/command/redhat.rb
111
- - lib/specinfra/command/redhat7.rb
112
135
  - lib/specinfra/command/smartos.rb
113
136
  - lib/specinfra/command/solaris.rb
114
137
  - lib/specinfra/command/solaris10.rb
@@ -132,7 +155,6 @@ files:
132
155
  - spec/backend/ssh/build_command_spec.rb
133
156
  - spec/configuration_spec.rb
134
157
  - spec/helper/backend_spec.rb
135
- - spec/helper/detect_os_spec.rb
136
158
  - spec/helper/properties_spec.rb
137
159
  - spec/spec_helper.rb
138
160
  - specinfra.gemspec
@@ -152,20 +174,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
152
174
  version: '0'
153
175
  required_rubygems_version: !ruby/object:Gem::Requirement
154
176
  requirements:
155
- - - ">="
177
+ - - ">"
156
178
  - !ruby/object:Gem::Version
157
- version: '0'
179
+ version: 1.3.1
158
180
  requirements: []
159
181
  rubyforge_project:
160
182
  rubygems_version: 2.2.2
161
183
  signing_key:
162
184
  specification_version: 4
163
- summary: Common layer for serverspec and itamae
185
+ summary: Common layer for serverspec and configspec
164
186
  test_files:
165
187
  - spec/backend/exec/build_command_spec.rb
166
188
  - spec/backend/ssh/build_command_spec.rb
167
189
  - spec/configuration_spec.rb
168
190
  - spec/helper/backend_spec.rb
169
- - spec/helper/detect_os_spec.rb
170
191
  - spec/helper/properties_spec.rb
171
192
  - spec/spec_helper.rb
@@ -1,7 +0,0 @@
1
- function FindScheduledTask
2
- {
3
- param($name)
4
-
5
- $task = schtasks /query /v /fo csv /TN "$name" | ConvertFrom-CSV
6
- return $task
7
- }
@@ -1,29 +0,0 @@
1
- module SpecInfra
2
- module Command
3
- class Fedora < RedHat
4
- def check_enabled(service, target="multi-user.target")
5
- host_port = SpecInfra.configuration.ssh ? [SpecInfra.configuration.ssh.host, SpecInfra.configuration.ssh.options[:port]] : ['localhost', nil]
6
- if property.has_key?(:os_by_host) && property[:os_by_host][host_port][:release].to_i < 15
7
- super
8
- else
9
- # Fedora 15+ uses systemd which no longer has runlevels but targets
10
- # For backwards compatibility, Fedora provides pseudo targets for
11
- # runlevels
12
- if target.is_a? Integer
13
- target = "runlevel#{target}.target"
14
- end
15
- "systemctl --plain list-dependencies #{target} | grep '^#{escape(service)}.service$'"
16
- end
17
- end
18
-
19
- def check_running(service)
20
- host_port = SpecInfra.configuration.ssh ? [SpecInfra.configuration.ssh.host, SpecInfra.configuration.ssh.options[:port]] : ['localhost', nil]
21
- if property.has_key?(:os_by_host) && property[:os_by_host][host_port][:release].to_i < 15
22
- super
23
- else
24
- "systemctl is-active #{escape(service)}.service"
25
- end
26
- end
27
- end
28
- end
29
- end
@@ -1,28 +0,0 @@
1
- module SpecInfra
2
- module Command
3
- class NixOS < Linux
4
- def check_enabled(service,level=3)
5
- level = "multi-user.target" if level == 3
6
- "systemctl --plain list-dependencies #{escape(level)} | grep '#{escape(service)}.service$'"
7
- end
8
-
9
- def check_installed(package, version=nil)
10
- if version
11
- "nix-store -q --references /var/run/current-system/sw | grep #{escape(package)}-#{escape(version)}"
12
- else
13
- "nix-store -q --references /var/run/current-system/sw | grep #{escape(package)}"
14
- end
15
- end
16
-
17
- alias :check_installed_by_nix :check_installed
18
-
19
- def check_running(service)
20
- "systemctl is-active #{escape(service)}.service"
21
- end
22
-
23
- def install(package)
24
- "nix-env -i #{package}"
25
- end
26
- end
27
- end
28
- end
@@ -1,14 +0,0 @@
1
- module SpecInfra
2
- module Command
3
- class OpenSUSE < SuSE
4
- def check_enabled(service, level=nil)
5
- "systemctl is-enabled #{escape(service)}.service"
6
- end
7
-
8
- def check_running(service)
9
- "service #{escape(service)} status"
10
- end
11
-
12
- end
13
- end
14
- end
@@ -1,9 +0,0 @@
1
- module SpecInfra
2
- module Command
3
- class RedHat7 < RedHat
4
- def check_enabled(service, level=3)
5
- "systemctl --plain list-dependencies runlevel#{level}.target | grep '^#{escape(service)}.service$'"
6
- end
7
- end
8
- end
9
- end
@@ -1,117 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe SpecInfra::Helper::DetectOS do
4
- shared_context 'no ssh connection' do
5
- before do
6
- SpecInfra.stub_chain(:configuration, :ssh).and_return(nil)
7
- end
8
- end
9
- shared_context 'existing ssh connection' do |hostname, port|
10
- before do
11
- ssh_session.stub(:host).and_return(hostname)
12
- ssh_session.stub(:options).and_return({:port => port})
13
- SpecInfra.stub_chain(:configuration, :ssh).and_return(ssh_session)
14
- end
15
- end
16
- shared_examples 'derive os from backend' do |os|
17
- before do
18
- backend.stub(:check_os).and_return(os)
19
- end
20
-
21
- it 'returns the os derived by the backend ' do
22
- expect(subject.os).to eq os
23
- end
24
- end
25
- shared_examples 'derive os from cached property' do |os|
26
- it 'returns the os derived by the property ' do
27
- expect(subject.os).to eq os
28
- end
29
- end
30
-
31
- let(:subject) { Object.new.extend SpecInfra::Helper::DetectOS }
32
- let(:backend) { double('backend') }
33
- let(:ssh_session) { double('ssh') }
34
-
35
- before do
36
- subject.stub(:backend).and_return(backend)
37
- end
38
-
39
- describe '#os' do
40
- context 'using the backend to retrieve the os' do
41
- context 'no cached values' do
42
- before do
43
- subject.property[:os_by_host] = nil
44
- end
45
-
46
- context 'with localhost' do
47
- include_context 'no ssh connection'
48
- after do
49
- expect(subject.property[:os_by_host]).to eq({['localhost', nil] => 'test os'})
50
- end
51
-
52
- include_examples 'derive os from backend', 'test os'
53
- end
54
-
55
- context 'with ssh' do
56
- include_context 'existing ssh connection', 'test.host', 123
57
- after do
58
- expect(subject.property[:os_by_host]).to eq({['test.host', 123] => 'test os'})
59
- end
60
-
61
- include_examples 'derive os from backend', 'test os'
62
- end
63
- end
64
-
65
- context 'existing cached values' do
66
- before do
67
- subject.property[:os_by_host] = {['test.host', 123] => 'cached os'}
68
- end
69
-
70
- context 'with localhost' do
71
- include_context 'no ssh connection'
72
- after do
73
- expect(property[:os_by_host]).to eq({['test.host', 123] => 'cached os', ['localhost', nil] => 'test os'})
74
- end
75
-
76
- include_examples 'derive os from backend', 'test os'
77
- end
78
-
79
- context 'with ssh' do
80
- include_context 'existing ssh connection', 'test.another.host', 456
81
- after do
82
- expect(property[:os_by_host]).to eq({['test.host', 123] => 'cached os', ['test.another.host', 456] => 'test os'})
83
- end
84
-
85
- include_examples 'derive os from backend', 'test os'
86
- end
87
-
88
- context 'same host with different ports' do
89
- include_context 'existing ssh connection', 'test.host', 456
90
-
91
- after do
92
- subject.property[:os_by_host] = {['test.host', 123] => 'cached os', ['test.host', 456] => 'test os'}
93
- end
94
-
95
- include_examples 'derive os from backend', 'test os'
96
- end
97
- end
98
- end
99
-
100
- context 'using cached values to retrieve the os' do
101
- before do
102
- subject.property[:os_by_host] = {['test.host', 123] => 'test os', ['localhost', nil] => 'local os'}
103
- end
104
- context 'with localhost' do
105
- include_context 'no ssh connection'
106
-
107
- include_examples 'derive os from cached property', 'local os'
108
- end
109
-
110
- context 'with ssh' do
111
- include_context 'existing ssh connection', 'test.host', 123
112
-
113
- include_examples 'derive os from cached property', 'test os'
114
- end
115
- end
116
- end
117
- end