4 describe "the staging parser function" do
5 let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
8 Puppet::Parser::Functions.function("staging_parse").should == "function_staging_parse"
11 it "should raise a ParseError if there is less than 1 arguments" do
12 lambda { scope.function_staging_parse([]) }.should( raise_error(Puppet::ParseError))
15 it "should raise a ParseError if there is more than 3 arguments" do
16 lambda { scope.function_staging_parse(['/etc', 'filename', '.zip', 'error']) }.should( raise_error(Puppet::ParseError))
19 it "should raise a ParseError if there is an invalid info request" do
20 lambda { scope.function_staging_parse(['/etc', 'sheep', '.zip']) }.should( raise_error(Puppet::ParseError))
23 it "should raise a ParseError if 'source' doesn't have a URI path component" do
24 lambda { scope.function_staging_parse(['uri:without-path']) }.should( raise_error(Puppet::ParseError, /has no URI 'path' component/))
27 it "should return the filename by default" do
28 result = scope.function_staging_parse(["/etc/puppet/sample.tar.gz"])
29 result.should(eq('sample.tar.gz'))
32 it "should return the file basename" do
33 result = scope.function_staging_parse(["/etc/puppet/sample.tar.gz", "basename"])
34 result.should(eq('sample.tar'))
37 it "should return the file basename with custom extensions" do
38 result = scope.function_staging_parse(["/etc/puppet/sample.tar.gz", "basename", ".tar.gz"])
39 result.should(eq('sample'))
42 it "should return the file extname" do
43 result = scope.function_staging_parse(["/etc/puppet/sample.tar.gz", "extname"])
44 result.should(eq('.gz'))
47 it "should return the file parent" do
48 result = scope.function_staging_parse(["/etc/puppet/sample.tar.gz", "parent"])
49 result.should(eq('/etc/puppet'))