Skip to content

Instantly share code, notes, and snippets.

@mivok
Last active June 29, 2017 21:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mivok/f73992be9247df1d3cb5b195d43c5e5c to your computer and use it in GitHub Desktop.
Save mivok/f73992be9247df1d3cb5b195d43c5e5c to your computer and use it in GitHub Desktop.
module MockDeliverySugar
module DSL
def automate_chef_server
@automate_chef_server ||= MockDeliverySugar::ChefServer.new
end
def load_delivery_chef_config
automate_chef_server.load_server_config
end
end
class ChefServer
include MockDeliverySugar::DSL
def load_server_config
Chef::Log.info("In MockDeliverySugar::ChefServer.load_server_config")
# Note: we don't actually load the config here, we're just testing to
# see if the stored config has some value in it
@stored_config = "Some value: #{rand(1000000)}"
Chef::Log.info("Stored config is: #{@stored_config}")
end
def unload_server_config
Chef::Log.info("In MockDeliverySugar::ChefServer.unload_server_config")
Chef::Log.info("Stored config is: #{@stored_config}")
end
end
end
module TestCookbook
module Helpers
module_function
def unload_delivery_chef_config
Chef::Log.info("In unload_delivery_chef_config")
automate_chef_server = send(:automate_chef_server)
automate_chef_server.unload_server_config
end
end
end
Chef::Recipe.send(:include, TestCookbook::Helpers)
Chef::Resource.send(:include, TestCookbook::Helpers)
Chef::Provider.send(:include, TestCookbook::Helpers)
Chef::Recipe.send(:include, MockDeliverySugar::DSL)
Chef::Resource.send(:include, MockDeliverySugar::DSL)
Chef::Provider.send(:include, MockDeliverySugar::DSL)
action :create do
load_delivery_chef_config
log 'This is where we would use the config, do provisioning and stuff'
ruby_block 'force_unload_server_config' do
block { unload_delivery_chef_config }
end
end
#!/bin/bash
chef-client -z -r test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment