chef-rewind 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +6 -0
  3. data/.kitchen.yml +26 -0
  4. data/.travis.yml +11 -0
  5. data/Berksfile +4 -0
  6. data/Gemfile +5 -34
  7. data/README.md +6 -2
  8. data/Rakefile +10 -0
  9. data/chef-rewind.gemspec +1 -1
  10. data/gemfiles/chef-11.gemfile +7 -0
  11. data/gemfiles/chef-12.gemfile +7 -0
  12. data/lib/chef/rewind.rb +45 -15
  13. data/spec/data/cookbooks/rewind/Berksfile +3 -0
  14. data/spec/data/cookbooks/rewind/README.md +1 -0
  15. data/spec/data/cookbooks/rewind/files/default/test/default_test.rb +21 -0
  16. data/spec/data/cookbooks/rewind/metadata.rb +7 -0
  17. data/spec/data/cookbooks/rewind/recipes/base.rb +11 -0
  18. data/spec/data/cookbooks/rewind/recipes/default.rb +12 -0
  19. data/spec/rewind_recipe_spec.rb +10 -11
  20. data/spec/rewind_resource_spec.rb +2 -2
  21. data/spec/spec_helper.rb +0 -44
  22. data/spec/unwind_recipe_spec.rb +34 -5
  23. metadata +23 -89
  24. data/spec/data/cookbooks/angrybash/recipes/default.rb +0 -8
  25. data/spec/data/cookbooks/apache2/files/default/apache2_module_conf_generate.pl +0 -2
  26. data/spec/data/cookbooks/apache2/recipes/default.rb +0 -3
  27. data/spec/data/cookbooks/borken/recipes/default.rb +0 -2
  28. data/spec/data/cookbooks/borken/templates/default/borken.erb +0 -2
  29. data/spec/data/cookbooks/chefignore +0 -6
  30. data/spec/data/cookbooks/java/files/default/java.response +0 -2
  31. data/spec/data/cookbooks/openldap/attributes/default.rb +0 -16
  32. data/spec/data/cookbooks/openldap/attributes/smokey.rb +0 -1
  33. data/spec/data/cookbooks/openldap/definitions/client.rb +0 -5
  34. data/spec/data/cookbooks/openldap/definitions/server.rb +0 -5
  35. data/spec/data/cookbooks/openldap/files/default/.dotfile +0 -1
  36. data/spec/data/cookbooks/openldap/files/default/.ssh/id_rsa +0 -1
  37. data/spec/data/cookbooks/openldap/files/default/remotedir/.a_dotdir/.a_dotfile_in_a_dotdir +0 -1
  38. data/spec/data/cookbooks/openldap/files/default/remotedir/remote_dir_file1.txt +0 -3
  39. data/spec/data/cookbooks/openldap/files/default/remotedir/remote_dir_file2.txt +0 -3
  40. data/spec/data/cookbooks/openldap/files/default/remotedir/remotesubdir/.a_dotfile +0 -1
  41. data/spec/data/cookbooks/openldap/files/default/remotedir/remotesubdir/remote_subdir_file1.txt +0 -3
  42. data/spec/data/cookbooks/openldap/files/default/remotedir/remotesubdir/remote_subdir_file2.txt +0 -3
  43. data/spec/data/cookbooks/openldap/files/default/remotedir/subdir_with_no_file_just_a_subsubdir/the_subsubdir/some_file.txt +0 -3
  44. data/spec/data/cookbooks/openldap/recipes/default.rb +0 -3
  45. data/spec/data/cookbooks/openldap/recipes/gigantor.rb +0 -3
  46. data/spec/data/cookbooks/openldap/recipes/one.rb +0 -15
  47. data/spec/data/cookbooks/openldap/templates/default/openldap_stuff.conf.erb +0 -1
  48. data/spec/data/cookbooks/openldap/templates/default/openldap_variable_stuff.conf.erb +0 -1
  49. data/spec/data/cookbooks/openldap/templates/default/test.erb +0 -1
  50. data/spec/support/lib/chef/provider/easy.rb +0 -35
  51. data/spec/support/lib/chef/provider/snakeoil.rb +0 -40
  52. data/spec/support/lib/chef/resource/one_two_three_four.rb +0 -43
  53. data/spec/support/matchers/leak.rb +0 -96
  54. data/spec/support/mock/constant.rb +0 -52
  55. data/spec/support/mock/platform.rb +0 -18
  56. data/spec/support/platform_helpers.rb +0 -31
  57. data/spec/support/platforms/prof/gc.rb +0 -54
  58. data/spec/support/platforms/prof/win32.rb +0 -46
  59. data/spec/support/shared/functional/directory_resource.rb +0 -85
  60. data/spec/support/shared/functional/file_resource.rb +0 -173
  61. data/spec/support/shared/functional/knife.rb +0 -37
  62. data/spec/support/shared/functional/securable_resource.rb +0 -394
  63. data/spec/support/shared/unit/api_error_inspector.rb +0 -192
  64. data/spec/support/shared/unit/platform_introspector.rb +0 -162
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cefbbaa69a7831ac60f9c606e878059e7f2608dc
4
- data.tar.gz: 2a4f1030ac29fac1a99648ba1adb0b6cb29ec53e
3
+ metadata.gz: 998da8b82028835bba55051d2942811b230025c2
4
+ data.tar.gz: 13133b9eccad6d6d5e66c7439e7f8ff47f82545c
5
5
  SHA512:
6
- metadata.gz: c5054f2756825cb8eb289b35d93b1759699dfb801797eba165de52ce56e6955ce2394d26b9c5094c00e24090af6f15698d3c15cb56242ac65a40a6f022650cf7
7
- data.tar.gz: 4e60f6920312e2e226fbfd52c8860b06504cf82155f207ad762bdbb2cca8ba70db5432f6e1e698fb964707edb287b60e751ca51f2d77cd22adc5fd1153793097
6
+ metadata.gz: 70aeff096b089815c45ffea3914ca4971ff503e5b0e6847a925e814abc9b406e45eb0b847c44d59f694e390cb38cc052ab2dbcd79c0d263991dd6530cb53521b
7
+ data.tar.gz: e722f94a7dc57f7a7e21bc740649a9c51ca7c7d01a56beddf32a09be3cd585865139d9b9bc784ead0c40739d72bdce322be8fc8f19e0e2d06141fcd682853d20
data/.gitignore CHANGED
@@ -2,8 +2,11 @@
2
2
  *.rbc
3
3
  .bundle
4
4
  .config
5
+ .rake_tasks~
5
6
  .yardoc
7
+ Berksfile.lock
6
8
  Gemfile.lock
9
+ gemfiles/*.lock
7
10
  InstalledFiles
8
11
  _yardoc
9
12
  coverage
@@ -12,6 +15,9 @@ lib/bundler/man
12
15
  pkg
13
16
  rdoc
14
17
  spec/reports
18
+ tags
15
19
  test/tmp
16
20
  test/version_tmp
17
21
  tmp
22
+ .kitchen/
23
+ .kitchen.local.yml
@@ -0,0 +1,26 @@
1
+ ---
2
+ driver:
3
+ name: vagrant
4
+ synced_folders:
5
+ - [ 'pkg', '/opt/pkg']
6
+
7
+ provisioner:
8
+ name: chef_zero
9
+
10
+ platforms:
11
+ <% %w{11.16.4 12.0.1}.each do |chef_ver| %>
12
+ - name: ubuntu-14.04-<%= chef_ver %>
13
+ driver_config:
14
+ box: opscode-ubuntu-14.04
15
+ box_url: http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_ubuntu-14.04_chef-provisionerless.box
16
+ require_chef_omnibus: <%= chef_ver %>
17
+ <% end %>
18
+
19
+ suites:
20
+ - name: default
21
+ run_list:
22
+ - "recipe[rewind]"
23
+ - "recipe[minitest-handler]"
24
+ attributes:
25
+ rewind:
26
+ ver: 0.0.9
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.5
4
+ - 2.0.0
5
+ script: bundle exec rake spec
6
+ bundler_args: --without kitchen
7
+ sudo: false
8
+ gemfile:
9
+ - Gemfile
10
+ - gemfiles/chef-11.gemfile
11
+ - gemfiles/chef-12.gemfile
@@ -0,0 +1,4 @@
1
+ source "https://supermarket.getchef.com"
2
+
3
+ cookbook "rewind", :path => "spec/data/cookbooks/rewind"
4
+ cookbook 'minitest-handler'
data/Gemfile CHANGED
@@ -2,43 +2,14 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
- gem "activesupport", :group => :compat_testing, :platform => "ruby"
6
5
  gem "ronn"
7
6
  gem "rspec"
8
7
  gem "chef"
9
8
  gem "pry"
9
+ gem "rake"
10
10
 
11
- group(:development, :test) do
12
- gem 'rack'
13
- gem 'thin'
14
-
15
- # Eventmachine 1.0.0 is causing functional test failures on Solaris
16
- # 9 SPARC. Pinning em to 0.12.10 solves this issue until we can
17
- # replace thin with webrat or some other alternative.
18
- gem 'eventmachine', '0.12.10', :platforms => :ruby
19
-
20
- gem 'ruby-shadow', :platforms => :ruby unless RUBY_PLATFORM.downcase.match(/(darwin|freebsd)/)
21
- # gem 'awesome_print'
22
- # gem 'pry'
23
- end
24
-
25
- platforms :mswin, :mingw do
26
- gem "ffi", "1.0.9"
27
- gem "rdp-ruby-wmi", "0.3.1"
28
- gem "windows-api", "0.4.0"
29
- gem "windows-pr", "1.2.1"
30
- gem "win32-api", "1.4.8"
31
- gem "win32-dir", "0.3.7"
32
- gem "win32-event", "0.5.2"
33
- gem "win32-mutex", "0.3.1"
34
- gem "win32-process", "0.6.5"
35
- gem "win32-service", "0.7.2"
11
+ group :kitchen do
12
+ gem 'test-kitchen'
13
+ gem 'kitchen-vagrant'
14
+ gem 'berkshelf'
36
15
  end
37
-
38
- platforms :mingw_18 do
39
- gem "win32-open3", "0.3.2"
40
- end
41
-
42
- # If you want to load debugging tools into the bundle exec sandbox,
43
- # add these additional dependencies into chef/Gemfile.local
44
- eval(IO.read(__FILE__ + '.local'), binding) if File.exists?(__FILE__ + '.local')
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Chef::Rewind
2
2
 
3
+ [![Build Status](https://travis-ci.org/thommay/chef-rewind.svg?branch=master)](https://travis-ci.org/thommay/chef-rewind)
4
+
3
5
  This adds a simple function to the Chef library scope to
4
6
  rewind or unwind an existing resource. If the given resource does not exist,
5
7
  a `Chef::Exceptions::ResourceNotFound` exception will be raised.
@@ -151,5 +153,7 @@ the source file and not in the my-postgresql cookbook.
151
153
  1. Fork it
152
154
  2. Create your feature branch (`git checkout -b my-new-feature`)
153
155
  3. Commit your changes (`git commit -am 'Added some feature'`)
154
- 4. Push to the branch (`git push origin my-new-feature`)
155
- 5. Create new Pull Request
156
+ 4. Run the unit tests (`bundle exec rake spec`)
157
+ 5. Run test kitchen (`bundle exec kitchen test`)
158
+ 6. Push to the branch (`git push origin my-new-feature`)
159
+ 7. Create new Pull Request
data/Rakefile CHANGED
@@ -1,2 +1,12 @@
1
1
  #!/usr/bin/env rake
2
+ require 'rspec/core/rake_task'
2
3
  require "bundler/gem_tasks"
4
+
5
+ RSpec::Core::RakeTask.new
6
+
7
+ begin
8
+ require 'kitchen/rake_tasks'
9
+ Kitchen::RakeTasks.new
10
+ rescue LoadError
11
+ puts ">>>>> Kitchen gem not loaded, omitting tasks" unless ENV['CI']
12
+ end
@@ -12,5 +12,5 @@ Gem::Specification.new do |gem|
12
12
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
13
13
  gem.name = "chef-rewind"
14
14
  gem.require_paths = ["lib"]
15
- gem.version = "0.0.8"
15
+ gem.version = "0.0.9"
16
16
  end
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem "ronn"
4
+ gem "rspec"
5
+ gem "chef", '~> 11.0'
6
+ gem "pry"
7
+ gem "rake"
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem "ronn"
4
+ gem "rspec"
5
+ gem "chef", '~> 12.0'
6
+ gem "pry"
7
+ gem "rake"
@@ -50,16 +50,16 @@ class Chef
50
50
  class Resource
51
51
  def cookbook_name(arg=nil)
52
52
  set_or_return(
53
- :cookbook_name,
54
- arg,
55
- :kind_of => String)
53
+ :cookbook_name,
54
+ arg,
55
+ :kind_of => String)
56
56
  end
57
57
 
58
58
  def recipe_name(arg=nil)
59
59
  set_or_return(
60
- :recipe_name,
61
- arg,
62
- :kind_of => String)
60
+ :recipe_name,
61
+ arg,
62
+ :kind_of => String)
63
63
  end
64
64
  end
65
65
  end
@@ -67,18 +67,48 @@ end
67
67
 
68
68
  class Chef
69
69
  class ResourceCollection
70
- def delete_resource(resource_id)
71
- lookup resource_id
72
-
73
- # assumes `resource_id` is the same as `Chef::Resource#to_s`
74
- @resources.delete_if {|r| r.to_s == resource_id }
75
- resource_index_value = @resources_by_name[resource_id]
76
- @resources_by_name.each do |k, v|
77
- @resources_by_name[k] = v - 1 if v > resource_index_value
70
+ if Gem::Version.new(Chef::VERSION) > Gem::Version.new('12')
71
+ class ResourceSet
72
+ def delete(key)
73
+ @resources_by_key.delete(key)
74
+ end
78
75
  end
79
76
 
80
- @resources_by_name.delete resource_id
77
+ class ResourceList
78
+ def delete(key)
79
+ @resources.delete_if { |r| r.to_s == key }
80
+ end
81
+ end
82
+
83
+ def delete_resource(resource_id)
84
+ lookup resource_id
85
+
86
+ @resource_set.delete(resource_id)
87
+ @resource_list.delete(resource_id)
88
+ end
89
+ else
90
+ def delete_resource(resource_id)
91
+ lookup resource_id
92
+
93
+ indexes_to_delete = @resources.each_index.select do |resource_index|
94
+ # assumes `resource_id` is the same as `Chef::Resource#to_s`
95
+ @resources[resource_index].to_s == resource_id
96
+ end
81
97
 
98
+ # Delete indexes backwards to avoid problems with changing the array
99
+ indexes_to_delete.sort.reverse.each { |index| delete_index index }
100
+
101
+ @resources_by_name.delete resource_id
102
+ end
103
+
104
+ private
105
+
106
+ def delete_index(resource_index)
107
+ @resources.delete_at resource_index
108
+ @resources_by_name.each do |k, v|
109
+ @resources_by_name[k] = v - 1 if v > resource_index
110
+ end
111
+ end
82
112
  end
83
113
  end
84
114
  end
@@ -0,0 +1,3 @@
1
+ source "https://supermarket.getchef.com"
2
+
3
+ metadata
@@ -0,0 +1 @@
1
+ A sample cookbook
@@ -0,0 +1,21 @@
1
+ require 'minitest/spec'
2
+
3
+ describe_recipe 'rewind::default' do
4
+ describe 'the first file' do
5
+ it 'should get created' do
6
+ file('/tmp/first_file').must_exist
7
+ end
8
+
9
+ it 'should be rewound' do
10
+ file('/tmp/first_file').must_include 'a rewound file'
11
+ end
12
+ end
13
+
14
+ it 'should create the second file' do
15
+ file('/tmp/second_file').must_exist
16
+ end
17
+
18
+ it 'should not create the third file' do
19
+ file('/tmp/third_file').wont_exist
20
+ end
21
+ end
@@ -0,0 +1,7 @@
1
+ name 'rewind'
2
+ maintainer ''
3
+ maintainer_email ''
4
+ license ''
5
+ description 'Installs/Configures rewind'
6
+ long_description 'Installs/Configures rewind'
7
+ version '0.1.0'
@@ -0,0 +1,11 @@
1
+ file "/tmp/first_file" do
2
+ content 'a pristine file'
3
+ end
4
+
5
+ file '/tmp/second_file' do
6
+ content 'a file that should exist'
7
+ end
8
+
9
+ file '/tmp/third_file' do
10
+ content 'i should not exist'
11
+ end
@@ -0,0 +1,12 @@
1
+ chef_gem 'chef-rewind' do
2
+ source "/opt/pkg/chef-rewind-#{node['rewind']['ver']}.gem"
3
+ end
4
+
5
+ require 'chef/rewind'
6
+ include_recipe 'rewind::base'
7
+
8
+ rewind "file[/tmp/first_file]" do
9
+ content "a rewound file"
10
+ end
11
+
12
+ unwind 'file[/tmp/third_file]'
@@ -1,9 +1,8 @@
1
-
2
1
  require 'spec_helper'
3
2
  require 'chef/rewind'
4
3
 
5
4
  describe Chef::Recipe do
6
-
5
+
7
6
  before(:each) do
8
7
  @cookbook_repo = File.expand_path(File.join(File.dirname(__FILE__), "..", "data", "cookbooks"))
9
8
  cl = Chef::CookbookLoader.new(@cookbook_repo)
@@ -18,7 +17,7 @@ describe Chef::Recipe do
18
17
  # Shell/ext.rb is on the run path, and it defines
19
18
  # Chef::Recipe#resources to call pp, which we don't want when
20
19
  # we're running tests.
21
- @recipe.stub!(:pp)
20
+ allow(@recipe).to receive(:pp)
22
21
  end
23
22
 
24
23
 
@@ -28,34 +27,34 @@ describe Chef::Recipe do
28
27
  @recipe.zen_master "foobar" do
29
28
  peace false
30
29
  end
31
-
30
+
32
31
  @recipe.rewind "zen_master[foobar]" do
33
32
  peace true
34
33
  end
35
34
  resources = @run_context.resource_collection.all_resources
36
- resources.length.should == 1
35
+ expect(resources.length).to eq 1
37
36
  end
38
37
 
39
38
  it "change the value of an existing resource" do
40
39
  @recipe.zen_master "foobar" do
41
40
  peace false
42
41
  end
43
-
42
+
44
43
  @recipe.rewind "zen_master[foobar]" do
45
44
  peace true
46
45
  end
47
-
46
+
48
47
  zen_master = @run_context.resource_collection.find("zen_master[foobar]")
49
48
  peace_status = zen_master.instance_exec { @peace }
50
- peace_status.should == true
49
+ expect(peace_status).to be true
51
50
  end
52
-
51
+
53
52
  it "throw an error when rewinding a nonexistent resource" do
54
- lambda do
53
+ expect {
55
54
  @recipe.rewind "zen_master[foobar]" do
56
55
  peace true
57
56
  end
58
- end.should raise_error(Chef::Exceptions::ResourceNotFound)
57
+ }.to raise_error(Chef::Exceptions::ResourceNotFound)
59
58
  end
60
59
  end
61
60
 
@@ -18,7 +18,7 @@ describe Chef::Resource do
18
18
  describe "cookbook_name" do
19
19
  it "cookbook_name sets @cookbook_name properly" do
20
20
  @resource.cookbook_name "foobar"
21
- @resource.cookbook_name.should == "foobar"
21
+ expect(@resource.cookbook_name).to eq "foobar"
22
22
  end
23
23
 
24
24
  end
@@ -26,7 +26,7 @@ describe Chef::Resource do
26
26
  describe "recipe_name" do
27
27
  it "recipe_name sets @recipe_name properly" do
28
28
  @resource.recipe_name "foobar"
29
- @resource.recipe_name.should == "foobar"
29
+ expect(@resource.recipe_name).to eq "foobar"
30
30
  end
31
31
 
32
32
  end
@@ -15,19 +15,9 @@
15
15
  # See the License for the specific language governing permissions and
16
16
  # limitations under the License.
17
17
 
18
- # If you need to add anything in here, don't.
19
- # Add it to one of the files in spec/support
20
-
21
- # Abuse ruby's constant lookup to avoid undefined constant errors
22
- module Shef
23
- JUST_TESTING_MOVE_ALONG = true unless defined? JUST_TESTING_MOVE_ALONG
24
- IRB = nil unless defined? IRB
25
- end
26
-
27
18
  # Ruby 1.9 Compat
28
19
  $:.unshift File.expand_path("../..", __FILE__)
29
20
 
30
- require 'rubygems'
31
21
  require 'rspec/mocks'
32
22
 
33
23
  $:.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
@@ -35,25 +25,7 @@ $:.unshift(File.expand_path("../lib", __FILE__))
35
25
  $:.unshift(File.dirname(__FILE__))
36
26
 
37
27
  require 'chef'
38
- require 'chef/knife'
39
- Chef::Knife.load_commands
40
28
  require 'chef/mixins'
41
- require 'chef/application'
42
- require 'chef/applications'
43
-
44
- begin
45
- require 'chef/shef'
46
- rescue LoadError
47
- require 'chef/shef/ext'
48
- end
49
- require 'chef/util/file_edit'
50
-
51
- # If you want to load anything into the testing environment
52
- # without versioning it, add it to spec/support/local_gems.rb
53
- require 'spec/support/local_gems.rb' if File.exists?(File.join(File.dirname(__FILE__), 'support', 'local_gems.rb'))
54
-
55
- # Explicitly require spec helpers that need to load first
56
- require 'spec/support/platform_helpers'
57
29
 
58
30
  # Autoloads support files
59
31
  # Excludes support/platforms by default
@@ -63,19 +35,3 @@ Dir["spec/support/**/*.rb"].
63
35
  map { |f| f.gsub(%r{.rb$}, '') }.
64
36
  each { |f| require f }
65
37
 
66
- RSpec.configure do |config|
67
- config.include(Matchers)
68
- config.filter_run :focus => true
69
- config.filter_run_excluding :external => true
70
-
71
- # Add jruby filters here
72
- config.filter_run_excluding :windows_only => true unless windows?
73
- config.filter_run_excluding :unix_only => true unless unix?
74
- config.filter_run_excluding :ruby_18_only => true unless ruby_18?
75
- config.filter_run_excluding :ruby_19_only => true unless ruby_19?
76
- config.filter_run_excluding :requires_root => true unless ENV['USER'] == 'root'
77
- config.filter_run_excluding :requires_unprivileged_user => true if ENV['USER'] == 'root'
78
-
79
- config.run_all_when_everything_filtered = true
80
- config.treat_symbols_as_metadata_keys_with_true_values = true
81
- end