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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6465c0cb3fd1e3c207bfab4b6de1e09771b4b0e8
4
- data.tar.gz: b28a47a69b3c7fc326e3ef0155d4c7d722443f71
3
+ metadata.gz: 593c624ff578dd19f008494d2c96baffdac588f2
4
+ data.tar.gz: 02e72fd3e80fb95ba6baaa8b9179648f31bed28b
5
5
  SHA512:
6
- metadata.gz: 3c8cdd616012454564afcc9593b5a91431bd46ba001ccb8bec99cd63d89faa5fe7500e714baeb6eaffeb1539a468630b6e2b37ac490be21893fbf75908c97672
7
- data.tar.gz: 8d607e79f5876652dbda649c88b206c63fb0601be455d39cc5025917f12222a6e29bd599c0760febcbc25b75f846f44380df33f4ac0c92eb32aaf7d0267b9cdb
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}" }, :exec, :ssh, :cmd, :winrm, :powershell, :helper ].flatten
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
- [:exec, :ssh, :cmd, :winrm, :powershell].each do |backend|
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
@@ -1,20 +1,20 @@
1
1
  module Serverspec
2
2
  module Helper
3
3
  [
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',
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,9 +2,11 @@ RSpec::Matchers.define :be_executable do
2
2
  match do |file|
3
3
  file.executable?(@by_whom, @by_user)
4
4
  end
5
+
5
6
  chain :by do |by_whom|
6
7
  @by_whom = by_whom
7
8
  end
9
+
8
10
  chain :by_user do |by_user|
9
11
  @by_user = by_user
10
12
  end
@@ -10,5 +10,4 @@ RSpec::Matchers.define :be_installed do
10
10
  chain :with_version do |version|
11
11
  @version = version
12
12
  end
13
-
14
13
  end
@@ -2,10 +2,12 @@ RSpec::Matchers.define :be_mounted do
2
2
  match do |path|
3
3
  path.mounted?(@attr, @only_with)
4
4
  end
5
+
5
6
  chain :with do |attr|
6
7
  @attr = attr
7
8
  @only_with = false
8
9
  end
10
+
9
11
  chain :only_with do |attr|
10
12
  @attr = attr
11
13
  @only_with = true
@@ -15,4 +15,3 @@ RSpec::Matchers.define :be_reachable do
15
15
  @attr = attr
16
16
  end
17
17
  end
18
-
@@ -2,9 +2,11 @@ RSpec::Matchers.define :be_readable do
2
2
  match do |file|
3
3
  file.readable?(@by_whom, @by_user)
4
4
  end
5
+
5
6
  chain :by do |by_whom|
6
7
  @by_whom = by_whom
7
8
  end
9
+
8
10
  chain :by_user do |by_user|
9
11
  @by_user = by_user
10
12
  end
@@ -2,8 +2,8 @@ RSpec::Matchers.define :be_resolvable do
2
2
  match do |name|
3
3
  name.resolvable?(@type)
4
4
  end
5
+
5
6
  chain :by do |type|
6
7
  @type = type
7
8
  end
8
9
  end
9
-
@@ -2,9 +2,11 @@ RSpec::Matchers.define :be_writable do
2
2
  match do |file|
3
3
  file.writable?(@by_whom, @by_user)
4
4
  end
5
+
5
6
  chain :by do |by_whom|
6
7
  @by_whom = by_whom
7
8
  end
9
+
8
10
  chain :by_user do |by_user|
9
11
  @by_user = by_user
10
12
  end
@@ -3,4 +3,3 @@ RSpec::Matchers.define :belong_to_group do |group|
3
3
  user.belongs_to_group?(group)
4
4
  end
5
5
  end
6
-
@@ -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
- subject.has_entry?(@user, entry)
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
@@ -6,9 +6,11 @@ RSpec::Matchers.define :have_rule do |rule|
6
6
  subject.has_rule?(rule)
7
7
  end
8
8
  end
9
+
9
10
  chain :with_table do |table|
10
11
  @table = table
11
12
  end
13
+
12
14
  chain :with_chain do |chain|
13
15
  @chain = chain
14
16
  end
@@ -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
- ret.stdout =~ content
6
+ stdout =~ content
10
7
  else
11
- ret.stdout.strip == content
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
- ret.stderr =~ content
14
+ stderr =~ content
19
15
  else
20
- ret.stderr.strip == content
16
+ stderr.strip == content
21
17
  end
22
18
  end
23
19
 
24
20
  def return_exit_status?(status)
25
- ret = backend.run_command(@name)
26
- ret.exit_status.to_i == status
21
+ exit_status == status
27
22
  end
28
23
 
29
24
  def stdout
30
- if @result.nil?
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
- if @result.nil?
38
- @result = backend.run_command(@name).stderr
39
- end
40
- @result
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
@@ -70,7 +70,7 @@ module Serverspec
70
70
  def match_checksum(checksum)
71
71
  backend.check_file_checksum(@name, checksum)
72
72
  end
73
-
73
+
74
74
  def match_md5checksum(md5sum)
75
75
  backend.check_file_md5checksum(@name, md5sum)
76
76
  end
@@ -6,13 +6,12 @@ module Serverspec
6
6
  end
7
7
 
8
8
  def has_dotnet_version?(dotnet)
9
- backend.check_iis_app_pool_dotnet(@name, dotnet)
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
- backend.check_iis_website_running(@name)
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
- backend.check_iis_website_path(@name, path)
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
@@ -4,6 +4,7 @@ module Serverspec
4
4
  def has_rule?(rule, table, chain)
5
5
  backend.check_iptables_rule(rule, table, chain)
6
6
  end
7
+
7
8
  def to_s
8
9
  'iptables'
9
10
  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.run_command(commands.get_process(@name, :format => "#{keyword}="))
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
@@ -2,7 +2,7 @@ module Serverspec
2
2
  module Type
3
3
  class WindowsFeature < Base
4
4
  def installed?(provider, version)
5
- backend.check_windows_feature_enabled(@name, provider)
5
+ backend.check_windows_feature_enabled(@name, provider)
6
6
  end
7
7
  end
8
8
  end
@@ -1,3 +1,3 @@
1
1
  module Serverspec
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
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.0.0
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-03-27 00:00:00.000000000 Z
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