serverspec 0.3.2 → 0.4.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.
@@ -1,6 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe 'Serverspec matchers of Red Hat family', :os => :redhat do
3
+ include Serverspec::Helper::RedHat
4
+
5
+ describe 'Serverspec matchers of Red Hat family' do
4
6
  it_behaves_like 'support be_enabled matcher', 'sshd'
5
7
  it_behaves_like 'support be_installed matcher', 'openssh'
6
8
  it_behaves_like 'support be_running matcher', 'sshd'
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ include Serverspec::Helper::RedHat
4
+
5
+ describe 'Serverspec service matchers of Red Hat family' do
6
+ it_behaves_like 'support service enabled matcher', 'sshd'
7
+ it_behaves_like 'support service running matcher', 'sshd'
8
+ it_behaves_like 'support service running under supervisor matcher', 'sshd'
9
+ it_behaves_like 'support service running under unimplemented matcher', 'sshd'
10
+ end
@@ -1,26 +1,28 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe 'check_enabled', :os => :solaris do
3
+ include Serverspec::Helper::Solaris
4
+
5
+ describe 'check_enabled' do
4
6
  subject { commands.check_enabled('httpd') }
5
7
  it { should eq "svcs -l httpd 2> /dev/null | grep 'enabled true'" }
6
8
  end
7
9
 
8
- describe 'check_file', :os => :solaris do
10
+ describe 'check_file' do
9
11
  subject { commands.check_file('/etc/passwd') }
10
12
  it { should eq 'test -f /etc/passwd' }
11
13
  end
12
14
 
13
- describe 'check_mounted', :os => :solaris do
15
+ describe 'check_mounted' do
14
16
  subject { commands.check_mounted('/') }
15
17
  it { should eq "mount | grep -w -- on\\ /" }
16
18
  end
17
19
 
18
- describe 'check_routing_table', :os => :solaris do
20
+ describe 'check_routing_table' do
19
21
  subject { commands.check_routing_table('192.168.100.0/24') }
20
22
  it { should eq "ip route | grep -E '^192.168.100.0/24 |^default '" }
21
23
  end
22
24
 
23
- describe 'check_reachable', :os => :solaris do
25
+ describe 'check_reachable' do
24
26
  context "connect with name from /etc/services to localhost" do
25
27
  subject { commands.check_reachable('localhost', 'ssh', 'tcp', 1) }
26
28
  it { should eq "nc -vvvvzt localhost ssh -w 1" }
@@ -35,7 +37,7 @@ describe 'check_reachable', :os => :solaris do
35
37
  end
36
38
  end
37
39
 
38
- describe 'check_resolvable', :os => :solaris do
40
+ describe 'check_resolvable' do
39
41
  context "resolve localhost by hosts" do
40
42
  subject { commands.check_resolvable('localhost', 'hosts') }
41
43
  it { should eq "grep -w -- localhost /etc/hosts" }
@@ -50,52 +52,52 @@ describe 'check_resolvable', :os => :solaris do
50
52
  end
51
53
  end
52
54
 
53
- describe 'check_directory', :os => :solaris do
55
+ describe 'check_directory' do
54
56
  subject { commands.check_directory('/var/log') }
55
57
  it { should eq 'test -d /var/log' }
56
58
  end
57
59
 
58
- describe 'check_user', :os => :solaris do
60
+ describe 'check_user' do
59
61
  subject { commands.check_user('root') }
60
62
  it { should eq 'id root' }
61
63
  end
62
64
 
63
- describe 'check_group', :os => :solaris do
65
+ describe 'check_group' do
64
66
  subject { commands.check_group('wheel') }
65
67
  it { should eq 'getent group | grep -wq -- wheel' }
66
68
  end
67
69
 
68
- describe 'check_installed', :os => :solaris do
70
+ describe 'check_installed' do
69
71
  subject { commands.check_installed('httpd') }
70
72
  it { should eq 'pkg list -H httpd 2> /dev/null' }
71
73
  end
72
74
 
73
- describe 'check_listening', :os => :solaris do
75
+ describe 'check_listening' do
74
76
  subject { commands.check_listening(80) }
75
77
  it { should eq "netstat -an 2> /dev/null | egrep 'LISTEN|Idle' | grep -- .80\\ " }
76
78
  end
77
79
 
78
- describe 'check_running', :os => :solaris do
80
+ describe 'check_running' do
79
81
  subject { commands.check_running('httpd') }
80
82
  it { should eq "svcs -l httpd status 2> /dev/null |grep 'state online'" }
81
83
  end
82
84
 
83
- describe 'check_running_under_supervisor', :os => :solaris do
85
+ describe 'check_running_under_supervisor' do
84
86
  subject { commands.check_running_under_supervisor('httpd') }
85
87
  it { should eq 'supervisorctl status httpd' }
86
88
  end
87
89
 
88
- describe 'check_process', :os => :solaris do
90
+ describe 'check_process' do
89
91
  subject { commands.check_process('httpd') }
90
92
  it { should eq 'ps aux | grep -w -- httpd | grep -qv grep' }
91
93
  end
92
94
 
93
- describe 'check_file_contain', :os => :solaris do
95
+ describe 'check_file_contain' do
94
96
  subject { commands.check_file_contain('/etc/passwd', 'root') }
95
97
  it { should eq "grep -q -- root /etc/passwd" }
96
98
  end
97
99
 
98
- describe 'check_file_contain_within', :os => :solaris do
100
+ describe 'check_file_contain_within' do
99
101
  context 'contain a pattern in the file' do
100
102
  subject { commands.check_file_contain_within('Gemfile', 'rspec') }
101
103
  it { should eq "sed -n 1,\\$p Gemfile | grep -q -- rspec /dev/stdin" }
@@ -117,67 +119,67 @@ describe 'check_file_contain_within', :os => :solaris do
117
119
  end
118
120
  end
119
121
 
120
- describe 'check_file_md5checksum', :os => :solaris do
122
+ describe 'check_file_md5checksum' do
121
123
  subject { commands.check_file_md5checksum('/etc/passwd', '96c8c50f81a29965f7af6de371ab4250') }
122
124
  it { should eq "md5sum /etc/passwd | grep -iw -- ^96c8c50f81a29965f7af6de371ab4250" }
123
125
  end
124
126
 
125
- describe 'check_mode', :os => :solaris do
127
+ describe 'check_mode' do
126
128
  subject { commands.check_mode('/etc/sudoers', 440) }
127
129
  it { should eq 'stat -c %a /etc/sudoers | grep -- \\^440\\$' }
128
130
  end
129
131
 
130
- describe 'check_owner', :os => :solaris do
132
+ describe 'check_owner' do
131
133
  subject { commands.check_owner('/etc/passwd', 'root') }
132
134
  it { should eq 'stat -c %U /etc/passwd | grep -- \\^root\\$' }
133
135
  end
134
136
 
135
- describe 'check_grouped', :os => :solaris do
137
+ describe 'check_grouped' do
136
138
  subject { commands.check_grouped('/etc/passwd', 'wheel') }
137
139
  it { should eq 'stat -c %G /etc/passwd | grep -- \\^wheel\\$' }
138
140
  end
139
141
 
140
- describe 'check_cron_entry', :os => :solaris do
142
+ describe 'check_cron_entry' do
141
143
  subject { commands.check_cron_entry('root', '* * * * * /usr/local/bin/batch.sh') }
142
144
  it { should eq 'crontab -l root | grep -- \\\\\\*\\ \\\\\\*\\ \\\\\\*\\ \\\\\\*\\ \\\\\\*\\ /usr/local/bin/batch.sh' }
143
145
  end
144
146
 
145
- describe 'check_link', :os => :solaris do
147
+ describe 'check_link' do
146
148
  subject { commands.check_link('/etc/system-release', '/etc/redhat-release') }
147
149
  it { should eq 'stat -c %N /etc/system-release | grep -- /etc/redhat-release' }
148
150
  end
149
151
 
150
- describe 'check_installed_by_gem', :os => :solaris do
152
+ describe 'check_installed_by_gem' do
151
153
  subject { commands.check_installed_by_gem('jekyll') }
152
154
  it { should eq 'gem list --local | grep -- \\^jekyll\\ ' }
153
155
  end
154
156
 
155
- describe 'check_belonging_group', :os => :solaris do
157
+ describe 'check_belonging_group' do
156
158
  subject { commands.check_belonging_group('root', 'wheel') }
157
159
  it { should eq "id -Gn root | grep -- wheel" }
158
160
  end
159
161
 
160
- describe 'have_gid', :os => :solaris do
162
+ describe 'have_gid' do
161
163
  subject { commands.check_gid('root', 0) }
162
164
  it { should eq "getent group | grep -- \\^root: | cut -f 3 -d ':' | grep -w -- 0" }
163
165
  end
164
166
 
165
- describe 'have_uid', :os => :solaris do
167
+ describe 'have_uid' do
166
168
  subject { commands.check_uid('root', 0) }
167
169
  it { should eq "id root | grep -- \\^uid\\=0\\(" }
168
170
  end
169
171
 
170
- describe 'have_login_shell', :os => :solaris do
172
+ describe 'have_login_shell' do
171
173
  subject { commands.check_login_shell('root', '/bin/bash') }
172
174
  it { should eq "getent passwd root | cut -f 7 -d ':' | grep -w -- /bin/bash" }
173
175
  end
174
176
 
175
- describe 'have_home_directory', :os => :solaris do
177
+ describe 'have_home_directory' do
176
178
  subject { commands.check_home_directory('root', '/root') }
177
179
  it { should eq "getent passwd root | cut -f 6 -d ':' | grep -w -- /root" }
178
180
  end
179
181
 
180
- describe 'have_authorized_key', :os => :solaris do
182
+ describe 'have_authorized_key' do
181
183
  key = "ssh-rsa ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGH"
182
184
  escaped_key = key.gsub(/ /, '\ ')
183
185
 
@@ -195,7 +197,7 @@ describe 'have_authorized_key', :os => :solaris do
195
197
  end
196
198
  end
197
199
 
198
- describe 'check_zfs', :os => :solaris do
200
+ describe 'check_zfs' do
199
201
  context 'check without properties' do
200
202
  subject { commands.check_zfs('rpool') }
201
203
  it { should eq "/sbin/zfs list -H rpool" }
@@ -212,27 +214,27 @@ describe 'check_zfs', :os => :solaris do
212
214
  end
213
215
  end
214
216
 
215
- describe 'get_mode', :os => :solaris do
217
+ describe 'get_mode' do
216
218
  subject { commands.get_mode('/dev') }
217
219
  it { should eq 'stat -c %a /dev' }
218
220
  end
219
221
 
220
- describe 'check_ip_filter_rule', :os => :solaris do
222
+ describe 'check_ip_filter_rule' do
221
223
  subject { commands.check_ipfilter_rule('pass in quick on lo0 all') }
222
224
  it { should eq "/sbin/ipfstat -io 2> /dev/null | grep -- pass\\ in\\ quick\\ on\\ lo0\\ all" }
223
225
  end
224
226
 
225
- describe 'check_ipnat_rule', :os => :solaris do
227
+ describe 'check_ipnat_rule' do
226
228
  subject { commands.check_ipnat_rule('map net1 192.168.0.0/24 -> 0.0.0.0/32') }
227
229
  it { should eq "/sbin/ipnat -l 2> /dev/null | grep -- \\^map\\ net1\\ 192.168.0.0/24\\ -\\>\\ 0.0.0.0/32\\$" }
228
230
  end
229
231
 
230
- describe 'check_svcprop', :os => :solaris do
232
+ describe 'check_svcprop' do
231
233
  subject { commands.check_svcprop('svc:/network/http:apache22', 'httpd/enable_64bit','false') }
232
234
  it { should eq "svcprop -p httpd/enable_64bit svc:/network/http:apache22 | grep -- \\^false\\$" }
233
235
  end
234
236
 
235
- describe 'check_svcprops', :os => :solaris do
237
+ describe 'check_svcprops' do
236
238
  subject {
237
239
  commands.check_svcprops('svc:/network/http:apache22', {
238
240
  'httpd/enable_64bit' => 'false',
@@ -242,7 +244,7 @@ describe 'check_svcprops', :os => :solaris do
242
244
  it { should eq "svcprop -p httpd/enable_64bit svc:/network/http:apache22 | grep -- \\^false\\$ && svcprop -p httpd/server_type svc:/network/http:apache22 | grep -- \\^worker\\$" }
243
245
  end
244
246
 
245
- describe 'check_access_by_user', :os => :solaris do
247
+ describe 'check_access_by_user' do
246
248
  context 'read access' do
247
249
  subject {commands.check_access_by_user '/tmp/something', 'dummyuser1', 'r'}
248
250
  it { should eq 'su dummyuser1 -c "/usr/bin/test -r /tmp/something"' }
@@ -1,6 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe 'Serverspec matchers of Solaris family', :os => :solaris do
3
+ include Serverspec::Helper::Solaris
4
+
5
+ describe 'Serverspec matchers of Solaris family' do
4
6
  it_behaves_like 'support be_enabled matcher', 'svc:/network/ssh:default'
5
7
  it_behaves_like 'support be_installed matcher', 'service/network/ssh'
6
8
  it_behaves_like 'support be_running matcher', 'svc:/network/ssh:default'
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ include Serverspec::Helper::Solaris
4
+
5
+ describe 'Serverspec service matchers of Red Hat family' do
6
+ it_behaves_like 'support service enabled matcher', 'sshd'
7
+ it_behaves_like 'support service running matcher', 'sshd'
8
+ it_behaves_like 'support service running under supervisor matcher', 'sshd'
9
+ it_behaves_like 'support service running under unimplemented matcher', 'sshd'
10
+ end
@@ -0,0 +1,72 @@
1
+ shared_examples_for 'support service enabled matcher' do |valid_service|
2
+ describe 'be_enabled' do
3
+ describe service(valid_service) do
4
+ it { should be_enabled }
5
+ end
6
+
7
+ describe service('invalid-service') do
8
+ it { should_not be_enabled }
9
+ end
10
+ end
11
+ end
12
+
13
+ shared_examples_for 'support service running matcher' do |valid_service|
14
+ describe 'be_running' do
15
+ describe service(valid_service) do
16
+ it { should be_running }
17
+ end
18
+
19
+ describe service('invalid-daemon') do
20
+ it { should_not be_running }
21
+ end
22
+
23
+ describe service(valid_service) do
24
+ before :all do
25
+ RSpec.configure do |c|
26
+ c.stdout = "#{valid_service} is stopped\r\n"
27
+ end
28
+ end
29
+ it { should be_running }
30
+ end
31
+ end
32
+ end
33
+
34
+ shared_examples_for 'support service running under supervisor matcher' do |valid_service|
35
+ describe 'be_running.under("supervisor")' do
36
+ describe service(valid_service) do
37
+ before :all do
38
+ RSpec.configure do |c|
39
+ c.stdout = "#{valid_service} RUNNING\r\n"
40
+ end
41
+ end
42
+
43
+ it { should be_running.under('supervisor') }
44
+ end
45
+
46
+ describe service(valid_service) do
47
+ before :all do
48
+ RSpec.configure do |c|
49
+ c.stdout = "#{valid_service} STOPPED\r\n"
50
+ end
51
+ end
52
+
53
+ it { should_not be_running.under('supervisor') }
54
+ end
55
+
56
+ describe service('invalid-daemon') do
57
+ it { should_not be_running.under('supervisor') }
58
+ end
59
+ end
60
+ end
61
+
62
+ shared_examples_for 'support service running under unimplemented matcher' do |valid_service|
63
+ describe 'be_running.under("not implemented")' do
64
+ describe service(valid_service) do
65
+ it {
66
+ expect {
67
+ should be_running.under('not implemented')
68
+ }.to raise_error(ArgumentError, %r/\A`be_running` matcher doesn\'t support/)
69
+ }
70
+ end
71
+ end
72
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: serverspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-14 00:00:00.000000000 Z
12
+ date: 2013-05-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: net-ssh
@@ -32,17 +32,17 @@ dependencies:
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  none: false
34
34
  requirements:
35
- - - ! '>='
35
+ - - ~>
36
36
  - !ruby/object:Gem::Version
37
- version: '0'
37
+ version: '2.0'
38
38
  type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
- - - ! '>='
43
+ - - ~>
44
44
  - !ruby/object:Gem::Version
45
- version: '0'
45
+ version: '2.0'
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: highline
48
48
  requirement: !ruby/object:Gem::Requirement
@@ -133,6 +133,7 @@ files:
133
133
  - lib/serverspec/helper/redhat.rb
134
134
  - lib/serverspec/helper/solaris.rb
135
135
  - lib/serverspec/helper/ssh.rb
136
+ - lib/serverspec/helper/type.rb
136
137
  - lib/serverspec/matchers.rb
137
138
  - lib/serverspec/matchers/be_default_gateway.rb
138
139
  - lib/serverspec/matchers/be_directory.rb
@@ -179,21 +180,28 @@ files:
179
180
  - lib/serverspec/matchers/return_stdout.rb
180
181
  - lib/serverspec/setup.rb
181
182
  - lib/serverspec/subject.rb
183
+ - lib/serverspec/type/service.rb
182
184
  - lib/serverspec/version.rb
183
185
  - serverspec.gemspec
184
186
  - spec/darwin/commands_spec.rb
185
187
  - spec/darwin/matchers_spec.rb
188
+ - spec/darwin/service_spec.rb
186
189
  - spec/debian/commands_spec.rb
187
190
  - spec/debian/matchers_spec.rb
191
+ - spec/debian/service_spec.rb
188
192
  - spec/gentoo/commands_spec.rb
189
193
  - spec/gentoo/matchers_spec.rb
194
+ - spec/gentoo/service_spec.rb
190
195
  - spec/helpers/attributes_spec.rb
191
196
  - spec/redhat/commands_spec.rb
192
197
  - spec/redhat/matchers_spec.rb
198
+ - spec/redhat/service_spec.rb
193
199
  - spec/solaris/commands_spec.rb
194
200
  - spec/solaris/matchers_spec.rb
201
+ - spec/solaris/service_spec.rb
195
202
  - spec/spec_helper.rb
196
203
  - spec/support/shared_matcher_examples.rb
204
+ - spec/support/shared_service_examples.rb
197
205
  homepage: http://serverspec.org/
198
206
  licenses:
199
207
  - MIT
@@ -222,14 +230,20 @@ summary: RSpec tests for your servers provisioned by Puppet, Chef or anything el
222
230
  test_files:
223
231
  - spec/darwin/commands_spec.rb
224
232
  - spec/darwin/matchers_spec.rb
233
+ - spec/darwin/service_spec.rb
225
234
  - spec/debian/commands_spec.rb
226
235
  - spec/debian/matchers_spec.rb
236
+ - spec/debian/service_spec.rb
227
237
  - spec/gentoo/commands_spec.rb
228
238
  - spec/gentoo/matchers_spec.rb
239
+ - spec/gentoo/service_spec.rb
229
240
  - spec/helpers/attributes_spec.rb
230
241
  - spec/redhat/commands_spec.rb
231
242
  - spec/redhat/matchers_spec.rb
243
+ - spec/redhat/service_spec.rb
232
244
  - spec/solaris/commands_spec.rb
233
245
  - spec/solaris/matchers_spec.rb
246
+ - spec/solaris/service_spec.rb
234
247
  - spec/spec_helper.rb
235
248
  - spec/support/shared_matcher_examples.rb
249
+ - spec/support/shared_service_examples.rb