serverspec 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +7 -2
- data/lib/serverspec/helper/os.rb +14 -14
- data/lib/serverspec/matchers/be_executable.rb +2 -0
- data/lib/serverspec/matchers/be_installed.rb +0 -1
- data/lib/serverspec/matchers/be_mounted.rb +2 -0
- data/lib/serverspec/matchers/be_reachable.rb +0 -1
- data/lib/serverspec/matchers/be_readable.rb +2 -0
- data/lib/serverspec/matchers/be_resolvable.rb +1 -1
- data/lib/serverspec/matchers/be_writable.rb +2 -0
- data/lib/serverspec/matchers/belong_to_group.rb +0 -1
- data/lib/serverspec/matchers/contain.rb +4 -0
- data/lib/serverspec/matchers/have_entry.rb +2 -1
- data/lib/serverspec/matchers/have_rule.rb +2 -0
- data/lib/serverspec/type/command.rb +17 -18
- data/lib/serverspec/type/file.rb +1 -1
- data/lib/serverspec/type/iis_app_pool.rb +1 -2
- data/lib/serverspec/type/iis_website.rb +2 -3
- data/lib/serverspec/type/iptables.rb +1 -0
- data/lib/serverspec/type/process.rb +1 -2
- data/lib/serverspec/type/windows_feature.rb +1 -1
- data/lib/serverspec/version.rb +1 -1
- data/serverspec.gemspec +1 -0
- data/spec/unit/command_spec.rb +81 -0
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 593c624ff578dd19f008494d2c96baffdac588f2
|
4
|
+
data.tar.gz: 02e72fd3e80fb95ba6baaa8b9179648f31bed28b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8e3c139f6303c2845fdeea770cd3d1515e7c10fa4a54a7e6892b7abe556c982061fbf90b8a68878d28d00469c83c59b0a4b53f8b5b8ee9d52d62f9ec8fc5555
|
7
|
+
data.tar.gz: 173e75bf9d20f30f1f29b978d68d6d7105fdffb9f30432f4d6e8a73cc785a7da02e5e02f37f23664d0d2cd11b39b3ea285fc45af55798d585dc568ff55cf0924
|
data/Rakefile
CHANGED
@@ -6,8 +6,9 @@ task :spec => 'spec:all'
|
|
6
6
|
|
7
7
|
namespace :spec do
|
8
8
|
oses = %w( darwin debian gentoo plamo redhat aix solaris solaris10 solaris11 smartos windows freebsd freebsd10)
|
9
|
+
backends = %w( exec ssh cmd winrm powershell )
|
9
10
|
|
10
|
-
task :all => [ oses.map {|os| "spec:#{os}" },
|
11
|
+
task :all => [ oses.map {|os| "spec:#{os}" }, backends, :helper, :unit ].flatten
|
11
12
|
|
12
13
|
oses.each do |os|
|
13
14
|
RSpec::Core::RakeTask.new(os.to_sym) do |t|
|
@@ -15,7 +16,7 @@ namespace :spec do
|
|
15
16
|
end
|
16
17
|
end
|
17
18
|
|
18
|
-
|
19
|
+
backends.each do |backend|
|
19
20
|
RSpec::Core::RakeTask.new(backend) do |t|
|
20
21
|
t.pattern = "spec/backend/#{backend.to_s}/*_spec.rb"
|
21
22
|
end
|
@@ -24,4 +25,8 @@ namespace :spec do
|
|
24
25
|
RSpec::Core::RakeTask.new(:helper) do |t|
|
25
26
|
t.pattern = "spec/helper/*_spec.rb"
|
26
27
|
end
|
28
|
+
|
29
|
+
RSpec::Core::RakeTask.new(:unit) do |t|
|
30
|
+
t.pattern = "spec/unit/*_spec.rb"
|
31
|
+
end
|
27
32
|
end
|
data/lib/serverspec/helper/os.rb
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
module Serverspec
|
2
2
|
module Helper
|
3
3
|
[
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
4
|
+
'DetectOS',
|
5
|
+
'AIX',
|
6
|
+
'Darwin',
|
7
|
+
'Debian',
|
8
|
+
'FreeBSD',
|
9
|
+
'FreeBSD10',
|
10
|
+
'Gentoo',
|
11
|
+
'Plamo',
|
12
|
+
'RedHat',
|
13
|
+
'SmartOS',
|
14
|
+
'Solaris',
|
15
|
+
'Solaris10',
|
16
|
+
'Solaris11',
|
17
|
+
'Windows',
|
18
18
|
].each do |os|
|
19
19
|
eval <<-EOF
|
20
20
|
module #{os}
|
@@ -2,17 +2,21 @@ RSpec::Matchers.define :contain do |pattern|
|
|
2
2
|
match do |file|
|
3
3
|
file.contain(pattern, @from, @to)
|
4
4
|
end
|
5
|
+
|
5
6
|
# for contain(pattern).from(/A/).to(/B/)
|
6
7
|
chain :from do |from|
|
7
8
|
@from = Regexp.new(from).inspect
|
8
9
|
end
|
10
|
+
|
9
11
|
chain :to do |to|
|
10
12
|
@to = Regexp.new(to).inspect
|
11
13
|
end
|
14
|
+
|
12
15
|
# for contain(pattern).after(/A/)
|
13
16
|
chain :after do |after|
|
14
17
|
@from = Regexp.new(after).inspect
|
15
18
|
end
|
19
|
+
|
16
20
|
# for contain(pattern).before(/B/)
|
17
21
|
chain :before do |before|
|
18
22
|
@to = Regexp.new(before).inspect
|
@@ -1,11 +1,12 @@
|
|
1
1
|
RSpec::Matchers.define :have_entry do |entry|
|
2
2
|
match do |subject|
|
3
3
|
if subject.class.name == 'Serverspec::Type::Cron'
|
4
|
-
|
4
|
+
subject.has_entry?(@user, entry)
|
5
5
|
elsif subject.respond_to?(:has_entry?)
|
6
6
|
subject.has_entry?(entry)
|
7
7
|
end
|
8
8
|
end
|
9
|
+
|
9
10
|
# For cron type
|
10
11
|
chain :with_user do |user|
|
11
12
|
@user = user
|
@@ -1,43 +1,42 @@
|
|
1
1
|
module Serverspec
|
2
2
|
module Type
|
3
3
|
class Command < Base
|
4
|
-
attr_accessor :result
|
5
|
-
|
6
4
|
def return_stdout?(content)
|
7
|
-
ret = backend.run_command(@name)
|
8
5
|
if content.instance_of?(Regexp)
|
9
|
-
|
6
|
+
stdout =~ content
|
10
7
|
else
|
11
|
-
|
8
|
+
stdout.strip == content
|
12
9
|
end
|
13
10
|
end
|
14
11
|
|
15
12
|
def return_stderr?(content)
|
16
|
-
ret = backend.run_command(@name)
|
17
13
|
if content.instance_of?(Regexp)
|
18
|
-
|
14
|
+
stderr =~ content
|
19
15
|
else
|
20
|
-
|
16
|
+
stderr.strip == content
|
21
17
|
end
|
22
18
|
end
|
23
19
|
|
24
20
|
def return_exit_status?(status)
|
25
|
-
|
26
|
-
ret.exit_status.to_i == status
|
21
|
+
exit_status == status
|
27
22
|
end
|
28
23
|
|
29
24
|
def stdout
|
30
|
-
|
31
|
-
@result = backend.run_command(@name).stdout
|
32
|
-
end
|
33
|
-
@result
|
25
|
+
command_result.stdout
|
34
26
|
end
|
35
27
|
|
36
28
|
def stderr
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
29
|
+
command_result.stderr
|
30
|
+
end
|
31
|
+
|
32
|
+
def exit_status
|
33
|
+
command_result.exit_status.to_i
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def command_result()
|
39
|
+
@command_result ||= backend.run_command(@name)
|
41
40
|
end
|
42
41
|
end
|
43
42
|
end
|
data/lib/serverspec/type/file.rb
CHANGED
@@ -6,13 +6,12 @@ module Serverspec
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def has_dotnet_version?(dotnet)
|
9
|
-
|
9
|
+
backend.check_iis_app_pool_dotnet(@name, dotnet)
|
10
10
|
end
|
11
11
|
|
12
12
|
def to_s
|
13
13
|
%Q[IIS Application Pool "#{@name}"]
|
14
14
|
end
|
15
|
-
|
16
15
|
end
|
17
16
|
end
|
18
17
|
end
|
@@ -11,7 +11,7 @@ module Serverspec
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def running?()
|
14
|
-
|
14
|
+
backend.check_iis_website_running(@name)
|
15
15
|
end
|
16
16
|
|
17
17
|
def in_app_pool?(app_pool)
|
@@ -19,13 +19,12 @@ module Serverspec
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def has_physical_path?(path)
|
22
|
-
|
22
|
+
backend.check_iis_website_path(@name, path)
|
23
23
|
end
|
24
24
|
|
25
25
|
def to_s
|
26
26
|
%Q[IIS Website "#{@name}"]
|
27
27
|
end
|
28
|
-
|
29
28
|
end
|
30
29
|
end
|
31
30
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
module Serverspec
|
2
2
|
module Type
|
3
3
|
class Process < Base
|
4
|
-
|
5
4
|
def running?
|
6
5
|
pid = backend.run_command(commands.get_process(@name, :format => "pid=")).stdout
|
7
6
|
not pid.empty?
|
@@ -20,7 +19,7 @@ module Serverspec
|
|
20
19
|
end
|
21
20
|
|
22
21
|
def get_column(keyword)
|
23
|
-
ret = backend.
|
22
|
+
ret = backend.get_process(@name, :format => "#{keyword}=")
|
24
23
|
val = ret.stdout.strip
|
25
24
|
val = val.to_i if val.match(/^\d+$/)
|
26
25
|
val
|
data/lib/serverspec/version.rb
CHANGED
data/serverspec.gemspec
CHANGED
@@ -24,5 +24,6 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_runtime_dependency "specinfra", ">= 1.0.0"
|
25
25
|
spec.add_development_dependency "bundler", "~> 1.3"
|
26
26
|
spec.add_development_dependency "rake", "~> 10.1.1"
|
27
|
+
spec.add_development_dependency "octokit", "~> 2.7.2"
|
27
28
|
spec.add_development_dependency "octorelease"
|
28
29
|
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Serverspec::Type::Command do
|
4
|
+
subject { command('echo banana') }
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
allow(subject.backend).to receive(:run_command).and_return(
|
8
|
+
CommandResult.new({
|
9
|
+
:stdout => "banana\n",
|
10
|
+
:stderr => "split\n",
|
11
|
+
:exit_status => "42", # Command should convert this to an integer
|
12
|
+
})
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'has stdout' do
|
17
|
+
expect(subject.stdout).to be == "banana\n"
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'has stderr' do
|
21
|
+
expect(subject.stderr).to be == "split\n"
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'has exit_status' do
|
25
|
+
expect(subject.exit_status).to be == 42
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'does not conflate stdout and stderr' do
|
29
|
+
expect(subject.stdout).to eq("banana\n")
|
30
|
+
expect(subject.stderr).to eq("split\n")
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'runs the command lazily' do
|
34
|
+
expect(subject.backend).to receive(:run_command).exactly(0).times
|
35
|
+
|
36
|
+
# Not sending any messages to the subject.
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'does not run the command more than once' do
|
40
|
+
expect(subject.backend).to receive(:run_command).once
|
41
|
+
|
42
|
+
# We can send all these messages, but the command is invoked only once.
|
43
|
+
subject.stdout
|
44
|
+
subject.stderr
|
45
|
+
subject.exit_status
|
46
|
+
subject.return_stdout? 'foo'
|
47
|
+
subject.return_stderr? 'foo'
|
48
|
+
subject.return_exit_status? 0
|
49
|
+
end
|
50
|
+
|
51
|
+
describe '#return_stdout?' do
|
52
|
+
it 'matches against a string, stripping whitespace' do
|
53
|
+
expect(subject.return_stdout? 'banana').to be_true
|
54
|
+
expect(subject.return_stdout? 'pancake').to be_false
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'matches against a regex' do
|
58
|
+
expect(subject.return_stdout? /anan/).to be_true
|
59
|
+
expect(subject.return_stdout? /^anan/).to be_false
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe '#return_stderr?' do
|
64
|
+
it 'matches against a string, stripping whitespace' do
|
65
|
+
expect(subject.return_stderr? 'split').to be_true
|
66
|
+
expect(subject.return_stderr? 'pancake').to be_false
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'matches against a regex' do
|
70
|
+
expect(subject.return_stderr? /pli/).to be_true
|
71
|
+
expect(subject.return_stderr? /^pli/).to be_false
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe '#return_stderr?' do
|
76
|
+
it 'matches against an integer' do
|
77
|
+
expect(subject.return_exit_status? 42).to be_true
|
78
|
+
expect(subject.return_exit_status? 43).to be_false
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: serverspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
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-
|
11
|
+
date: 2014-04-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: net-ssh
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: 10.1.1
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: octokit
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 2.7.2
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 2.7.2
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
112
|
name: octorelease
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -366,6 +380,7 @@ files:
|
|
366
380
|
- spec/solaris11/zfs_spec.rb
|
367
381
|
- spec/spec_helper.rb
|
368
382
|
- spec/support/powershell_command_runner.rb
|
383
|
+
- spec/unit/command_spec.rb
|
369
384
|
- spec/windows/command_spec.rb
|
370
385
|
- spec/windows/file_spec.rb
|
371
386
|
- spec/windows/group_spec.rb
|
@@ -578,6 +593,7 @@ test_files:
|
|
578
593
|
- spec/solaris11/zfs_spec.rb
|
579
594
|
- spec/spec_helper.rb
|
580
595
|
- spec/support/powershell_command_runner.rb
|
596
|
+
- spec/unit/command_spec.rb
|
581
597
|
- spec/windows/command_spec.rb
|
582
598
|
- spec/windows/file_spec.rb
|
583
599
|
- spec/windows/group_spec.rb
|