Skip to content

Commit f7f70fe

Browse files
committed
Merge pull request #185 from lmello/refactor_16498
(#16498) Added unit test for loadyaml function.
2 parents 5cc5e29 + bcd84f5 commit f7f70fe

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#! /usr/bin/env ruby -S rspec
2+
require 'spec_helper'
3+
4+
describe "the loadyaml function" do
5+
include PuppetlabsSpec::Files
6+
7+
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
8+
9+
it "should exist" do
10+
Puppet::Parser::Functions.function("loadyaml").should == "function_loadyaml"
11+
end
12+
13+
it "should raise a ParseError if there is less than 1 arguments" do
14+
expect { scope.function_loadyaml([]) }.to raise_error(Puppet::ParseError)
15+
end
16+
17+
it "should convert YAML file to a data structure" do
18+
yaml_file = tmpfilename ('yamlfile')
19+
File.open(yaml_file, 'w') do |fh|
20+
fh.write("---\n aaa: 1\n bbb: 2\n ccc: 3\n ddd: 4\n")
21+
end
22+
result = scope.function_loadyaml([yaml_file])
23+
result.should == {"aaa" => 1, "bbb" => 2, "ccc" => 3, "ddd" => 4 }
24+
end
25+
end

0 commit comments

Comments
 (0)