2011-06-29 22:21:55 +02:00
|
|
|
#!/usr/bin/env rspec
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2011-08-05 09:25:03 +02:00
|
|
|
describe "the parsejson function" do
|
2011-06-29 22:21:55 +02:00
|
|
|
before :all do
|
|
|
|
Puppet::Parser::Functions.autoloader.loadall
|
|
|
|
end
|
|
|
|
|
|
|
|
before :each do
|
|
|
|
@scope = Puppet::Parser::Scope.new
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should exist" do
|
2011-08-05 09:25:03 +02:00
|
|
|
Puppet::Parser::Functions.function("parsejson").should == "function_parsejson"
|
2011-06-29 22:21:55 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should raise a ParseError if there is less than 1 arguments" do
|
2011-08-05 09:25:03 +02:00
|
|
|
lambda { @scope.function_parsejson([]) }.should( raise_error(Puppet::ParseError))
|
2011-06-29 22:21:55 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should convert JSON to a data structure" do
|
|
|
|
json = <<-EOS
|
|
|
|
["aaa","bbb","ccc"]
|
|
|
|
EOS
|
2011-08-05 09:25:03 +02:00
|
|
|
result = @scope.function_parsejson([json])
|
2011-06-29 22:21:55 +02:00
|
|
|
result.should(eq(['aaa','bbb','ccc']))
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|