summaryrefslogtreecommitdiff
path: root/spec/unit
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2014-10-02 07:54:40 +0200
committerGuido Günther <agx@sigxcpu.org>2014-10-02 08:23:25 +0200
commit165d5daf93f394c8eff20f77f699f782000596e5 (patch)
tree820d7ea7a0b47a55a34bc73f13b57cab19c57c44 /spec/unit
parent6b9bc57547e7bc84b17f33a4807f22be6bf91ecb (diff)
Add parse_url
This allows us to parse URLs into a hash.
Diffstat (limited to 'spec/unit')
-rw-r--r--spec/unit/puppet/parser/functions/parse_url_spec.rb33
1 files changed, 33 insertions, 0 deletions
diff --git a/spec/unit/puppet/parser/functions/parse_url_spec.rb b/spec/unit/puppet/parser/functions/parse_url_spec.rb
new file mode 100644
index 0000000..dd665d3
--- /dev/null
+++ b/spec/unit/puppet/parser/functions/parse_url_spec.rb
@@ -0,0 +1,33 @@
+#! /usr/bin/env ruby -S rspec
+#
+require 'spec_helper'
+
+describe 'the parse_url function' do
+ let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
+
+ it "should exist" do
+ Puppet::Parser::Functions.function("parse_url").should == "function_parse_url"
+ end
+
+ it 'should parse protocoll, host and path' do
+ result = scope.function_parse_url(['http://example.com/foo'])
+ result.should eq({"port" => 80,
+ "path" => "/foo",
+ "scheme" => "http",
+ "host" => "example.com"})
+ end
+
+
+ it "should raise a ParseError if there is less than 1 arguments" do
+ lambda { scope.function_parse_url([]) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should raise a ParseError if there is more than 1 arguments" do
+ lambda { scope.function_parse_url(['one', 'two']) }.should( raise_error(Puppet::ParseError))
+ end
+
+ it "should raise a ParseError if the URL format is invalid" do
+ lambda { scope.function_parse_url(['not_a_url://foo://'])}.should( raise_error(Puppet::ParseError))
+ end
+end
+