]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/staging/spec/unit/puppet/parser/functions/staging_parse_spec.rb
add nanliu/staging to 3rdparty
[dsa-puppet.git] / 3rdparty / modules / staging / spec / unit / puppet / parser / functions / staging_parse_spec.rb
1 #!/usr/bin/env rspec
2 require 'spec_helper'
3
4 describe "the staging parser function" do
5   let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6
7   it "should exist" do
8     Puppet::Parser::Functions.function("staging_parse").should == "function_staging_parse"
9   end
10
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))
13   end
14
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))
17   end
18
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))
21   end
22
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/))
25   end
26
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'))
30   end
31
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'))
35   end
36
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'))
40   end
41
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'))
45   end
46
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'))
50   end
51 end