Created
September 13, 2017 17:57
-
-
Save qubitrenegade/5c3dda97faf76db893dd3868b404483f to your computer and use it in GitHub Desktop.
Testing an Ohai Plugin generated from Template using burtlo/chefspec-ohai to test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# recipes/default.rb | |
ohai_plugin 'consul' do | |
resource :template | |
variables config_var: node['my_cookbook']['some_important_var'] | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# templates/default/my_plugin.rb | |
Ohai.plugin :MyPlugin do | |
provides 'my_plugin/foo' | |
def some_config_var | |
'<%= @config_var %>' | |
end | |
collect_data :default do | |
my_plugin Mash.new | |
consul[:path] = some_config_var | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# spec/unit/ohai_plugins/my_plugin_spec.rb | |
require 'spec_helper' | |
require 'tempfile' | |
require 'erb' | |
@config_var = 'Go see a Star War!' | |
temp_file = Tempfile.new('foo') | |
# temp_file = 'test/integration/default/ohai_plugins/my_plugin_rendered.rb' | |
template = ERB.new(File.read('templates/default/my_plugin.rb')).result | |
File.write(temp_file, template) | |
describe_ohai_plugin :MyPlugin do | |
let(:plugin_file) { temp_file } | |
# Do tests here as normal | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment