Skip to content
This repository has been archived by the owner on Jul 14, 2021. It is now read-only.

Commit

Permalink
Integrate rm_policy_group service with undo stack
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsdeleo committed Aug 10, 2015
1 parent 6d428e0 commit 3dc88b7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
4 changes: 0 additions & 4 deletions lib/chef-dk/policyfile/undo_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,6 @@ def for_serialization
}
end

def commit!
raise NotImplementedError, "TODO"
end

private

def reset!
Expand Down
7 changes: 6 additions & 1 deletion lib/chef-dk/policyfile_services/rm_policy_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

require 'chef-dk/service_exceptions'
require 'chef-dk/authenticated_http'
require 'chef-dk/policyfile/undo_stack'
require 'chef-dk/policyfile/undo_record'

module ChefDK
Expand All @@ -35,12 +36,16 @@ class RmPolicyGroup
# @api private
attr_reader :undo_record

# @api private
attr_reader :undo_stack

def initialize(config: nil, ui: nil, policy_group: nil)
@chef_config = config
@ui = ui
@policy_group = policy_group

@undo_record = Policyfile::UndoRecord.new
@undo_stack = Policyfile::UndoStack.new
end

def run
Expand All @@ -59,7 +64,7 @@ def run
http_client.delete("/policy_groups/#{policy_group}")
undo_record.add_policy_group(policy_group)
ui.err("Removed policy group '#{policy_group}'.")
undo_record.commit!
undo_stack.push(undo_record)
rescue => e
raise DeletePolicyGroupError.new("Failed to delete policy group '#{policy_group}'", e)
end
Expand Down
9 changes: 7 additions & 2 deletions spec/unit/policyfile_services/rm_policy_group_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@
rm_policy_group_service.undo_record
end

let(:undo_stack) do
rm_policy_group_service.undo_stack
end


it "configures an HTTP client" do
expect(ChefDK::AuthenticatedHTTP).to receive(:new).with("https://localhost:10443",
signing_key_filename: "/path/to/client/key.pem",
Expand Down Expand Up @@ -145,7 +150,7 @@
allow(rm_policy_group_service).to receive(:http_client).and_return(http_client)
expect(http_client).to receive(:get).with("/policy_groups").and_return(empty_policy_groups)
expect(http_client).to receive(:delete).with("/policy_groups/preprod")
expect(undo_record).to receive(:commit!)
expect(undo_stack).to receive(:push).with(undo_record)
end

it "removes the group" do
Expand Down Expand Up @@ -198,7 +203,7 @@
and_return(policy_db_9)

expect(http_client).to receive(:delete).with("/policy_groups/preprod")
expect(undo_record).to receive(:commit!)
expect(undo_stack).to receive(:push).with(undo_record)
end

it "removes the group" do
Expand Down

0 comments on commit 3dc88b7

Please sign in to comment.