1 #! /usr/bin/env ruby -S rspec
4 describe "the enclose_ipv6 function" do
5 let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
8 expect(Puppet::Parser::Functions.function("enclose_ipv6")).to eq("function_enclose_ipv6")
11 it "should raise a ParseError if there is less than 1 arguments" do
12 expect { scope.function_enclose_ipv6([]) }.to( raise_error(Puppet::ParseError) )
15 it "should raise a ParseError if there is more than 1 arguments" do
16 expect { scope.function_enclose_ipv6(['argument1','argument2']) }.to( raise_error(Puppet::ParseError) )
19 it "should raise a ParseError when given garbage" do
20 expect { scope.function_enclose_ipv6(['garbage']) }.to( raise_error(Puppet::ParseError) )
23 it "should raise a ParseError when given something else than a string or an array" do
24 expect { scope.function_enclose_ipv6([['1' => '127.0.0.1']]) }.to( raise_error(Puppet::ParseError) )
27 it "should not raise a ParseError when given a single ip string" do
28 expect { scope.function_enclose_ipv6(['127.0.0.1']) }.to_not raise_error
31 it "should not raise a ParseError when given * as ip string" do
32 expect { scope.function_enclose_ipv6(['*']) }.to_not raise_error
35 it "should not raise a ParseError when given an array of ip strings" do
36 expect { scope.function_enclose_ipv6([['127.0.0.1','fe80::1']]) }.to_not raise_error
39 it "should not raise a ParseError when given differently notations of ip addresses" do
40 expect { scope.function_enclose_ipv6([['127.0.0.1','fe80::1','[fe80::1]']]) }.to_not raise_error
43 it "should raise a ParseError when given a wrong ipv4 address" do
44 expect { scope.function_enclose_ipv6(['127..0.0.1']) }.to( raise_error(Puppet::ParseError) )
47 it "should raise a ParseError when given a ipv4 address with square brackets" do
48 expect { scope.function_enclose_ipv6(['[127.0.0.1]']) }.to( raise_error(Puppet::ParseError) )
51 it "should raise a ParseError when given a wrong ipv6 address" do
52 expect { scope.function_enclose_ipv6(['fe80:::1']) }.to( raise_error(Puppet::ParseError) )
55 it "should embrace ipv6 adresses within an array of ip addresses" do
56 result = scope.function_enclose_ipv6([['127.0.0.1','fe80::1','[fe80::2]']])
57 expect(result).to(eq(['127.0.0.1','[fe80::1]','[fe80::2]']))
60 it "should embrace a single ipv6 adresse" do
61 result = scope.function_enclose_ipv6(['fe80::1'])
62 expect(result).to(eq(['[fe80::1]']))
65 it "should not embrace a single ipv4 adresse" do
66 result = scope.function_enclose_ipv6(['127.0.0.1'])
67 expect(result).to(eq(['127.0.0.1']))