Skip to content

Instantly share code, notes, and snippets.

@ploubser
Created March 21, 2013 17:09
Show Gist options
  • Select an option

  • Save ploubser/5214729 to your computer and use it in GitHub Desktop.

Select an option

Save ploubser/5214729 to your computer and use it in GitHub Desktop.
specdir = File.expand_path(File.join(File.dirname(__FILE__), ".."))
require "#{specdir}/spec_helper.rb"
$TEST_FILENAME = '/x/web/LIVE/testservice/testservice.txt'
module Puppet::Parser::Functions
# Stub the function by creating a new one
newfunction(:appconfig_lookup, :type => :rvalue) do |args|
return {"hello" => "world"}
end
# Fix the "does not return a value" issue
def self.rvalue?(name)
return true
end
end
# Very dirty monkey patch.
class Puppet::Resource
def parse_title
h = {}
type = resource_type
if type.respond_to? :title_patterns
type.title_patterns.each { |regexp, symbols_and_lambdas|
if captures = regexp.match(title.to_s)
symbols_and_lambdas.zip(captures[1..-1]).each { |symbol_and_lambda,capture|
sym, lam = symbol_and_lambda
if lam
h[sym] = lam.call(captures)
else
h[sym] = capture
end
}
return h
end
}
else
return { :name => title.to_s }
end
end
end
describe 'test::txt' do
let (:title) { $TEST_FILENAME }
context "when label data is present" do
let (:facts) do
{ :label_data => {
'CONFIG' => {
'testservice' => '1.0-1',
'topo-yaml' => '1.0-1',
},
},
}
end
let (:params) do
{ :package_name => 'testservice',
:service_name => 'testservice',
}
end
it "should work" do
should contain_file($TEST_FILENAME).with({ :content => "hello=world\n" })
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment