chef-rewind 0.0.8 → 0.0.9
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.
- checksums.yaml +4 -4
- data/.gitignore +6 -0
- data/.kitchen.yml +26 -0
- data/.travis.yml +11 -0
- data/Berksfile +4 -0
- data/Gemfile +5 -34
- data/README.md +6 -2
- data/Rakefile +10 -0
- data/chef-rewind.gemspec +1 -1
- data/gemfiles/chef-11.gemfile +7 -0
- data/gemfiles/chef-12.gemfile +7 -0
- data/lib/chef/rewind.rb +45 -15
- data/spec/data/cookbooks/rewind/Berksfile +3 -0
- data/spec/data/cookbooks/rewind/README.md +1 -0
- data/spec/data/cookbooks/rewind/files/default/test/default_test.rb +21 -0
- data/spec/data/cookbooks/rewind/metadata.rb +7 -0
- data/spec/data/cookbooks/rewind/recipes/base.rb +11 -0
- data/spec/data/cookbooks/rewind/recipes/default.rb +12 -0
- data/spec/rewind_recipe_spec.rb +10 -11
- data/spec/rewind_resource_spec.rb +2 -2
- data/spec/spec_helper.rb +0 -44
- data/spec/unwind_recipe_spec.rb +34 -5
- metadata +23 -89
- data/spec/data/cookbooks/angrybash/recipes/default.rb +0 -8
- data/spec/data/cookbooks/apache2/files/default/apache2_module_conf_generate.pl +0 -2
- data/spec/data/cookbooks/apache2/recipes/default.rb +0 -3
- data/spec/data/cookbooks/borken/recipes/default.rb +0 -2
- data/spec/data/cookbooks/borken/templates/default/borken.erb +0 -2
- data/spec/data/cookbooks/chefignore +0 -6
- data/spec/data/cookbooks/java/files/default/java.response +0 -2
- data/spec/data/cookbooks/openldap/attributes/default.rb +0 -16
- data/spec/data/cookbooks/openldap/attributes/smokey.rb +0 -1
- data/spec/data/cookbooks/openldap/definitions/client.rb +0 -5
- data/spec/data/cookbooks/openldap/definitions/server.rb +0 -5
- data/spec/data/cookbooks/openldap/files/default/.dotfile +0 -1
- data/spec/data/cookbooks/openldap/files/default/.ssh/id_rsa +0 -1
- data/spec/data/cookbooks/openldap/files/default/remotedir/.a_dotdir/.a_dotfile_in_a_dotdir +0 -1
- data/spec/data/cookbooks/openldap/files/default/remotedir/remote_dir_file1.txt +0 -3
- data/spec/data/cookbooks/openldap/files/default/remotedir/remote_dir_file2.txt +0 -3
- data/spec/data/cookbooks/openldap/files/default/remotedir/remotesubdir/.a_dotfile +0 -1
- data/spec/data/cookbooks/openldap/files/default/remotedir/remotesubdir/remote_subdir_file1.txt +0 -3
- data/spec/data/cookbooks/openldap/files/default/remotedir/remotesubdir/remote_subdir_file2.txt +0 -3
- data/spec/data/cookbooks/openldap/files/default/remotedir/subdir_with_no_file_just_a_subsubdir/the_subsubdir/some_file.txt +0 -3
- data/spec/data/cookbooks/openldap/recipes/default.rb +0 -3
- data/spec/data/cookbooks/openldap/recipes/gigantor.rb +0 -3
- data/spec/data/cookbooks/openldap/recipes/one.rb +0 -15
- data/spec/data/cookbooks/openldap/templates/default/openldap_stuff.conf.erb +0 -1
- data/spec/data/cookbooks/openldap/templates/default/openldap_variable_stuff.conf.erb +0 -1
- data/spec/data/cookbooks/openldap/templates/default/test.erb +0 -1
- data/spec/support/lib/chef/provider/easy.rb +0 -35
- data/spec/support/lib/chef/provider/snakeoil.rb +0 -40
- data/spec/support/lib/chef/resource/one_two_three_four.rb +0 -43
- data/spec/support/matchers/leak.rb +0 -96
- data/spec/support/mock/constant.rb +0 -52
- data/spec/support/mock/platform.rb +0 -18
- data/spec/support/platform_helpers.rb +0 -31
- data/spec/support/platforms/prof/gc.rb +0 -54
- data/spec/support/platforms/prof/win32.rb +0 -46
- data/spec/support/shared/functional/directory_resource.rb +0 -85
- data/spec/support/shared/functional/file_resource.rb +0 -173
- data/spec/support/shared/functional/knife.rb +0 -37
- data/spec/support/shared/functional/securable_resource.rb +0 -394
- data/spec/support/shared/unit/api_error_inspector.rb +0 -192
- data/spec/support/shared/unit/platform_introspector.rb +0 -162
@@ -1,43 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Author:: John Hampton (<john@cleanoffer.com>)
|
3
|
-
# Copyright:: Copyright (c) 2009 CleanOffer, Inc.
|
4
|
-
# License:: Apache License, Version 2.0
|
5
|
-
#
|
6
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
# you may not use this file except in compliance with the License.
|
8
|
-
# You may obtain a copy of the License at
|
9
|
-
#
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
-
# See the License for the specific language governing permissions and
|
16
|
-
# limitations under the License.
|
17
|
-
#
|
18
|
-
|
19
|
-
class Chef
|
20
|
-
class Resource
|
21
|
-
class OneTwoThreeFour < Chef::Resource
|
22
|
-
attr_reader :i_can_count
|
23
|
-
|
24
|
-
def initialize(name, run_context)
|
25
|
-
@resource_name = :one_two_three_four
|
26
|
-
super
|
27
|
-
end
|
28
|
-
|
29
|
-
def i_can_count(tf)
|
30
|
-
@i_can_count = tf
|
31
|
-
end
|
32
|
-
|
33
|
-
def something(arg=nil)
|
34
|
-
set_if_args(@something, arg) do
|
35
|
-
case arg
|
36
|
-
when true, false
|
37
|
-
@something = arg
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
@@ -1,96 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Author:: Seth Chisamore (<schisamo@opscode.com>)
|
3
|
-
# Copyright:: Copyright (c) 2011 Opscode, Inc.
|
4
|
-
# License:: Apache License, Version 2.0
|
5
|
-
#
|
6
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
# you may not use this file except in compliance with the License.
|
8
|
-
# You may obtain a copy of the License at
|
9
|
-
#
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
-
# See the License for the specific language governing permissions and
|
16
|
-
# limitations under the License.
|
17
|
-
#
|
18
|
-
|
19
|
-
module Matchers
|
20
|
-
module LeakBase
|
21
|
-
include RSpec::Matchers
|
22
|
-
|
23
|
-
def initialize(opts={}, &block)
|
24
|
-
@warmup = opts[:warmup] || 5
|
25
|
-
@iterations = opts[:iterations] || 100
|
26
|
-
@variance = opts[:variance] || 1000
|
27
|
-
end
|
28
|
-
|
29
|
-
def failure_message_for_should
|
30
|
-
"expected final measure [#{@final_measure}] to be greater than or within +/- #{@variance} delta of initial measure [#{@initial_measure}]"
|
31
|
-
end
|
32
|
-
|
33
|
-
def failure_message_for_should_not
|
34
|
-
"expected final measure [#{@final_measure}] to be less than or within +/- #{@variance} delta of initial measure [#{@initial_measure}]"
|
35
|
-
end
|
36
|
-
|
37
|
-
private
|
38
|
-
def match(measure, given_proc)
|
39
|
-
profiler.start
|
40
|
-
|
41
|
-
@initial_measure = 0
|
42
|
-
@final_measure = 0
|
43
|
-
|
44
|
-
@warmup.times do
|
45
|
-
given_proc.call
|
46
|
-
end
|
47
|
-
|
48
|
-
@initial_measure = profiler.send(measure)
|
49
|
-
|
50
|
-
@iterations.times do
|
51
|
-
given_proc.call
|
52
|
-
end
|
53
|
-
|
54
|
-
profiler.stop
|
55
|
-
|
56
|
-
@final_measure = profiler.send(measure)
|
57
|
-
@final_measure > (@initial_measure + @variance)
|
58
|
-
end
|
59
|
-
|
60
|
-
def profiler
|
61
|
-
@profiler ||= begin
|
62
|
-
if Chef::Platform.windows?
|
63
|
-
require File.join(File.dirname(__FILE__), '..', 'prof', 'win32')
|
64
|
-
RSpec::Prof::Win32::Profiler.new
|
65
|
-
else
|
66
|
-
require File.join(File.dirname(__FILE__), '..', 'prof', 'gc')
|
67
|
-
RSpec::Prof::GC::Profiler.new
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
end
|
73
|
-
|
74
|
-
class LeakMemory
|
75
|
-
include LeakBase
|
76
|
-
|
77
|
-
def matches?(given_proc)
|
78
|
-
match(:working_set_size, given_proc)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
class LeakHandles
|
83
|
-
include LeakBase
|
84
|
-
|
85
|
-
def matches?(given_proc)
|
86
|
-
match(:handle_count, given_proc)
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
def leak_memory(opts, &block)
|
91
|
-
Matchers::LeakMemory.new(opts, &block)
|
92
|
-
end
|
93
|
-
def leak_handles(opts, &block)
|
94
|
-
Matchers::LeakHandles.new(opts, &block)
|
95
|
-
end
|
96
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
# Allows easy mocking of global and class constants
|
2
|
-
|
3
|
-
# Inspired by:
|
4
|
-
# http://missingbit.blogspot.com/2011/07/stubbing-constants-in-rspec_20.html
|
5
|
-
# http://digitaldumptruck.jotabout.com/?p=551
|
6
|
-
|
7
|
-
def mock_constants(constants, &block)
|
8
|
-
saved_constants = {}
|
9
|
-
constants.each do |constant, val|
|
10
|
-
source_object, const_name = parse_constant(constant)
|
11
|
-
saved_constants[constant] = source_object.const_get(const_name)
|
12
|
-
with_warnings(nil) {source_object.const_set(const_name, val) }
|
13
|
-
end
|
14
|
-
|
15
|
-
begin
|
16
|
-
block.call
|
17
|
-
ensure
|
18
|
-
constants.each do |constant, val|
|
19
|
-
source_object, const_name = parse_constant(constant)
|
20
|
-
with_warnings(nil) { source_object.const_set(const_name, saved_constants[constant]) }
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def parse_constant(constant)
|
26
|
-
source, _, constant_name = constant.to_s.rpartition('::')
|
27
|
-
[constantize(source), constant_name]
|
28
|
-
end
|
29
|
-
|
30
|
-
# Taken from ActiveSupport
|
31
|
-
|
32
|
-
# File activesupport/lib/active_support/core_ext/kernel/reporting.rb, line 3
|
33
|
-
#
|
34
|
-
# Sets $VERBOSE for the duration of the block and back to its original value afterwards.
|
35
|
-
def with_warnings(flag)
|
36
|
-
old_verbose, $VERBOSE = $VERBOSE, flag
|
37
|
-
yield
|
38
|
-
ensure
|
39
|
-
$VERBOSE = old_verbose
|
40
|
-
end
|
41
|
-
|
42
|
-
# File activesupport/lib/active_support/inflector/methods.rb, line 209
|
43
|
-
def constantize(camel_cased_word)
|
44
|
-
names = camel_cased_word.split('::')
|
45
|
-
names.shift if names.empty? || names.first.empty?
|
46
|
-
|
47
|
-
constant = Object
|
48
|
-
names.each do |name|
|
49
|
-
constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
|
50
|
-
end
|
51
|
-
constant
|
52
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
# makes Chef think it's running on a certain platform..useful for unit testing
|
2
|
-
# platform-specific functionality.
|
3
|
-
#
|
4
|
-
# If a block is given yields to the block with +RUBY_PLATFORM+ set to
|
5
|
-
# 'i386-mingw32' (windows) or 'x86_64-darwin11.2.0' (unix). Usueful for
|
6
|
-
# testing code that mixes in platform specific modules like +Chef::Mixin::Securable+
|
7
|
-
# or +Chef::FileAccessControl+
|
8
|
-
def platform_mock(platform = :unix, &block)
|
9
|
-
Chef::Platform.stub!(:windows?).and_return(platform == :windows ? true : false)
|
10
|
-
ENV['SYSTEMDRIVE'] = (platform == :windows ? 'C:' : nil)
|
11
|
-
if block_given?
|
12
|
-
mock_constants({"RUBY_PLATFORM" => (platform == :windows ? 'i386-mingw32' : 'x86_64-darwin11.2.0'),
|
13
|
-
"File::PATH_SEPARATOR" => (platform == :windows ? ";" : ":"),
|
14
|
-
"File::ALT_SEPARATOR" => (platform == :windows ? "\\" : nil) }) do
|
15
|
-
yield
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
def ruby_19?
|
2
|
-
!!(RUBY_VERSION =~ /^1.9/)
|
3
|
-
end
|
4
|
-
|
5
|
-
def ruby_18?
|
6
|
-
!!(RUBY_VERSION =~ /^1.8/)
|
7
|
-
end
|
8
|
-
|
9
|
-
def windows?
|
10
|
-
!!(RUBY_PLATFORM =~ /mswin|mingw|windows/)
|
11
|
-
end
|
12
|
-
|
13
|
-
# def jruby?
|
14
|
-
|
15
|
-
def unix?
|
16
|
-
!windows?
|
17
|
-
end
|
18
|
-
|
19
|
-
def os_x?
|
20
|
-
!!(RUBY_PLATFORM =~ /darwin/)
|
21
|
-
end
|
22
|
-
|
23
|
-
def solaris?
|
24
|
-
!!(RUBY_PLATFORM =~ /solaris/)
|
25
|
-
end
|
26
|
-
|
27
|
-
def freebsd?
|
28
|
-
!!(RUBY_PLATFORM =~ /freebsd/)
|
29
|
-
end
|
30
|
-
|
31
|
-
DEV_NULL = windows? ? 'NUL' : '/dev/null'
|
@@ -1,54 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Author:: Seth Chisamore (<schisamo@opscode.com>)
|
3
|
-
# Copyright:: Copyright (c) 2011 Opscode, Inc.
|
4
|
-
# License:: Apache License, Version 2.0
|
5
|
-
#
|
6
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
# you may not use this file except in compliance with the License.
|
8
|
-
# You may obtain a copy of the License at
|
9
|
-
#
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
-
# See the License for the specific language governing permissions and
|
16
|
-
# limitations under the License.
|
17
|
-
#
|
18
|
-
|
19
|
-
module RSpec
|
20
|
-
module Prof
|
21
|
-
module GC
|
22
|
-
class Profiler
|
23
|
-
|
24
|
-
# GC 1 invokes.
|
25
|
-
# Index Invoke Time(sec) Use Size(byte) Total Size(byte) Total Object GC time(ms)
|
26
|
-
# 1 0.012 159240 212940 10647 0.00000000000001530000
|
27
|
-
LINE_PATTERN = /^\s+([\d\.]*)\s+([\d\.]*)\s+([\d\.]*)\s+([\d\.]*)\s+([\d\.]*)\s+([\d\.]*)$/
|
28
|
-
|
29
|
-
def start
|
30
|
-
::GC::Profiler.enable unless ::GC::Profiler.enabled?
|
31
|
-
end
|
32
|
-
|
33
|
-
def stop
|
34
|
-
::GC::Profiler.disable
|
35
|
-
end
|
36
|
-
|
37
|
-
def working_set_size
|
38
|
-
begin
|
39
|
-
::GC.start
|
40
|
-
::GC::Profiler.result.scan(LINE_PATTERN)[-1][2].to_i if ::GC::Profiler.enabled?
|
41
|
-
ensure
|
42
|
-
::GC::Profiler.clear
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def handle_count
|
47
|
-
0
|
48
|
-
end
|
49
|
-
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
@@ -1,46 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Author:: Seth Chisamore (<schisamo@opscode.com>)
|
3
|
-
# Copyright:: Copyright (c) 2011 Opscode, Inc.
|
4
|
-
# License:: Apache License, Version 2.0
|
5
|
-
#
|
6
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
# you may not use this file except in compliance with the License.
|
8
|
-
# You may obtain a copy of the License at
|
9
|
-
#
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
-
# See the License for the specific language governing permissions and
|
16
|
-
# limitations under the License.
|
17
|
-
#
|
18
|
-
|
19
|
-
require 'chef/win32/process'
|
20
|
-
|
21
|
-
module RSpec
|
22
|
-
module Prof
|
23
|
-
module Win32
|
24
|
-
class Profiler
|
25
|
-
|
26
|
-
def start
|
27
|
-
GC.start
|
28
|
-
end
|
29
|
-
|
30
|
-
def stop
|
31
|
-
GC.start
|
32
|
-
end
|
33
|
-
|
34
|
-
def working_set_size
|
35
|
-
Chef::ReservedNames::Win32::Process.get_current_process.memory_info[:WorkingSetSize]
|
36
|
-
end
|
37
|
-
|
38
|
-
def handle_count
|
39
|
-
Chef::ReservedNames::Win32::Process.get_current_process.handle_count
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
@@ -1,85 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Author:: Seth Chisamore (<schisamo@opscode.com>)
|
3
|
-
# Copyright:: Copyright (c) 2011 Opscode, Inc.
|
4
|
-
# License:: Apache License, Version 2.0
|
5
|
-
#
|
6
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
# you may not use this file except in compliance with the License.
|
8
|
-
# You may obtain a copy of the License at
|
9
|
-
#
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
-
# See the License for the specific language governing permissions and
|
16
|
-
# limitations under the License.
|
17
|
-
#
|
18
|
-
|
19
|
-
shared_examples_for "a directory resource" do
|
20
|
-
context "when the target directory does not exist" do
|
21
|
-
it "creates the directory when the :create action is run" do
|
22
|
-
resource.run_action(:create)
|
23
|
-
File.should exist(path)
|
24
|
-
end
|
25
|
-
|
26
|
-
it "recursively creates required directories if requested" do
|
27
|
-
resource.recursive(true)
|
28
|
-
recursive_path = File.join(path, 'red-headed-stepchild')
|
29
|
-
resource.path(recursive_path)
|
30
|
-
resource.run_action(:create)
|
31
|
-
File.should exist(path)
|
32
|
-
File.should exist(recursive_path)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
context "when the target directory exists" do
|
37
|
-
before(:each) do
|
38
|
-
FileUtils.mkdir(path)
|
39
|
-
end
|
40
|
-
|
41
|
-
it "does not re-create the directory" do
|
42
|
-
resource.run_action(:create)
|
43
|
-
File.should exist(path)
|
44
|
-
end
|
45
|
-
|
46
|
-
it "deletes the directory when the :delete action is run" do
|
47
|
-
resource.run_action(:delete)
|
48
|
-
File.should_not exist(path)
|
49
|
-
end
|
50
|
-
|
51
|
-
it "recursively deletes directories if requested" do
|
52
|
-
FileUtils.mkdir(File.join(path, 'red-headed-stepchild'))
|
53
|
-
resource.recursive(true)
|
54
|
-
resource.run_action(:delete)
|
55
|
-
File.should_not exist(path)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
# Set up the context for security tests
|
60
|
-
def allowed_acl(sid, expected_perms)
|
61
|
-
[
|
62
|
-
ACE.access_allowed(sid, expected_perms[:specific]),
|
63
|
-
ACE.access_allowed(sid, expected_perms[:generic], (Chef::ReservedNames::Win32::API::Security::INHERIT_ONLY_ACE | Chef::ReservedNames::Win32::API::Security::CONTAINER_INHERIT_ACE | Chef::ReservedNames::Win32::API::Security::OBJECT_INHERIT_ACE))
|
64
|
-
]
|
65
|
-
end
|
66
|
-
|
67
|
-
def denied_acl(sid, expected_perms)
|
68
|
-
[
|
69
|
-
ACE.access_denied(sid, expected_perms[:specific]),
|
70
|
-
ACE.access_denied(sid, expected_perms[:generic], (Chef::ReservedNames::Win32::API::Security::INHERIT_ONLY_ACE | Chef::ReservedNames::Win32::API::Security::CONTAINER_INHERIT_ACE | Chef::ReservedNames::Win32::API::Security::OBJECT_INHERIT_ACE))
|
71
|
-
]
|
72
|
-
end
|
73
|
-
|
74
|
-
it_behaves_like "a securable resource"
|
75
|
-
end
|
76
|
-
|
77
|
-
shared_context Chef::Resource::Directory do
|
78
|
-
let(:path) do
|
79
|
-
File.join(Dir.tmpdir, make_tmpname(directory_base, nil))
|
80
|
-
end
|
81
|
-
|
82
|
-
after(:each) do
|
83
|
-
FileUtils.rm_r(path) if File.exists?(path)
|
84
|
-
end
|
85
|
-
end
|
@@ -1,173 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Author:: Seth Chisamore (<schisamo@opscode.com>)
|
3
|
-
# Copyright:: Copyright (c) 2011 Opscode, Inc.
|
4
|
-
# License:: Apache License, Version 2.0
|
5
|
-
#
|
6
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
# you may not use this file except in compliance with the License.
|
8
|
-
# You may obtain a copy of the License at
|
9
|
-
#
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
-
# See the License for the specific language governing permissions and
|
16
|
-
# limitations under the License.
|
17
|
-
#
|
18
|
-
|
19
|
-
shared_examples_for "a file with the wrong content" do
|
20
|
-
it "overwrites the file with the updated content when the :create action is run" do
|
21
|
-
Chef::Config[:file_backup_path] = CHEF_SPEC_BACKUP_PATH
|
22
|
-
sleep 1
|
23
|
-
resource.run_action(:create)
|
24
|
-
File.stat(path).mtime.should > @expected_mtime
|
25
|
-
sha256_checksum(path).should_not == @expected_checksum
|
26
|
-
end
|
27
|
-
|
28
|
-
it "doesn't overwrite the file when the :create_if_missing action is run" do
|
29
|
-
sleep 1
|
30
|
-
resource.run_action(:create_if_missing)
|
31
|
-
File.stat(path).mtime.should == @expected_mtime
|
32
|
-
sha256_checksum(path).should == @expected_checksum
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should backup the existing file" do
|
36
|
-
Chef::Config[:file_backup_path] = CHEF_SPEC_BACKUP_PATH
|
37
|
-
resource.run_action(:create)
|
38
|
-
Dir.glob(backup_glob).size.should equal(1)
|
39
|
-
end
|
40
|
-
|
41
|
-
it "should not attempt to backup the existing file if :backup == 0" do
|
42
|
-
Chef::Config[:file_backup_path] = CHEF_SPEC_BACKUP_PATH
|
43
|
-
resource.backup(0)
|
44
|
-
resource.run_action(:create)
|
45
|
-
Dir.glob(backup_glob).size.should equal(0)
|
46
|
-
end
|
47
|
-
|
48
|
-
it "deletes the file when the :delete action is run" do
|
49
|
-
resource.run_action(:delete)
|
50
|
-
File.should_not exist(path)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
shared_examples_for "a file with the correct content" do
|
55
|
-
it "does not overwrite the original when the :create action is run" do
|
56
|
-
resource.run_action(:create)
|
57
|
-
sha256_checksum(path).should == @expected_checksum
|
58
|
-
end
|
59
|
-
|
60
|
-
it "does not update the mtime/atime of the file when the :create action is run" do
|
61
|
-
sleep 1
|
62
|
-
File.stat(path).mtime.should == @expected_mtime
|
63
|
-
File.stat(path).atime.should be_within(2).of(@expected_atime)
|
64
|
-
end
|
65
|
-
|
66
|
-
it "doesn't overwrite the file when the :create_if_missing action is run" do
|
67
|
-
resource.run_action(:create_if_missing)
|
68
|
-
sha256_checksum(path).should == @expected_checksum
|
69
|
-
end
|
70
|
-
|
71
|
-
it "deletes the file when the :delete action is run" do
|
72
|
-
resource.run_action(:delete)
|
73
|
-
File.should_not exist(path)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
shared_examples_for "a file resource" do
|
78
|
-
# note the stripping of the drive letter from the tmpdir on windows
|
79
|
-
let(:backup_glob) { File.join(CHEF_SPEC_BACKUP_PATH, Dir.tmpdir.sub(/^([A-Za-z]:)/, ""), "#{file_base}*") }
|
80
|
-
|
81
|
-
context "when the target file does not exist" do
|
82
|
-
it "creates the file when the :create action is run" do
|
83
|
-
resource.run_action(:create)
|
84
|
-
File.should exist(path)
|
85
|
-
end
|
86
|
-
|
87
|
-
it "creates the file with the correct content when the :create action is run" do
|
88
|
-
resource.run_action(:create)
|
89
|
-
IO.read(path).should == expected_content
|
90
|
-
end
|
91
|
-
|
92
|
-
it "creates the file with the correct content when the :create_if_missing action is run" do
|
93
|
-
resource.run_action(:create_if_missing)
|
94
|
-
IO.read(path).should == expected_content
|
95
|
-
end
|
96
|
-
|
97
|
-
it "deletes the file when the :delete action is run" do
|
98
|
-
resource.run_action(:delete)
|
99
|
-
File.should_not exist(path)
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
# Set up the context for security tests
|
104
|
-
def allowed_acl(sid, expected_perms)
|
105
|
-
[ ACE.access_allowed(sid, expected_perms[:specific]) ]
|
106
|
-
end
|
107
|
-
|
108
|
-
def denied_acl(sid, expected_perms)
|
109
|
-
[ ACE.access_denied(sid, expected_perms[:specific]) ]
|
110
|
-
end
|
111
|
-
|
112
|
-
|
113
|
-
context "when the target file has the wrong content" do
|
114
|
-
before(:each) do
|
115
|
-
File.open(path, "w") { |f| f.print "This is so wrong!!!" }
|
116
|
-
@expected_mtime = File.stat(path).mtime
|
117
|
-
@expected_checksum = sha256_checksum(path)
|
118
|
-
end
|
119
|
-
|
120
|
-
describe "and the target file has the correct permissions" do
|
121
|
-
include_context "setup correct permissions"
|
122
|
-
|
123
|
-
it_behaves_like "a file with the wrong content"
|
124
|
-
|
125
|
-
it_behaves_like "a securable resource"
|
126
|
-
end
|
127
|
-
|
128
|
-
context "and the target file has incorrect permissions" do
|
129
|
-
include_context "setup broken permissions"
|
130
|
-
|
131
|
-
it_behaves_like "a file with the wrong content"
|
132
|
-
|
133
|
-
it_behaves_like "a securable resource"
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
context "when the target file has the correct content" do
|
138
|
-
before(:each) do
|
139
|
-
File.open(path, "w") { |f| f.print expected_content }
|
140
|
-
@expected_mtime = File.stat(path).mtime
|
141
|
-
@expected_atime = File.stat(path).atime
|
142
|
-
@expected_checksum = sha256_checksum(path)
|
143
|
-
end
|
144
|
-
|
145
|
-
describe "and the target file has the correct permissions" do
|
146
|
-
include_context "setup correct permissions"
|
147
|
-
|
148
|
-
it_behaves_like "a file with the correct content"
|
149
|
-
|
150
|
-
it_behaves_like "a securable resource"
|
151
|
-
end
|
152
|
-
|
153
|
-
context "and the target file has incorrect permissions" do
|
154
|
-
include_context "setup broken permissions"
|
155
|
-
|
156
|
-
it_behaves_like "a file with the correct content"
|
157
|
-
|
158
|
-
it_behaves_like "a securable resource"
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
end
|
163
|
-
|
164
|
-
shared_context Chef::Resource::File do
|
165
|
-
let(:path) do
|
166
|
-
File.join(Dir.tmpdir, make_tmpname(file_base, nil))
|
167
|
-
end
|
168
|
-
|
169
|
-
after(:each) do
|
170
|
-
FileUtils.rm_r(path) if File.exists?(path)
|
171
|
-
FileUtils.rm_r(CHEF_SPEC_BACKUP_PATH) if File.exists?(CHEF_SPEC_BACKUP_PATH)
|
172
|
-
end
|
173
|
-
end
|